本文整理汇总了PHP中WP_Automatic_Updater类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Automatic_Updater类的具体用法?PHP WP_Automatic_Updater怎么用?PHP WP_Automatic_Updater使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Automatic_Updater类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: is_version_controlled
/**
* Finds out if a site is using a version control system.
* @return bool
**/
public static function is_version_controlled()
{
if (!class_exists('WP_Automatic_Updater')) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
$updater = new WP_Automatic_Updater();
return (bool) strval($updater->is_vcs_checkout($context = ABSPATH));
}
示例2: is_version_controlled
/**
* Finds out if a site is using a version control system.
* @return string ( '1' | '0' )
**/
public static function is_version_controlled()
{
if (!class_exists('WP_Automatic_Updater')) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
$updater = new WP_Automatic_Updater();
$is_version_controlled = strval($updater->is_vcs_checkout($context = ABSPATH));
// transients should not be empty
if (empty($is_version_controlled)) {
$is_version_controlled = '0';
}
return $is_version_controlled;
}
示例3: async_upgrade
/**
* Asynchronously upgrades language packs after other upgrades have been made.
*
* Hooked to the {@see 'upgrader_process_complete'} action by default.
*
* @since 3.7.0
* @access public
* @static
*
* @param false|WP_Upgrader $upgrader Optional. WP_Upgrader instance or false. If `$upgrader` is
* a Language_Pack_Upgrader instance, the method will bail to
* avoid recursion. Otherwise unused. Default false.
*/
public static function async_upgrade($upgrader = false)
{
// Avoid recursion.
if ($upgrader && $upgrader instanceof Language_Pack_Upgrader) {
return;
}
// Nothing to do?
$language_updates = wp_get_translation_updates();
if (!$language_updates) {
return;
}
/*
* Avoid messing with VCS installs, at least for now.
* Noted: this is not the ideal way to accomplish this.
*/
$check_vcs = new WP_Automatic_Updater();
if ($check_vcs->is_vcs_checkout(WP_CONTENT_DIR)) {
return;
}
foreach ($language_updates as $key => $language_update) {
$update = !empty($language_update->autoupdate);
/**
* Filters whether to asynchronously update translation for core, a plugin, or a theme.
*
* @since 4.0.0
*
* @param bool $update Whether to update.
* @param object $language_update The update offer.
*/
$update = apply_filters('async_update_translation', $update, $language_update);
if (!$update) {
unset($language_updates[$key]);
}
}
if (empty($language_updates)) {
return;
}
// Re-use the automatic upgrader skin if the parent upgrader is using it.
if ($upgrader && $upgrader->skin instanceof Automatic_Upgrader_Skin) {
$skin = $upgrader->skin;
} else {
$skin = new Language_Pack_Upgrader_Skin(array('skip_header_footer' => true));
}
$lp_upgrader = new Language_Pack_Upgrader($skin);
$lp_upgrader->bulk_upgrade($language_updates);
}
示例4: find_core_auto_update
/**
* Gets the best available (and enabled) Auto-Update for WordPress Core.
*
* If there's 1.2.3 and 1.3 on offer, it'll choose 1.3 if the install allows it, else, 1.2.3
*
* @since 3.7.0
*
* @return array|false False on failure, otherwise the core update offering.
*/
function find_core_auto_update() {
$updates = get_site_transient( 'update_core' );
if ( ! $updates || empty( $updates->updates ) )
return false;
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
$auto_update = false;
$upgrader = new WP_Automatic_Updater;
foreach ( $updates->updates as $update ) {
if ( 'autoupdate' != $update->response )
continue;
if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) )
continue;
if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) )
$auto_update = $update;
}
return $auto_update;
}
示例5: find_core_auto_update
/**
* Gets the best available (and enabled) Auto-Update for WordPress Core.
*
* If there's 1.2.3 and 1.3 on offer, it'll choose 1.3 if the install allows it, else, 1.2.3
*
* @since 3.7.0
*
* @return array|false False on failure, otherwise the core update offering.
*/
function find_core_auto_update()
{
$updates = get_site_transient('update_core');
if (!$updates || empty($updates->updates)) {
return false;
}
$auto_update = false;
$upgrader = new WP_Automatic_Updater();
foreach ($updates->updates as $update) {
if ('autoupdate' != $update->response) {
continue;
}
if (!$upgrader->should_update('core', $update, ABSPATH)) {
continue;
}
if (!$auto_update || version_compare($update->current, $auto_update->current, '>')) {
$auto_update = $update;
}
}
return $auto_update;
}
示例6: get_possible_failures
static function get_possible_failures()
{
$result = array();
// Lets check some reasons why it might not be working as expected
include_once ABSPATH . '/wp-admin/includes/admin.php';
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
$upgrader = new WP_Automatic_Updater();
if ($upgrader->is_disabled()) {
$result[] = 'autoupdates-disabled';
}
if (!is_main_site()) {
$result[] = 'is-not-main-site';
}
if (!is_main_network()) {
$result[] = 'is-not-main-network';
}
if ($upgrader->is_vcs_checkout(ABSPATH)) {
$result[] = 'site-on-vcs';
}
if ($upgrader->is_vcs_checkout(WP_PLUGIN_DIR)) {
$result[] = 'plugin-directory-on-vcs';
}
if ($upgrader->is_vcs_checkout(WP_CONTENT_DIR)) {
$result[] = 'content-directory-on-vcs';
}
$lock = get_option('auto_updater.lock');
if ($lock > time() - HOUR_IN_SECONDS) {
$result[] = 'lock-is-set';
}
$skin = new Automatic_Upgrader_Skin();
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/template.php';
if (!$skin->request_filesystem_credentials(false, ABSPATH, false)) {
$result[] = 'no-system-write-access';
}
if (!$skin->request_filesystem_credentials(false, WP_PLUGIN_DIR, false)) {
$result[] = 'no-plugin-directory-write-access';
}
if (!$skin->request_filesystem_credentials(false, WP_CONTENT_DIR, false)) {
$result[] = 'no-wp-content-directory-write-access';
}
return $result;
}
示例7: core_upgrade_preamble
/**
* Display upgrade WordPress for downloading latest or upgrading automatically form.
*
* @since 2.7.0
*
* @global string $wp_version
* @global string $required_php_version
* @global string $required_mysql_version
*/
function core_upgrade_preamble()
{
global $wp_version, $required_php_version, $required_mysql_version;
$updates = get_core_updates();
if (!isset($updates[0]->response) || 'latest' == $updates[0]->response) {
echo '<h3>';
_e('You have Project Nami ' . get_projectnami_version() . ' which contains the latest version of WordPress.');
if (wp_http_supports(array('ssl'))) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new WP_Automatic_Updater();
$future_minor_update = (object) array('current' => $wp_version . '.1.next.minor', 'version' => $wp_version . '.1.next.minor', 'php_version' => $required_php_version, 'mysql_version' => $required_mysql_version);
$should_auto_update = $upgrader->should_update('core', $future_minor_update, ABSPATH);
if ($should_auto_update) {
echo ' ' . __('Future security updates will be applied automatically.');
}
}
echo '</h2>';
} else {
echo '<div class="notice notice-warning"><p>';
_e('<strong>Important:</strong> before updating, please back up your database and files.');
echo '</p></div>';
echo '<h3 class="response">';
_e('An updated version of WordPress is available. Please check <a href="http://projectnami.org/download/">the Project Nami Download page</a> for the latest build.');
echo '</h3>';
}
if (isset($updates[0]) && $updates[0]->response == 'development') {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new WP_Automatic_Updater();
if (wp_http_supports('ssl') && $upgrader->should_update('core', $updates[0], ABSPATH)) {
echo '<div class="updated inline"><p>';
echo '<strong>' . __('BETA TESTERS:') . '</strong> ' . __('This site is set up to install updates of future beta versions automatically.');
echo '</p></div>';
}
}
echo '<ul class="core-updates">';
foreach ((array) $updates as $update) {
echo '<li>';
list_core_update($update);
echo '</li>';
}
echo '</ul>';
// Don't show the maintenance mode notice when we are only showing a single re-install option.
if ($updates && (count($updates) > 1 || $updates[0]->response != 'latest')) {
//echo '<p>' . __( 'While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, your site will return to normal.' ) . '</p>';
} elseif (!$updates) {
list($normalized_version) = explode('-', $wp_version);
echo '<p>' . sprintf(__('<a href="%s">Learn more about WordPress %s</a>.'), esc_url(self_admin_url('about.php')), $normalized_version) . '</p>';
}
dismissed_updates();
}
示例8: wp_maybe_auto_update
/**
* Performs WordPress automatic background updates.
*
* @since 3.7.0
*/
function wp_maybe_auto_update()
{
include_once ABSPATH . '/wp-admin/includes/admin.php';
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
$upgrader = new WP_Automatic_Updater();
$upgrader->run();
}
示例9: _e
</div>
<div class="col-3 last-feature">
<h4><?php _e( 'More Reliable Than Ever' ); ?></h4>
<p><?php _e( 'The update process has been made even more reliable and secure, with dozens of new checks and safeguards.' ); ?></p>
<p><?php _e( 'You’ll still need to click “Update Now” once WordPress 3.8 is released, but we’ve never had more confidence in that beautiful blue button.' ); ?></p>
</div>
<?php
if ( current_user_can( 'update_core' ) ) {
$future_minor_update = (object) array(
'current' => $wp_version . '.1.next.minor',
'version' => $wp_version . '.1.next.minor',
'php_version' => $required_php_version,
'mysql_version' => $required_mysql_version,
);
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$updater = new WP_Automatic_Updater;
$can_auto_update = wp_http_supports( array( 'ssl' ) ) && $updater->should_update( 'core', $future_minor_update, ABSPATH );
if ( $can_auto_update ) {
echo '<p class="about-auto-update cool">' . __( 'This site <strong>is</strong> able to apply these updates automatically. Cool!' ). '</p>';
// If the updater is disabled entirely, don't show them anything.
} elseif ( ! $updater->is_disabled() ) {
echo '<p class="about-auto-update">';
// If this is is filtered to false, they won't get emails, so don't claim we will.
// Assumption: If the user can update core, they can see what the admin email is.
/** This filter is documented in wp-admin/includes/class-wp-upgrader.php */
if ( apply_filters( 'send_core_update_notification_email', true, $future_minor_update ) ) {
printf( __( 'This site <strong>is not</strong> able to apply these updates automatically. But we’ll email %s when there is a new security release.' ), esc_html( get_site_option( 'admin_email' ) ) );
} else {
示例10: plugin_upgrade
function plugin_upgrade()
{
if (empty($this->options)) {
// Don't automatically enable core updates in installs coming from a repo
if (!class_exists('WP_Automatic_Updater')) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
$wpau = new WP_Automatic_Updater();
$core_updates_enabled = !$wpau->is_vcs_checkout(ABSPATH);
$this->options = array('update' => array('core' => array('minor' => $core_updates_enabled, 'major' => false), 'plugins' => false, 'themes' => false), 'svn' => array('core' => false, 'plugins' => array(), 'themes' => array()), 'svn-success-email' => true, 'debug' => 'debug', 'next-development-update' => time(), 'override-email' => '', 'disable-email' => false, 'upgrade-after-3.7' => true);
}
// 'debug' option added in version 0.3
if (!array_key_exists('debug', $this->options)) {
$this->options['debug'] = false;
}
// SVN updates added in version 0.5
if (!array_key_exists('svn', $this->options)) {
$this->options['svn'] = false;
}
// Development version updates added in version 0.6
if (!array_key_exists('next-development-update', $this->options)) {
$this->options['next-development-update'] = time();
}
// Override contact email added in version 0.7
if (!array_key_exists('override-email', $this->options)) {
$this->options['override-email'] = '';
}
// Ability to disable email added in version 0.7
if (!array_key_exists('disable-email', $this->options)) {
$this->options['disable-email'] = false;
}
// Ability to only send SVN update emails on failure added in 0.8
if (!array_key_exists('svn-success-email', $this->options)) {
$this->options['svn-success-email'] = true;
}
// SVN support for themes and plugins added in 0.8
if (!is_array($this->options['svn'])) {
$this->options['svn'] = array('core' => $this->options['svn'], 'plugins' => array(), 'themes' => array());
}
if (!array_key_exists('upgrade-after-3.7', $this->options)) {
$this->options['upgrade-after-3.7'] = true;
// Core is handling upgrades now, so we should unschedule our old events
foreach ($this->options['update'] as $type => $update) {
$timestamp = wp_next_scheduled("auto_updater_{$type}_event");
if ($timestamp) {
wp_unschedule_event($timestamp, "auto_updater_{$type}_event");
}
}
}
// Support for different types of core upgrades added in 1.0
if (!is_array($this->options['update']['core'])) {
$this->options['update']['core'] = array('major' => $this->options['update']['core'], 'minor' => $this->options['update']['core']);
}
// debug option changed to send debug email under varying conditions in 1.0
if (is_bool($this->options['debug'])) {
if ($this->options['debug']) {
$this->options['debug'] = 'always';
} else {
$this->options['debug'] = 'debug';
}
}
}
示例11: check_plugin_update
/**
* 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;
}
示例12: is_version_controlled
/**
* Finds out if a site is using a version control system.
* We'll store that information as a transient with a 24 expiration.
* We only need to check once per day.
*
* @return string ( '1' | '0' )
*/
function is_version_controlled()
{
$is_version_controlled = get_transient('jetpack_site_is_vcs');
if (false === $is_version_controlled) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$updater = new WP_Automatic_Updater();
$is_version_controlled = strval($updater->is_vcs_checkout($context = ABSPATH));
// transients should not be empty
if (empty($is_version_controlled)) {
$is_version_controlled = '0';
}
set_transient('jetpack_site_is_vcs', $is_version_controlled, DAY_IN_SECONDS);
}
return $is_version_controlled;
}
示例13: upgrade_screen
function upgrade_screen()
{
$html = ob_get_clean();
if (!$this->check_user_permission() && !$this->can_update_core()) {
$html = preg_replace('~<form[^>]*?>~', '<!--form opening tag removed by BusinessPres-->', $html);
$html = str_replace('</form>', '<!--form closing tag removed by BusinessPres-->', $html);
}
if (!$this->check_user_permission() && (empty($this->aOptions['cap_update']) || !$this->aOptions['cap_update'])) {
$html = preg_replace('~<input[^>]*?type=["\']checkbox["\'][^>]*?>~', '', $html);
$html = preg_replace('~<thead[\\s\\S]*?</thead>~', '', $html);
$html = preg_replace('~<tfoot[\\s\\S]*?</tfoot>~', '', $html);
$html = preg_replace('~<input[^>]*?upgrade-plugins[^>]*?>~', '', $html);
$html = preg_replace('~<input[^>]*?upgrade-themes[^>]*?>~', '', $html);
}
global $wp_version;
$new_html = '';
if (!$this->check_user_permission() && !$this->can_update_core()) {
$new_html .= "<div class='error'><p>" . $this->talk_no_permissions('upgrade WordPress core') . "</p></div>";
}
$new_html .= "<h4>WordPress " . $wp_version . " installed<br />";
global $wp_version;
$sStatus = false;
$iTTL = 0;
$aVersions = $this->cache_core_version_info();
if ($aVersions && isset($aVersions['data']) && count($aVersions['data']) > 0) {
if ($this->get_version_branch() && isset($aVersions['data'][$this->get_version_branch()])) {
$iDate = strtotime($aVersions['data'][$this->get_version_branch()]);
$iTTL = $iDate + 3600 * 24 * 30 * 30;
// the current version is good has time to live set to 30 months
if ($iTTL - time() < 0) {
$sStatus = "Not Secure - Major Upgrade Required";
} else {
if ($iTTL - time() < 3600 * 24 * 30 * 3) {
// if the current version is older than 23 monts, warn the user
$sStatus = "Update Recommended Soon";
} else {
$sStatus = "Secure";
}
}
}
if ($this->get_branch_latest() != $wp_version && strtotime($aVersions['data'][$this->get_branch_latest()]) + 3600 * 24 * 5 < time()) {
$sStatus = "Not Secure - Minor Upgrade Required";
}
}
$new_html .= "Last updated: " . date('j F Y', strtotime($aVersions['data'][$this->get_branch_latest()])) . "<br />";
$new_html .= "Status: " . $sStatus . "<br />";
$iRemaining = floor(($iTTL - time()) / (3600 * 24) / 30);
if ($iRemaining > 0) {
$new_html .= "Projected security updates: " . $iRemaining . " months.";
} else {
$new_html .= "Projected security updates: Negative " . abs($iRemaining) . " months. Expired or expiration imminent.";
}
$new_html .= "</h4>\n";
if (!class_exists('Core_Upgrader')) {
include_once ABSPATH . '/wp-admin/includes/admin.php';
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
}
if (class_exists('Core_Upgrader')) {
$new_html .= "<p>Core auto-updates status: ";
$bDisabled = false;
if (class_exists('Core_Upgrader')) {
$objUpdater = new WP_Automatic_Updater();
if ($objUpdater->is_disabled()) {
$new_html .= "disabled";
$bDisabled = true;
}
}
if (!$bDisabled) {
if (Core_Upgrader::should_update_to_version('100.1.2.3')) {
$new_html .= "<strong>Major version updates enabled</strong>";
} else {
if (Core_Upgrader::should_update_to_version(get_bloginfo('version') . '.0.1')) {
$new_html .= "only Minor version updates enabled";
}
}
}
$new_html .= "</p>";
}
$aBlockedUpdates = get_site_option('businesspress_core_update_delay');
$bFound = false;
if ($aBlockedUpdates) {
foreach ($aBlockedUpdates as $key => $value) {
if (stripos($key, '.next.minor') === false) {
$bFound = true;
}
}
}
if ($bFound && $aBlockedUpdates) {
ksort($aBlockedUpdates);
$aBlockedUpdates = array_reverse($aBlockedUpdates);
$new_html .= "<p>Recently blocked updates:</p>";
$new_html .= "<ul>\n";
foreach ($aBlockedUpdates as $key => $value) {
if (stripos($key, '.next.minor') !== false) {
$new_html .= "<li>WP core internal autoupdate check " . human_time_diff(time(), $value) . " ago</li>\n";
continue;
}
$new_html .= "<li><a href='https://codex.wordpress.org/Version_" . $key . "' target='_blank'>" . $key . "</a> " . human_time_diff(time(), $value) . " ago</li>\n";
}
$new_html .= "</ul>\n";
//.........这里部分代码省略.........
示例14: 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);
}