/** * Tests to see if we can and should update a specific item. * * @since 3.7.0 * * @param string $type The type of update being checked: 'core', 'theme', * 'plugin', 'translation'. * @param object $item The update offer. * @param string $context The filesystem context (a path) against which filesystem * access and status should be checked. */ public function should_update($type, $item, $context) { // Used to see if WP_Filesystem is set up to allow unattended updates. $skin = new Automatic_Upgrader_Skin(); if ($this->is_disabled()) { return false; } // Only relax the filesystem checks when the update doesn't include new files $allow_relaxed_file_ownership = false; if ('core' == $type && isset($item->new_files) && !$item->new_files) { $allow_relaxed_file_ownership = true; } // If we can't do an auto core update, we may still be able to email the user. if (!$skin->request_filesystem_credentials(false, $context, $allow_relaxed_file_ownership) || $this->is_vcs_checkout($context)) { if ('core' == $type) { $this->send_core_update_notification_email($item); } return false; } // Next up, is this an item we can update? if ('core' == $type) { $update = Core_Upgrader::should_update_to_version($item->current); } else { $update = !empty($item->autoupdate); } /** * Filter whether to automatically update core, a plugin, a theme, or a language. * * The dynamic portion of the hook name, `$type`, refers to the type of update * being checked. Can be 'core', 'theme', 'plugin', or 'translation'. * * Generally speaking, plugins, themes, and major core versions are not updated * by default, while translations and minor and development versions for core * are updated by default. * * See the {@see 'allow_dev_auto_core_updates', {@see 'allow_minor_auto_core_updates'}, * and {@see 'allow_major_auto_core_updates'} filters for a more straightforward way to * adjust core updates. * * @since 3.7.0 * * @param bool $update Whether to update. * @param object $item The update offer. */ $update = apply_filters('auto_update_' . $type, $update, $item); if (!$update) { if ('core' == $type) { $this->send_core_update_notification_email($item); } return false; } // If it's a core update, are we actually compatible with its requirements? if ('core' == $type) { global $wpdb; $php_compat = version_compare(phpversion(), $item->php_version, '>='); if (file_exists(WP_CONTENT_DIR . '/db.php') && empty($wpdb->is_mysql)) { $mysql_compat = true; } else { $mysql_compat = version_compare($wpdb->db_version(), $item->mysql_version, '>='); } if (!$php_compat || !$mysql_compat) { return false; } } return true; }
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"; $new_html .= "<p><a href='" . site_url('wp-admin/options-general.php?page=businesspress') . "'>BusinessPress</a> delays these updates 5 days to make sure you are not affected by any bugs in them.</p>"; } else { //$new_html .= "<p>No recent actions, be careful with your upgrades!</p>"; } /*if( stripos($html,'update-core.php?action=do-core-upgrade') !== false ) { preg_match( '~<input name="version" value="4.5"~', $html, $aVersion ); $new_html .= "<p>Alternatively you can download 4.4.2 and upload it via FTP.</p><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>"; }*/ // this bit if from update-core.php ob_start(); global $wp_version, $required_php_version, $required_mysql_version; $aShowed = array(); if ($this->check_user_permission() || $this->can_update_core()) { $aUpdates = get_site_transient('update_core'); if (!$aUpdates) { $aUpdates = get_option('_site_transient_update_core'); } if ($aUpdates && count($aUpdates->updates)) { foreach ($aUpdates->updates as $update) { if (stripos($update->version, $this->get_version_branch()) === 0) { if ($update->version == $wp_version) { echo "<strong>You have the latest version of WordPress.</strong>"; continue; } if (isset($aShowed[$update->version])) { continue; } $aShowed[$update->version] = true; echo '<ul class="core-updates-businespress">'; echo '<strong class="response">'; _e('There is a security update of WordPress available.', 'businesspress'); echo '</strong>'; echo '<li>'; $this->list_core_update($update, false); echo '</li>'; echo '</ul>'; } } } } $updates = get_core_updates(); $bMajorUpdate = false; foreach ((array) $updates as $update) { if (stripos($update->version, $this->get_version_branch()) === false) { $bMajorUpdate = true; } } if (!isset($updates[0]->response) || 'latest' == $updates[0]->response) { /*echo '<h2>'; _e('You have 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 { if ($bMajorUpdate) { echo '<strong class="response">'; _e('There is a core upgrade version of WordPress available.', 'businesspress'); echo '</strong>'; if ($this->check_user_permission() || $this->can_update_core()) { echo '<p>'; _e('Be very careful before you upgrade: in addition to causing your site to fail to load, core upgrades can corrupt your database or cause plugins important to your business to fail, such as membership and ecommerce solutions. <strong>Please be sure to upgrade all your plugins to their most recent version before a major version upgrade.</strong>', 'businesspress'); echo '</p>'; } } } 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>'; }*/ } if ($bMajorUpdate && ($this->check_user_permission() || $this->can_update_core())) { echo '<ul class="core-updates-businespress">'; foreach ((array) $updates as $update) { if (stripos($update->version, $this->get_version_branch()) === 0) { continue; // don't show the minor updates here! } echo '<li>'; if (!isset($update->response) || 'latest' == $update->response) { list_core_update($update); } else { $this->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>'; } } $new_html .= ob_get_clean(); if (preg_match('~<h\\d[^>]*?>Plugins</h\\d>~', $html)) { $html = preg_replace('~(<div class="wrap">)([\\s\\S]*?)(<h\\d[^>]*?>Plugins</h\\d>)~', '$1' . $new_html . '$3', $html); } else { $html = preg_replace('~(<div class="wrap">)([\\s\\S]*?)$~', '$1' . $new_html, $html); } echo $html; ?> <script> jQuery(function($){ $('form').submit( function(e) { var form = $(this); if( form.find('.check-1').prop('checked') && form.find('.check-2').prop('checked') && form.find('.check-3').prop('checked') ) { } else { e.preventDefault(); alert("Please confirm your site is ready for a core upgrade by checking the boxes above."); } }); }); </script> <?php }