Я нахожусь в процессе написания функции обновления для моего плагина, которая обслуживается через мой сервер, и обновления плагина будут вызываться через API. До сих пор я могу получить уведомление об обновлении для отображения на экране плагина. Однако, когда я нажимаю на ссылку «Просмотр версии», она выдает кучу ошибок. Показано ниже.
Я удалил большую часть кода, чтобы получить базовый набор кодов для работы до интеграции API. (так как я не знаю, какие данные требуются). Таким образом, запросы API на данный момент являются просто статическими данными в классе.
Страница: wp-admin/plugin-install.php?tab=plugin-information&plugin=myplugin§ion=changelog
Warning: call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members in /home/example/public_html/wp-includes/class-wp-hook.php on line 288
Warning: Creating default object from empty value in /home/example/public_html/wp-admin/includes/plugin-install.php on line 223
Notice: Undefined property: stdClass::$sections in /home/example/public_html/wp-admin/includes/plugin-install.php on line 566
Notice: Undefined property: stdClass::$sections in /home/example/public_html/wp-admin/includes/plugin-install.php on line 580
Notice: Undefined property: stdClass::$name in /home/example/public_html/wp-admin/includes/plugin-install.php on line 607
Вот мои действия
add_filter( 'plugins_api', array( $cc_maintenance, 'plugin_info', 20, 3 ) );
add_filter( 'site_transient_update_plugins', array( $cc_maintenance, 'push_update' ) );
add_action( 'upgrader_process_complete', array( $cc_maintenance, 'after_update' ), 10, 2 );
Вот моифайл класса $ cc_maintenance
<?php
class example_Maintenance
{
public function __construct()
{
}
public function plugin_info( $res, $action, $args )
{
// do nothing if this is not about getting plugin information
if( $action !== 'plugin_information' ):
return false;
endif;
// do nothing if it is not our plugin
if( 'example' !== $args->slug ):
return $res;
endif;
// trying to get from cache first, to disable cache comment 18,28,29,30,32
if( false == $remote = get_transient( 'upgrade_example_plugin' ) ):
$remote = json_encode( array(
"name" => "Test Updater",
"slug" => "example",
"download_url" => "https://example.com/wp-content/uploads/test-updater.zip",
"version" => "1.0.0",
"requires" => "3.0",
"tested" => "4.8.1",
"last_updated" => "2017-08-17 02:10:00",
"upgrade_notice" => "Plugin update is available.",
"author" => "Example Name",
"author_homepage" => "https://example.com",
"sections" => array(
"description" => "This is the plugin to test your updater script",
"installation" => "Upload the plugin to your blog, Activate it, that\'s it!",
"changelog" => "<h4>1.1 – August 17, 2017</h4><ul><li>Some bugs are fixed.</li><li>Release date.</li></ul>"
))
);
if ( !is_wp_error( $remote ) && isset( $remote['response']['code'] ) && $remote['response']['code'] == 200 && !empty( $remote['body'] ) ):
set_transient( 'upgrade_example_plugin', $remote, 43200 ); // 12 hours cache
endif;
endif;
if( $remote ):
$remote = json_decode( $remote );
$res = new stdClass();
$res->name = $remote->name;
$res->slug = 'example';
$res->version = $remote->version;
$res->tested = $remote->tested;
$res->requires = $remote->requires;
$res->author = '<a href="https://example.com">Example Author</a>';
$res->author_profile = '';
$res->download_link = $remote->download_url;
$res->trunk = $remote->download_url;
$res->last_updated = $remote->last_updated;
$res->sections = array(
'description' => "tab description",
'installation' => "tab installation",
'changelog' => "tab changelog",
);
// in case you want the screenshots tab, use the following HTML format for its content:
// <ol><li><a href="IMG_URL" target="_blank" rel="noopener noreferrer"><img src="IMG_URL" alt="CAPTION" /></a><p>CAPTION</p></li></ol>
if( !empty( $remote->sections->screenshots ) ) {
$res->sections['screenshots'] = $remote->sections->screenshots;
}
$res->banners = array(
'low' => 'https://example.com/banner-772x250.jpg',
'high' => 'https://example.com/banner-1544x500.jpg'
);
return $res;
endif;
return false;
}
public function push_update( $transient ){
delete_transient( 'upgrade_example_plugin' );
if ( empty($transient->checked ) ):
return $transient;
endif;
// your installed plugin version should be on the line below! You can obtain it dynamically of course
$res = new stdClass();
$res->slug = 'example';
$res->plugin = 'example/example.php';
$res->new_version = "1.0.1";
$res->tested = "5.0.0";
$res->package = "http://example.com/upgrade.zip";
$res->sections = serialize( array(
"Tab1" => "some content",
"Tab2" => "some content",
"Tab3" => "some content",
));
$transient->response['example/example.php'] = $res;
return $transient;
}
public function after_update( $upgrader_object, $options ) {
if ( $options['action'] == 'update' && $options['type'] === 'plugin' ) {
// just clean the cache when new plugin version is installed
delete_transient( 'upgrade_example_plugin' );
}
}
}
Любая помощь приветствуется. Заранее спасибо