/** * Whether the entire automatic updater is disabled. * * @since 3.7.0 * @access public */ public function is_disabled() { // Background updates are disabled if you don't want file changes. if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { return true; } if (wp_installing()) { return true; } // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters. $disabled = defined('AUTOMATIC_UPDATER_DISABLED') && AUTOMATIC_UPDATER_DISABLED; /** * Filters whether to entirely disable background updates. * * There are more fine-grained filters and controls for selective disabling. * This filter parallels the AUTOMATIC_UPDATER_DISABLED constant in name. * * This also disables update notification emails. That may change in the future. * * @since 3.7.0 * * @param bool $disabled Whether the updater should be disabled. */ return apply_filters('automatic_updater_disabled', $disabled); }
function wp_schedule_update_global_counts() { if (!is_main_network() || !is_main_site()) { return; } if (!wp_next_scheduled('update_global_counts') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'update_global_counts'); } }
public function schedule_events() { if (!is_main_site()) { return; } if (!wp_next_scheduled('gmember_network_counts') && !wp_installing()) { wp_schedule_event(time(), 'daily', 'gmember_network_counts'); } }
/** * Fix a race condition in alloptions caching * * See https://core.trac.wordpress.org/ticket/31245 */ function _wpcom_vip_maybe_clear_alloptions_cache($option) { if (!wp_installing()) { $alloptions = wp_load_alloptions(); //alloptions should be cached at this point if (isset($alloptions[$option])) { //only if option is among alloptions wp_cache_delete('alloptions', 'options'); } } }
function create_object($args) { global $wpdb; $meta = isset($args['meta']) ? $args['meta'] : array('public' => 1); $user_id = isset($args['user_id']) ? $args['user_id'] : get_current_user_id(); // temp tables will trigger db errors when we attempt to reference them as new temp tables $suppress = $wpdb->suppress_errors(); $blog = wpmu_create_blog($args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id']); $wpdb->suppress_errors($suppress); // Tell WP we're done installing. wp_installing(false); return $blog; }
public function test_update_theme() { $this->_setRole('administrator'); $_POST['_ajax_nonce'] = wp_create_nonce('updates'); $_POST['slug'] = 'twentyten'; // Make the request. try { // Prevent wp_update_themes() from running. wp_installing(true); $this->_handleAjax('update-theme'); wp_installing(false); } catch (WPAjaxDieContinueException $e) { unset($e); } // Get the response. $response = json_decode($this->_last_response, true); $expected = array('success' => false, 'data' => array('update' => 'theme', 'slug' => 'twentyten', 'errorMessage' => 'The theme is at the latest version.', 'newVersion' => '', 'debug' => array('The theme is at the latest version.'))); $this->assertEqualSets($expected, $response); }
function wp_get_active_and_valid_plugins() { $plugins = array(); $active_plugins = (array) get_option('active_plugins', array()); // Check for hacks file if the option is enabled if (get_option('hack_file') && file_exists(ABSPATH . 'my-hacks.php')) { _deprecated_file('my-hacks.php', '1.5'); array_unshift($plugins, ABSPATH . 'my-hacks.php'); } if (empty($active_plugins) || wp_installing()) { return $plugins; } $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; foreach ($active_plugins as $plugin) { if (!validate_file($plugin) && '.php' == substr($plugin, -4) && file_exists(WP_PLUGIN_DIR . '/' . $plugin) && (!$network_plugins || !in_array(WP_PLUGIN_DIR . '/' . $plugin, $network_plugins))) { $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; } } return $plugins; }
/** * Get available translations from the WordPress.org API. * * @since 4.0.0 * * @see translations_api() * * @return array Array of translations, each an array of data. If the API response results * in an error, an empty array will be returned. */ function wp_get_available_translations() { if (!wp_installing() && false !== ($translations = get_site_transient('available_translations'))) { return $translations; } include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version $api = translations_api('core', array('version' => $wp_version)); if (is_wp_error($api) || empty($api['translations'])) { return array(); } $translations = array(); // Key the array with the language code for now. foreach ($api['translations'] as $translation) { $translations[$translation['language']] = $translation; } if (!defined('WP_INSTALLING')) { set_site_transient('available_translations', $translations, 3 * HOUR_IN_SECONDS); } return $translations; }
* attempt to do no more than threshold value, with some +/- allowed. */ if ($c <= 50 || $c > 50 && mt_rand(0, (int) ($c / 50)) == 1) { require_once ABSPATH . WPINC . '/http.php'; $response = wp_remote_get(admin_url('upgrade.php?step=1'), array('timeout' => 120, 'httpversion' => '1.1')); /** This action is documented in wp-admin/network/upgrade.php */ do_action('after_mu_upgrade', $response); unset($response); } unset($c); } } require_once ABSPATH . 'wp-admin/includes/admin.php'; auth_redirect(); // Schedule trash collection if (!wp_next_scheduled('wp_scheduled_delete') && !wp_installing()) { wp_schedule_event(time(), 'daily', 'wp_scheduled_delete'); } set_screen_options(); $date_format = __('F j, Y'); $time_format = __('g:i a'); wp_enqueue_script('common'); /** * $pagenow is set in vars.php * $wp_importers is sometimes set in wp-admin/includes/import.php * The remaining variables are imported as globals elsewhere, declared as globals here * * @global string $pagenow * @global array $wp_importers * @global string $hook_suffix * @global string $plugin_page
/** * Administration Screen CSS for changing the styles. * * If installing the 'wp-admin/' directory will be replaced with './'. * * The $_wp_admin_css_colors global manages the Administration Screens CSS * stylesheet that is loaded. The option that is set is 'admin_color' and is the * color and key for the array. The value for the color key is an object with * a 'url' parameter that has the URL path to the CSS file. * * The query from $src parameter will be appended to the URL that is given from * the $_wp_admin_css_colors array value URL. * * @since 2.6.0 * @global array $_wp_admin_css_colors * * @param string $src Source URL. * @param string $handle Either 'colors' or 'colors-rtl'. * @return string|false URL path to CSS stylesheet for Administration Screens. */ function wp_style_loader_src($src, $handle) { global $_wp_admin_css_colors; if (wp_installing()) { return preg_replace('#^wp-admin/#', './', $src); } if ('colors' == $handle) { $color = get_user_option('admin_color'); if (empty($color) || !isset($_wp_admin_css_colors[$color])) { $color = 'fresh'; } $color = $_wp_admin_css_colors[$color]; $parsed = parse_url($src); $url = $color->url; if (!$url) { return false; } if (isset($parsed['query']) && $parsed['query']) { wp_parse_str($parsed['query'], $qv); $url = add_query_arg($qv, $url); } return $url; } return $src; }
/** * Checks that current theme files 'index.php' and 'style.css' exists. * * Does not initially check the default theme, which is the fallback and should always exist. * But if it doesn't exist, it'll fall back to the latest core default theme that does exist. * Will switch theme to the fallback theme if current theme does not validate. * * You can use the 'validate_current_theme' filter to return false to * disable this functionality. * * @since 1.5.0 * @see WP_DEFAULT_THEME * * @return bool */ function validate_current_theme() { /** * Filter whether to validate the current theme. * * @since 2.7.0 * * @param bool $validate Whether to validate the current theme. Default true. */ if (wp_installing() || !apply_filters('validate_current_theme', true)) { return true; } if (!file_exists(get_template_directory() . '/index.php')) { // Invalid. } elseif (!file_exists(get_template_directory() . '/style.css')) { // Invalid. } elseif (is_child_theme() && !file_exists(get_stylesheet_directory() . '/style.css')) { // Invalid. } else { // Valid. return true; } $default = wp_get_theme(WP_DEFAULT_THEME); if ($default->exists()) { switch_theme(WP_DEFAULT_THEME); return false; } /** * If we're in an invalid state but WP_DEFAULT_THEME doesn't exist, * switch to the latest core default theme that's installed. * If it turns out that this latest core default theme is our current * theme, then there's nothing we can do about that, so we have to bail, * rather than going into an infinite loop. (This is why there are * checks against WP_DEFAULT_THEME above, also.) We also can't do anything * if it turns out there is no default theme installed. (That's `false`.) */ $default = WP_Theme::get_core_default_theme(); if (false === $default || get_stylesheet() == $default->get_stylesheet()) { return true; } switch_theme($default->get_stylesheet()); return false; }
/** * Load default translated strings based on locale. * * Loads the .mo file in WP_LANG_DIR constant path from WordPress root. * The translated (.mo) file is named based on the locale. * * @see load_textdomain() * * @since 1.5.0 * * @param string $locale Optional. Locale to load. Default is the value of {@see get_locale()}. * @return bool Whether the textdomain was loaded. */ function load_default_textdomain($locale = null) { if (null === $locale) { $locale = get_locale(); } // Unload previously loaded strings so we can switch translations. unload_textdomain('default'); $return = load_textdomain('default', WP_LANG_DIR . "/{$locale}.mo"); if ((is_multisite() || defined('WP_INSTALLING_NETWORK') && WP_INSTALLING_NETWORK) && !file_exists(WP_LANG_DIR . "/admin-{$locale}.mo")) { load_textdomain('default', WP_LANG_DIR . "/ms-{$locale}.mo"); return $return; } if (is_admin() || wp_installing() || defined('WP_REPAIRING') && WP_REPAIRING) { load_textdomain('default', WP_LANG_DIR . "/admin-{$locale}.mo"); } if (is_network_admin() || defined('WP_INSTALLING_NETWORK') && WP_INSTALLING_NETWORK) { load_textdomain('default', WP_LANG_DIR . "/admin-network-{$locale}.mo"); } return $return; }
/** * Get the value of a transient. * * If the transient does not exist, does not have a value, or has expired, * then the return value will be false. * * @since 2.8.0 * * @param string $transient Transient name. Expected to not be SQL-escaped. * @return mixed Value of transient. */ function get_transient($transient) { /** * Filters the value of an existing transient. * * The dynamic portion of the hook name, `$transient`, refers to the transient name. * * Passing a truthy value to the filter will effectively short-circuit retrieval * of the transient, returning the passed value instead. * * @since 2.8.0 * @since 4.4.0 The `$transient` parameter was added * * @param mixed $pre_transient The default value to return if the transient does not exist. * Any value other than false will short-circuit the retrieval * of the transient, and return the returned value. * @param string $transient Transient name. */ $pre = apply_filters("pre_transient_{$transient}", false, $transient); if (false !== $pre) { return $pre; } if (wp_using_ext_object_cache()) { $value = wp_cache_get($transient, 'transient'); } else { $transient_option = '_transient_' . $transient; if (!wp_installing()) { // If option is not in alloptions, it is not autoloaded and thus has a timeout $alloptions = wp_load_alloptions(); if (!isset($alloptions[$transient_option])) { $transient_timeout = '_transient_timeout_' . $transient; $timeout = get_option($transient_timeout); if (false !== $timeout && $timeout < time()) { delete_option($transient_option); delete_option($transient_timeout); $value = false; } } } if (!isset($value)) { $value = get_option($transient_option); } } /** * Filters an existing transient's value. * * The dynamic portion of the hook name, `$transient`, refers to the transient name. * * @since 2.8.0 * @since 4.4.0 The `$transient` parameter was added * * @param mixed $value Value of transient. * @param string $transient Transient name. */ return apply_filters("transient_{$transient}", $value, $transient); }
/** * Load default translated strings based on locale. * * Loads the .mo file in WP_LANG_DIR constant path from WordPress root. * The translated (.mo) file is named based on the locale. * * @see load_textdomain() * * @since 1.5.0 * * @param string $locale Optional. Locale to load. Default is the value of {@see get_locale()}. * @return bool Whether the textdomain was loaded. */ function load_default_textdomain($locale = null) { if (null === $locale) { $locale = get_locale(); } // Unload previously loaded strings so we can switch translations. unload_textdomain('default'); $return = load_textdomain('default', WP_LANG_DIR . "/{$locale}.mo"); if (is_admin() || wp_installing() || defined('WP_REPAIRING') && WP_REPAIRING) { load_textdomain('default', WP_LANG_DIR . "/admin-{$locale}.mo"); } return $return; }
/** * Flushes rewrite rules if siteurl, home or page_on_front changed. * * @since 2.1.0 * * @param string $old_value * @param string $value */ function update_home_siteurl($old_value, $value) { if (wp_installing()) { return; } flush_rewrite_rules(); }
/** * Schedule core, theme, and plugin update checks. * * @since 3.1.0 */ function wp_schedule_update_checks() { if (!wp_next_scheduled('wp_version_check') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'wp_version_check'); } if (!wp_next_scheduled('wp_update_plugins') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins'); } if (!wp_next_scheduled('wp_update_themes') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); } }
/** * Displays a form to the user to request for their FTP/SSH details in order * to connect to the filesystem. * * All chosen/entered details are saved, Excluding the Password. * * Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467) * to specify an alternate FTP/SSH port. * * Plugins may override this form by returning true|false via the * {@see 'request_filesystem_credentials'} filter. * * @since 2.5. * * @todo Properly mark optional arguments as such * * @global string $pagenow * * @param string $form_post the URL to post the form to * @param string $type the chosen Filesystem method in use * @param bool $error if the current request has failed to connect * @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method() * @param array $extra_fields Extra POST fields which should be checked for to be included in the post. * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable. * @return bool False on failure. True on success. */ function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false, $extra_fields = null, $allow_relaxed_file_ownership = false) { global $pagenow; /** * Filter the filesystem credentials form output. * * Returning anything other than an empty string will effectively short-circuit * output of the filesystem credentials form, returning that value instead. * * @since 2.5.0 * * @param mixed $output Form output to return instead. Default empty. * @param string $form_post URL to POST the form to. * @param string $type Chosen type of filesystem. * @param bool $error Whether the current request has failed to connect. * Default false. * @param string $context Full path to the directory that is tested for * being writable. * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable. * @param array $extra_fields Extra POST fields. */ $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership); if ('' !== $req_cred) { return $req_cred; } if (empty($type)) { $type = get_filesystem_method(array(), $context, $allow_relaxed_file_ownership); } if ('direct' == $type) { return true; } if (is_null($extra_fields)) { $extra_fields = array('version', 'locale'); } $credentials = get_option('ftp_credentials', array('hostname' => '', 'username' => '')); // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option) $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? wp_unslash($_POST['hostname']) : $credentials['hostname']); $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? wp_unslash($_POST['username']) : $credentials['username']); $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? wp_unslash($_POST['password']) : ''); // Check to see if we are setting the public/private keys for ssh $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? wp_unslash($_POST['public_key']) : ''); $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? wp_unslash($_POST['private_key']) : ''); // Sanitize the hostname, Some people might pass in odd-data: $credentials['hostname'] = preg_replace('|\\w+://|', '', $credentials['hostname']); //Strip any schemes off if (strpos($credentials['hostname'], ':')) { list($credentials['hostname'], $credentials['port']) = explode(':', $credentials['hostname'], 2); if (!is_numeric($credentials['port'])) { unset($credentials['port']); } } else { unset($credentials['port']); } if (defined('FTP_SSH') && FTP_SSH || defined('FS_METHOD') && 'ssh2' == FS_METHOD) { $credentials['connection_type'] = 'ssh'; } elseif (defined('FTP_SSL') && FTP_SSL && 'ftpext' == $type) { //Only the FTP Extension understands SSL $credentials['connection_type'] = 'ftps'; } elseif (!empty($_POST['connection_type'])) { $credentials['connection_type'] = wp_unslash($_POST['connection_type']); } elseif (!isset($credentials['connection_type'])) { //All else fails (And it's not defaulted to something else saved), Default to FTP $credentials['connection_type'] = 'ftp'; } if (!$error && (!empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) || 'ssh' == $credentials['connection_type'] && !empty($credentials['public_key']) && !empty($credentials['private_key']))) { $stored_credentials = $credentials; if (!empty($stored_credentials['port'])) { //save port as part of hostname to simplify above code. $stored_credentials['hostname'] .= ':' . $stored_credentials['port']; } unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']); if (!wp_installing()) { update_option('ftp_credentials', $stored_credentials); } return $credentials; } $hostname = isset($credentials['hostname']) ? $credentials['hostname'] : ''; $username = isset($credentials['username']) ? $credentials['username'] : ''; $public_key = isset($credentials['public_key']) ? $credentials['public_key'] : ''; $private_key = isset($credentials['private_key']) ? $credentials['private_key'] : ''; $port = isset($credentials['port']) ? $credentials['port'] : ''; $connection_type = isset($credentials['connection_type']) ? $credentials['connection_type'] : ''; if ($error) { $error_string = __('<strong>ERROR:</strong> There was an error connecting to the server, Please verify the settings are correct.'); if (is_wp_error($error)) { $error_string = esc_html($error->get_error_message()); } echo '<div id="message" class="error"><p>' . $error_string . '</p></div>'; } $types = array(); if (extension_loaded('ftp') || extension_loaded('sockets') || function_exists('fsockopen')) { $types['ftp'] = __('FTP'); } if (extension_loaded('ftp')) { //Only this supports FTPS $types['ftps'] = __('FTPS (SSL)'); } if (extension_loaded('ssh2') && function_exists('stream_get_contents')) { $types['ssh'] = __('SSH2'); } /** * Filter the connection types to output to the filesystem credentials form. * * @since 2.9.0 * * @param array $types Types of connections. * @param array $credentials Credentials to connect with. * @param string $type Chosen filesystem method. * @param object $error Error object. * @param string $context Full path to the directory that is tested * for being writable. */ $types = apply_filters('fs_ftp_connection_types', $types, $credentials, $type, $error, $context); ?> <script type="text/javascript"> <!-- jQuery(function($){ jQuery("#ssh").click(function () { jQuery("#ssh_keys").show(); }); jQuery("#ftp, #ftps").click(function () { jQuery("#ssh_keys").hide(); }); jQuery('#request-filesystem-credentials-form input[value=""]:first').focus(); }); --> </script> <form action="<?php echo esc_url($form_post); ?> " method="post"> <div id="request-filesystem-credentials-form" class="request-filesystem-credentials-form"> <?php // Print a H1 heading in the FTP credentials modal dialog, default is a H2. $heading_tag = 'h2'; if ('plugins.php' === $pagenow || 'plugin-install.php' === $pagenow) { $heading_tag = 'h1'; } echo "<{$heading_tag} id='request-filesystem-credentials-title'>" . __('Connection Information') . "</{$heading_tag}>"; ?> <p id="request-filesystem-credentials-desc"><?php $label_user = __('Username'); $label_pass = __('Password'); _e('To perform the requested action, WordPress needs to access your web server.'); echo ' '; if (isset($types['ftp']) || isset($types['ftps'])) { if (isset($types['ssh'])) { _e('Please enter your FTP or SSH credentials to proceed.'); $label_user = __('FTP/SSH Username'); $label_pass = __('FTP/SSH Password'); } else { _e('Please enter your FTP credentials to proceed.'); $label_user = __('FTP Username'); $label_pass = __('FTP Password'); } echo ' '; } _e('If you do not remember your credentials, you should contact your web host.'); ?> </p> <label for="hostname"> <span class="field-title"><?php _e('Hostname'); ?> </span> <input name="hostname" type="text" id="hostname" aria-describedby="request-filesystem-credentials-desc" class="code" placeholder="<?php esc_attr_e('example: www.wordpress.org'); ?> " value="<?php echo esc_attr($hostname); if (!empty($port)) { echo ":{$port}"; } ?> "<?php disabled(defined('FTP_HOST')); ?> /> </label> <div class="ftp-username"> <label for="username"> <span class="field-title"><?php echo $label_user; ?> </span> <input name="username" type="text" id="username" value="<?php echo esc_attr($username); ?> "<?php disabled(defined('FTP_USER')); ?> /> </label> </div> <div class="ftp-password"> <label for="password"> <span class="field-title"><?php echo $label_pass; ?> </span> <input name="password" type="password" id="password" value="<?php if (defined('FTP_PASS')) { echo '*****'; } ?> "<?php disabled(defined('FTP_PASS')); ?> /> <em><?php if (!defined('FTP_PASS')) { _e('This password will not be stored on the server.'); } ?> </em> </label> </div> <?php if (isset($types['ssh'])) { ?> <fieldset> <legend><?php _e('Authentication Keys'); ?> </legend> <label for="public_key"> <span class="field-title"><?php _e('Public Key:'); ?> </span> <input name="public_key" type="text" id="public_key" aria-describedby="auth-keys-desc" value="<?php echo esc_attr($public_key); ?> "<?php disabled(defined('FTP_PUBKEY')); ?> /> </label> <label for="private_key"> <span class="field-title"><?php _e('Private Key:'); ?> </span> <input name="private_key" type="text" id="private_key" value="<?php echo esc_attr($private_key); ?> "<?php disabled(defined('FTP_PRIKEY')); ?> /> </label> </fieldset> <span id="auth-keys-desc"><?php _e('Enter the location on the server where the public and private keys are located. If a passphrase is needed, enter that in the password field above.'); ?> </span> <?php } ?> <fieldset> <legend><?php _e('Connection Type'); ?> </legend> <?php $disabled = disabled(defined('FTP_SSL') && FTP_SSL || defined('FTP_SSH') && FTP_SSH, true, false); foreach ($types as $name => $text) { ?> <label for="<?php echo esc_attr($name); ?> "> <input type="radio" name="connection_type" id="<?php echo esc_attr($name); ?> " value="<?php echo esc_attr($name); ?> "<?php checked($name, $connection_type); echo $disabled; ?> /> <?php echo $text; ?> </label> <?php } ?> </fieldset> <?php foreach ((array) $extra_fields as $field) { if (isset($_POST[$field])) { echo '<input type="hidden" name="' . esc_attr($field) . '" value="' . esc_attr(wp_unslash($_POST[$field])) . '" />'; } } ?> <p class="request-filesystem-credentials-action-buttons"> <button class="button cancel-button" data-js-action="close" type="button"><?php _e('Cancel'); ?> </button> <?php submit_button(__('Proceed'), 'button', 'upgrade', false); ?> </p> </div> </form> <?php return false; }
public function test_update_plugin() { $this->_setRole('administrator'); $_POST['_ajax_nonce'] = wp_create_nonce('updates'); $_POST['plugin'] = 'hello.php'; $_POST['slug'] = 'hello-dolly'; // Make the request try { // Prevent wp_update_plugins() from running wp_installing(true); $this->_handleAjax('update-plugin'); wp_installing(false); } catch (WPAjaxDieContinueException $e) { unset($e); } // Get the response. $response = json_decode($this->_last_response, true); $expected = array('success' => false, 'data' => array('update' => 'plugin', 'slug' => 'hello-dolly', 'plugin' => 'hello.php', 'pluginName' => 'Hello Dolly', 'errorMessage' => 'Plugin update failed.', 'oldVersion' => 'Version 1.6', 'newVersion' => '', 'debug' => array('The plugin is at the latest version.'))); $this->assertEqualSets($expected, $response); }
/** * Schedule core, theme, and plugin update checks. * * @since 3.1.0 */ function wp_schedule_update_checks() { if (!wp_next_scheduled('wp_version_check') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'wp_version_check'); } if (!wp_next_scheduled('wp_update_plugins') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins'); } if (!wp_next_scheduled('wp_update_themes') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); } if (wp_next_scheduled('wp_maybe_auto_update') > time() + HOUR_IN_SECONDS && !wp_installing()) { wp_clear_scheduled_hook('wp_maybe_auto_update'); } }
return $data_to_save; } } } if (!isset($data_to_save[$conditional_id]) || !$data_to_save[$conditional_id]) { unset($data_to_save[$field_id]); } return $data_to_save; } } /* End of class. */ /** * Instantiate our class. * * {@internal wp_installing() function was introduced in WP 4.4. The function exists and constant * check can be removed once the min version for this plugin has been upped to 4.4.}} */ if (function_exists('wp_installing') && wp_installing() === false || !function_exists('wp_installing') && (!defined('WP_INSTALLING') || WP_INSTALLING === false)) { add_action('plugins_loaded', 'cmb2_conditionals_init'); } if (!function_exists('cmb2_conditionals_init')) { /** * Initialize the class. */ function cmb2_conditionals_init() { $cmb2_conditionals = new CMB2_Conditionals(); } } } /* End of class-exists wrapper. */
/** * Identifies the network and site of a requested domain and path and populates the * corresponding network and site global objects as part of the multisite bootstrap process. * * Prior to 4.6.0, this was a procedural block in `ms-settings.php`. It was wrapped into * a function to facilitate unit tests. It should not be used outside of core. * * Usually, it's easier to query the site first, which then declares its network. * In limited situations, we either can or must find the network first. * * If a network and site are found, a `true` response will be returned so that the * request can continue. * * If neither a network or site is found, `false` or a URL string will be returned * so that either an error can be shown or a redirect can occur. * * @since 4.6.0 * @access private * * @global wpdb $wpdb WordPress database abstraction object. * @global WP_Network $current_site The current network. * @global WP_Site $current_blog The current site. * * @param string $domain The requested domain. * @param string $path The requested path. * @param bool $subdomain Whether a subdomain (true) or subdirectory (false) configuration. * @return bool|string True if bootstrap successfully populated `$current_blog` and `$current_site`. * False if bootstrap could not be properly completed. * Redirect URL if parts exist, but the request as a whole can not be fulfilled. */ function ms_load_current_site_and_network($domain, $path, $subdomain = false) { global $wpdb, $current_site, $current_blog; // If the network is defined in wp-config.php, we can simply use that. if (defined('DOMAIN_CURRENT_SITE') && defined('PATH_CURRENT_SITE')) { $current_site = new stdClass(); $current_site->id = defined('SITE_ID_CURRENT_SITE') ? SITE_ID_CURRENT_SITE : 1; $current_site->domain = DOMAIN_CURRENT_SITE; $current_site->path = PATH_CURRENT_SITE; if (defined('BLOG_ID_CURRENT_SITE')) { $current_site->blog_id = BLOG_ID_CURRENT_SITE; } elseif (defined('BLOGID_CURRENT_SITE')) { // deprecated. $current_site->blog_id = BLOGID_CURRENT_SITE; } if (0 === strcasecmp($current_site->domain, $domain) && 0 === strcasecmp($current_site->path, $path)) { $current_blog = get_site_by_path($domain, $path); } elseif ('/' !== $current_site->path && 0 === strcasecmp($current_site->domain, $domain) && 0 === stripos($path, $current_site->path)) { // If the current network has a path and also matches the domain and path of the request, // we need to look for a site using the first path segment following the network's path. $current_blog = get_site_by_path($domain, $path, 1 + count(explode('/', trim($current_site->path, '/')))); } else { // Otherwise, use the first path segment (as usual). $current_blog = get_site_by_path($domain, $path, 1); } } elseif (!$subdomain) { /* * A "subdomain" install can be re-interpreted to mean "can support any domain". * If we're not dealing with one of these installs, then the important part is determining * the network first, because we need the network's path to identify any sites. */ if (!($current_site = wp_cache_get('current_network', 'site-options'))) { // Are there even two networks installed? $one_network = $wpdb->get_row("SELECT * FROM {$wpdb->site} LIMIT 2"); // [sic] if (1 === $wpdb->num_rows) { $current_site = new WP_Network($one_network); wp_cache_add('current_network', $current_site, 'site-options'); } elseif (0 === $wpdb->num_rows) { // A network not found hook should fire here. return false; } } if (empty($current_site)) { $current_site = WP_Network::get_by_path($domain, $path, 1); } if (empty($current_site)) { /** * Fires when a network cannot be found based on the requested domain and path. * * At the time of this action, the only recourse is to redirect somewhere * and exit. If you want to declare a particular network, do so earlier. * * @since 4.4.0 * * @param string $domain The domain used to search for a network. * @param string $path The path used to search for a path. */ do_action('ms_network_not_found', $domain, $path); return false; } elseif ($path === $current_site->path) { $current_blog = get_site_by_path($domain, $path); } else { // Search the network path + one more path segment (on top of the network path). $current_blog = get_site_by_path($domain, $path, substr_count($current_site->path, '/')); } } else { // Find the site by the domain and at most the first path segment. $current_blog = get_site_by_path($domain, $path, 1); if ($current_blog) { $current_site = WP_Network::get_instance($current_blog->site_id ? $current_blog->site_id : 1); } else { // If you don't have a site with the same domain/path as a network, you're pretty screwed, but: $current_site = WP_Network::get_by_path($domain, $path, 1); } } // The network declared by the site trumps any constants. if ($current_blog && $current_blog->site_id != $current_site->id) { $current_site = WP_Network::get_instance($current_blog->site_id); } // No network has been found, bail. if (empty($current_site)) { /** This action is documented in wp-includes/ms-settings.php */ do_action('ms_network_not_found', $domain, $path); return false; } // During activation of a new subdomain, the requested site does not yet exist. if (empty($current_blog) && wp_installing()) { $current_blog = new stdClass(); $current_blog->blog_id = $blog_id = 1; $current_blog->public = 1; } // No site has been found, bail. if (empty($current_blog)) { // We're going to redirect to the network URL, with some possible modifications. $scheme = is_ssl() ? 'https' : 'http'; $destination = "{$scheme}://{$current_site->domain}{$current_site->path}"; /** * Fires when a network can be determined but a site cannot. * * At the time of this action, the only recourse is to redirect somewhere * and exit. If you want to declare a particular site, do so earlier. * * @since 3.9.0 * * @param object $current_site The network that had been determined. * @param string $domain The domain used to search for a site. * @param string $path The path used to search for a site. */ do_action('ms_site_not_found', $current_site, $domain, $path); if ($subdomain && !defined('NOBLOGREDIRECT')) { // For a "subdomain" install, redirect to the signup form specifically. $destination .= 'wp-signup.php?new=' . str_replace('.' . $current_site->domain, '', $domain); } elseif ($subdomain) { // For a "subdomain" install, the NOBLOGREDIRECT constant // can be used to avoid a redirect to the signup form. // Using the ms_site_not_found action is preferred to the constant. if ('%siteurl%' !== NOBLOGREDIRECT) { $destination = NOBLOGREDIRECT; } } elseif (0 === strcasecmp($current_site->domain, $domain)) { /* * If the domain we were searching for matches the network's domain, * it's no use redirecting back to ourselves -- it'll cause a loop. * As we couldn't find a site, we're simply not installed. */ return false; } return $destination; } // Figure out the current network's main site. if (empty($current_site->blog_id)) { if ($current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path) { $current_site->blog_id = $current_blog->blog_id; } elseif (!($current_site->blog_id = wp_cache_get('network:' . $current_site->id . ':main_site', 'site-options'))) { $current_site->blog_id = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path)); wp_cache_add('network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options'); } } return true; }
} if (!$filter_exists) { add_action('admin_init', 'yoast_wpseo_missing_filter', 1); } if (!function_exists('wp_installing')) { /** * We need to define wp_installing in WordPress versions older than 4.4 * * @return bool */ function wp_installing() { return defined('WP_INSTALLING'); } } if (!wp_installing() && ($spl_autoload_exists && $filter_exists)) { add_action('plugins_loaded', 'wpseo_init', 14); if (is_admin()) { new Yoast_Alerts(); if (defined('DOING_AJAX') && DOING_AJAX) { require_once WPSEO_PATH . 'admin/ajax.php'; // Crawl Issue Manager AJAX hooks. new WPSEO_GSC_Ajax(); // Plugin conflict ajax hooks. new Yoast_Plugin_Conflict_Ajax(); if (filter_input(INPUT_POST, 'action') === 'inline-save') { add_action('plugins_loaded', 'wpseo_admin_init', 15); } } else { add_action('plugins_loaded', 'wpseo_admin_init', 15); }
$locale = get_locale(); $locale_file = WP_LANG_DIR . "/{$locale}.php"; if (0 === validate_file($locale) && is_readable($locale_file)) { require $locale_file; } unset($locale_file); // Pull in locale data after loading text domain. require_once ABSPATH . WPINC . '/locale.php'; /** * WordPress Locale object for loading locale domain date and various strings. * @global object $wp_locale * @since 2.1.0 */ $GLOBALS['wp_locale'] = new WP_Locale(); // Load the functions for the active theme, for both parent and child theme if applicable. if (!wp_installing() || 'wp-activate.php' === $pagenow) { if (TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php')) { include STYLESHEETPATH . '/functions.php'; } if (file_exists(TEMPLATEPATH . '/functions.php')) { include TEMPLATEPATH . '/functions.php'; } } /** * Fires after the theme is loaded. * * @since 3.0.0 */ do_action('after_setup_theme'); // Set up current user. $GLOBALS['wp']->init();
/** * Schedule core, theme, and plugin update checks. * * @since 3.1.0 */ function wp_schedule_update_checks() { if (!wp_next_scheduled('wp_version_check') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'wp_version_check'); } if (!wp_next_scheduled('wp_update_plugins') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins'); } if (!wp_next_scheduled('wp_update_themes') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); } if (!wp_next_scheduled('wp_maybe_auto_update') && !wp_installing()) { // Schedule auto updates for 7 a.m. and 7 p.m. in the timezone of the site. $next = strtotime('today 7am'); $now = time(); // Find the next instance of 7 a.m. or 7 p.m., but skip it if it is within 3 hours from now. while ($now + 3 * HOUR_IN_SECONDS > $next) { $next += 12 * HOUR_IN_SECONDS; } $next = $next - get_option('gmt_offset') * HOUR_IN_SECONDS; // Add a random number of minutes, so we don't have all sites trying to update exactly on the hour $next = $next + rand(0, 59) * MINUTE_IN_SECONDS; wp_schedule_event($next, 'twicedaily', 'wp_maybe_auto_update'); } }
/** * Flushes rewrite rules if siteurl, home or page_on_front changed. * * @since 2.1.0 * * @param string $old_value * @param string $value */ function update_home_siteurl($old_value, $value) { if (wp_installing()) { return; } if (is_multisite() && ms_is_switched()) { delete_option('rewrite_rules'); } else { flush_rewrite_rules(); } }
/** * Checks that current theme files 'index.php' and 'style.css' exists. * * Does not check the default theme, which is the fallback and should always exist. * Will switch theme to the fallback theme if current theme does not validate. * You can use the 'validate_current_theme' filter to return false to * disable this functionality. * * @since 1.5.0 * @see WP_DEFAULT_THEME * * @return bool */ function validate_current_theme() { /** * Filter whether to validate the current theme. * * @since 2.7.0 * * @param bool true Validation flag to check the current theme. */ if (wp_installing() || !apply_filters('validate_current_theme', true)) { return true; } if (get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php')) { switch_theme(WP_DEFAULT_THEME); return false; } if (get_stylesheet() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/style.css')) { switch_theme(WP_DEFAULT_THEME); return false; } if (is_child_theme() && !file_exists(get_stylesheet_directory() . '/style.css')) { switch_theme(WP_DEFAULT_THEME); return false; } return true; }
/** * Load custom DB error or display WordPress DB error. * * If a file exists in the wp-content directory named db-error.php, then it will * be loaded instead of displaying the WordPress DB error. If it is not found, * then the WordPress DB error will be displayed instead. * * The WordPress DB error sets the HTTP status header to 500 to try to prevent * search engines from caching the message. Custom DB messages should do the * same. * * This function was backported to WordPress 2.3.2, but originally was added * in WordPress 2.5.0. * * @since 2.3.2 * * @global wpdb $wpdb WordPress database abstraction object. */ function dead_db() { global $wpdb; wp_load_translations_early(); // Load custom DB error template, if present. if (file_exists(WP_CONTENT_DIR . '/db-error.php')) { require_once WP_CONTENT_DIR . '/db-error.php'; die; } // If installing or in the admin, provide the verbose message. if (wp_installing() || defined('WP_ADMIN')) { wp_die($wpdb->error); } // Otherwise, be terse. status_header(500); nocache_headers(); header('Content-Type: text/html; charset=utf-8'); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"<?php if (is_rtl()) { echo ' dir="rtl"'; } ?> > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php _e('Database Error'); ?> </title> </head> <body> <h1><?php _e('Error establishing a database connection'); ?> </h1> </body> </html> <?php die; }
// If you don't have a site with the same domain/path as a network, you're pretty screwed, but: $current_site = WP_Network::get_by_path($domain, $path, 1); } } // The network declared by the site trumps any constants. if ($current_blog && $current_blog->site_id != $current_site->id) { $current_site = WP_Network::get_instance($current_blog->site_id); } // No network has been found, bail. if (empty($current_site)) { /** This action is documented in wp-includes/ms-settings.php */ do_action('ms_network_not_found', $domain, $path); ms_not_installed($domain, $path); } // During activation of a new subdomain, the requested site does not yet exist. if (empty($current_blog) && wp_installing()) { $current_blog = new stdClass(); $current_blog->blog_id = $blog_id = 1; $current_blog->public = 1; } // No site has been found, bail. if (empty($current_blog)) { // We're going to redirect to the network URL, with some possible modifications. $scheme = is_ssl() ? 'https' : 'http'; $destination = "{$scheme}://{$current_site->domain}{$current_site->path}"; /** * Fires when a network can be determined but a site cannot. * * At the time of this action, the only recourse is to redirect somewhere * and exit. If you want to declare a particular site, do so earlier. *
/** * Retrieve an array of active and valid plugin files. * * While upgrading or installing WordPress, no plugins are returned. * * The default directory is wp-content/plugins. To change the default * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` * in wp-config.php. * * @since 3.0.0 * @access private * * @return array Files. */ function wp_get_active_and_valid_plugins() { $plugins = array(); $active_plugins = (array) get_option('active_plugins', array()); if (empty($active_plugins) || wp_installing()) { return $plugins; } $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; foreach ($active_plugins as $plugin) { if (!validate_file($plugin) && '.php' == substr($plugin, -4) && file_exists(WP_PLUGIN_DIR . '/' . $plugin) && (!$network_plugins || !in_array(WP_PLUGIN_DIR . '/' . $plugin, $network_plugins))) { $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; } } return $plugins; }
/** * Schedule update of the network-wide counts for the current network. * * @since 3.1.0 */ function wp_schedule_update_network_counts() { if (!wp_next_scheduled('update_network_counts') && !wp_installing()) { wp_schedule_event(time(), 'twicedaily', 'update_network_counts'); } }