本文整理汇总了PHP中WP_Automatic_Updater::update方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Automatic_Updater::update方法的具体用法?PHP WP_Automatic_Updater::update怎么用?PHP WP_Automatic_Updater::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Automatic_Updater
的用法示例。
在下文中一共展示了WP_Automatic_Updater::update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stdClass
/**
* Check for Updates at the defined API endpoint and modify the update array.
*
* This function dives into the update API just when WordPress creates its update array,
* then adds a custom API call and injects the custom plugin data retrieved from the API.
* It is reassembled from parts of the native WordPress plugin update code.
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
*
* @uses api_request()
*
* @param array $_transient_data Update array build by WordPress.
* @return array Modified update array with custom plugin data.
*/
function check_plugin_update($_transient_data)
{
global $pagenow;
if (!is_object($_transient_data)) {
$_transient_data = new stdClass();
}
if (!$this->slug || !isset($this->api_data[$this->slug]) || 'plugins.php' == $pagenow && is_multisite()) {
return $_transient_data;
}
if (empty($_transient_data->response) || empty($_transient_data->response[$this->name])) {
$version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug));
if (false !== $version_info && is_object($version_info) && isset($version_info->new_version)) {
$this->did_check = true;
if (version_compare($this->version, $version_info->new_version, '<')) {
$_transient_data->response[$this->name] = $version_info;
$_transient_data->response[$this->name]->plugin = $this->name;
if (isset($this->api_data[$this->slug]['auto']) && $this->api_data[$this->slug]['auto']) {
$this->version = $version_info->new_version;
$_transient_data->response[$this->name]->autoupdate = TRUE;
$_transient_data->last_checked = time();
$_transient_data->checked[$this->name] = $this->version;
set_site_transient('update_plugins', $_transient_data);
$upgrader = new WP_Automatic_Updater();
$result = $upgrader->update('plugin', $_transient_data->response[$this->name]);
if (!is_wp_error(!$result)) {
delete_transient(self::PREFFIX . '-' . $this->slug);
activate_plugin($this->api_data[$this->slug]['dir']);
} else {
exit;
}
}
}
$_transient_data->last_checked = time();
$_transient_data->checked[$this->name] = $this->version;
}
}
return $_transient_data;
}
示例2: wp_ajax_update_core
/**
* AJAX handler for updating core.
*
* @since 4.6.0
*
* @see Core_Upgrader
*/
function wp_ajax_update_core()
{
check_ajax_referer('updates');
if (!current_user_can('update_core')) {
$status['error'] = __('You do not have sufficient permissions to update this site.');
wp_send_json_error($status);
}
$reinstall = isset($_POST['reinstall']) ? (bool) $_POST['reinstall'] : false;
$version = isset($_POST['version']) ? sanitize_text_field(wp_unslash($_POST['version'])) : false;
$locale = isset($_POST['locale']) ? sanitize_text_field(wp_unslash($_POST['locale'])) : 'en_US';
$update = find_core_update($version, $locale);
if (!$update) {
return;
}
$status = array('update' => 'core', 'redirect' => esc_url(self_admin_url('about.php?updated')));
if ($update->current === $update->version) {
wp_send_json_success($status);
}
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
if ($reinstall) {
$update->response = 'reinstall';
}
$upgrader = new WP_Automatic_Updater();
$result = $upgrader->update('core', $update);
if (is_array($result) && !empty($result[0])) {
wp_send_json_success($status);
} else {
if (is_wp_error($result)) {
$status['error'] = $result->get_error_message();
wp_send_json_error($status);
} else {
if (false === $result) {
// These aren't actual errors.
$status['error'] = __('Installation Failed');
wp_send_json_error($status);
}
}
}
// An unhandled error occurred.
$status['error'] = __('Installation failed.');
wp_send_json_error($status);
}