KEEP IN MIND THAT API_URLs ARE SET! I'VE JUST REMOVED THEM FROM THIS QUESTION AS I'D LIKE NOT TO SHARE THE URL. :D
I've been following this guide / which shows to to set up a server that would update plugins for external plugins. I've managed to get it to work by being able to download the plugin from the url it returns and i'm also able to see that wordpress has an update ready for me in the plugins page:
And here's how the plugin listing shows:
My issue is though that it shows that there's an update avaible. The update itself isnt shown. Not even the button to update nor the update notification on the plugin itself.
The guide above uses this repo:
So now for the code... My plugins are made with classes. I therfore use array($this, etc..).
public function check_for_plugin_update($checked_data) {
global $api_url, $plugin_slug, $wp_version;
$plugin_slug = basename(dirname(__FILE__));
$api_url = 'http://serverurl/api/';
//Comment out these two lines during testing.
if (empty($checked_data->checked))
return $checked_data;
$args = array(
'slug' => $plugin_slug,
'version' => '1.0.0',
);
$request_string = array(
'body' => array(
'action' => 'basic_check',
'request' => serialize($args),
'api-key' => md5(get_bloginfo('url')),
),
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
);
// Start checking for an update
$raw_response = wp_remote_post($api_url, $request_string);
if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200))
$response = unserialize($raw_response['body']);
if (is_object($response) && !empty($response)) // Feed the update data into WP updater
$checked_data->response[$plugin_slug .'/'. $plugin_slug .'.php'] = $response;
return $checked_data;
}
And
public function plugin_api_call($def, $action, $args) {
global $plugin_slug, $api_url, $wp_version;
$plugin_slug = basename(dirname(__FILE__));
$api_url = 'http://serverurl/api/';
if (!isset($args->slug) || ($args->slug != $plugin_slug))
return false;
// Get the current version
$plugin_info = get_site_transient('update_plugins');
$current_version = $plugin_info->checked[$plugin_slug .'/'. $plugin_slug .'.php'];
$args->version = $current_version;
$request_string = array(
'body' => array(
'action' => $action,
'request' => serialize($args),
'api-key' => md5(get_bloginfo('url')),
),
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
);
$request = wp_remote_post($api_url, $request_string);
if (is_wp_error($request)) {
$res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message());
} else {
$res = unserialize($request['body']);
if ($res === false)
$res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
}
return $res;
}
Both are in my class--main.php Everything is almost the same as on the repo. Few changes such as plugin naming and adding some stuff. Everything else is stock. So can anyone tell me why it knows that an update is avaible, however, the update button isnt showing? :D
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744715906a4589614.html
评论列表(0条)