本文整理汇总了PHP中update_network_option函数的典型用法代码示例。如果您正苦于以下问题:PHP update_network_option函数的具体用法?PHP update_network_option怎么用?PHP update_network_option使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_network_option函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_update_network_option_is_not_stored_as_autoload_option
/**
* @ticket 22846
*/
public function test_update_network_option_is_not_stored_as_autoload_option()
{
$key = rand_str();
if (is_multisite()) {
$this->markTestSkipped('Does not apply when used in multisite.');
}
update_network_option(null, $key, 'Not an autoload option');
$options = wp_load_alloptions();
$this->assertFalse(isset($options[$key]));
}
示例2: __invoke
/**
* Get/set sys version.
*
* @since 160531 Sys options.
*
* @param string $key Sys option key.
* @param mixed|null $value If setting value.
* @param bool $autoload Autoload option key?
*
* @return mixed|null Sys option value or `null`.
*/
public function __invoke(string $key, $value = null, bool $autoload = true)
{
$key = $this->App->Config->©brand['©var'] . '_' . $key;
if ($this->App->Config->§specs['§is_network_wide'] && $this->Wp->is_multisite) {
if (isset($value)) {
update_network_option(null, $key, $value);
}
if (($value = get_network_option(null, $key)) === null || $value === false) {
add_network_option(null, $key, ':null');
// Autoload impossible.
// These will not autoload and there is no way to change this.
}
} else {
// Default.
if (isset($value)) {
update_option($key, $value);
}
if (($value = get_option($key)) === null || $value === false) {
add_option($key, ':null', '', $autoload ? 'yes' : 'no');
}
}
return $value === null || $value === false || $value === ':null' ? null : $value;
}
示例3: save_modules
/**
* Saves the modules persistently.
*
* @since 3.0.0
*
* @return bool Whether or not the modules were saved successfully.
*/
public function save_modules()
{
return update_network_option(null, $this->option, $this->states);
}
示例4: __
if (is_subdomain_install()) {
echo '<p class="description">' . __('If registration is disabled, please set <code>NOBLOGREDIRECT</code> in <code>wp-config.php</code> to a URL you will redirect visitors to if they visit a non-existent site.') . '</p>';
}
?>
</fieldset>
</td>
</tr>
<tr>
<th scope="row"><?php
_e('Registration notification');
?>
</th>
<?php
if (!get_network_option('registrationnotification')) {
update_network_option('registrationnotification', 'yes');
}
?>
<td>
<label><input name="registrationnotification" type="checkbox" id="registrationnotification" value="yes"<?php
checked(get_network_option('registrationnotification'), 'yes');
?>
/> <?php
_e('Send the network admin an email notification every time someone registers a site or user account.');
?>
</label>
</td>
</tr>
<tr id="addnewusers">
<th scope="row"><?php
示例5: revoke_super_admin
/**
* Revokes Super Admin privileges.
*
* @since 3.0.0
*
* @global array $super_admins
*
* @param int $user_id ID of the user Super Admin privileges to be revoked from.
* @return bool True on success, false on failure. This can fail when the user's email
* is the network admin email or when the `$super_admins` global is defined.
*/
function revoke_super_admin($user_id)
{
// If global super_admins override is defined, there is nothing to do here.
if (isset($GLOBALS['super_admins'])) {
return false;
}
/**
* Fires before the user's Super Admin privileges are revoked.
*
* @since 3.0.0
*
* @param int $user_id ID of the user Super Admin privileges are being revoked from.
*/
do_action('revoke_super_admin', $user_id);
// Directly fetch site_admins instead of using get_super_admins()
$super_admins = get_network_option('site_admins', array('admin'));
$user = get_userdata($user_id);
if ($user && 0 !== strcasecmp($user->user_email, get_network_option('admin_email'))) {
if (false !== ($key = array_search($user->user_login, $super_admins))) {
unset($super_admins[$key]);
update_network_option('site_admins', $super_admins);
/**
* Fires after the user's Super Admin privileges are revoked.
*
* @since 3.0.0
*
* @param int $user_id ID of the user Super Admin privileges were revoked from.
*/
do_action('revoked_super_admin', $user_id);
return true;
}
}
return false;
}
示例6: set_site_transient
/**
* Set/update the value of a site transient.
*
* You do not need to serialize values, if the value needs to be serialize, then
* it will be serialized before it is set.
*
* @since 2.9.0
*
* @see set_transient()
*
* @param string $transient Transient name. Expected to not be SQL-escaped. Must be
* 40 characters or fewer in length.
* @param mixed $value Transient value. Expected to not be SQL-escaped.
* @param int $expiration Optional. Time until expiration in seconds. Default 0.
* @return bool False if value was not set and true if value was set.
*/
function set_site_transient($transient, $value, $expiration = 0)
{
/**
* Filter the value of a specific site transient before it is set.
*
* The dynamic portion of the hook name, `$transient`, refers to the transient name.
*
* @since 3.0.0
* @since 4.4.0 The `$transient` parameter was added
*
* @param mixed $value Value of site transient.
* @param string $transient Transient name.
*/
$value = apply_filters('pre_set_site_transient_' . $transient, $value, $transient);
$expiration = (int) $expiration;
if (wp_using_ext_object_cache()) {
$result = wp_cache_set($transient, $value, 'site-transient', $expiration);
} else {
$transient_timeout = '_site_transient_timeout_' . $transient;
$option = '_site_transient_' . $transient;
if (false === get_network_option($option)) {
if ($expiration) {
add_network_option($transient_timeout, time() + $expiration);
}
$result = add_network_option($option, $value);
} else {
if ($expiration) {
update_network_option($transient_timeout, time() + $expiration);
}
$result = update_network_option($option, $value);
}
}
if ($result) {
/**
* Fires after the value for a specific site transient has been set.
*
* The dynamic portion of the hook name, `$transient`, refers to the transient name.
*
* @since 3.0.0
* @since 4.4.0 The `$transient` parameter was added
*
* @param mixed $value Site transient value.
* @param int $expiration Time until expiration in seconds. Default 0.
* @param string $transient Transient name.
*/
do_action('set_site_transient_' . $transient, $value, $expiration, $transient);
/**
* Fires after the value for a site transient has been set.
*
* @since 3.0.0
*
* @param string $transient The name of the site transient.
* @param mixed $value Site transient value.
* @param int $expiration Time until expiration in seconds. Default 0.
*/
do_action('setted_site_transient', $transient, $value, $expiration);
}
return $result;
}
示例7: send_email
/**
* Sends an email upon the completion or failure of a background core update.
*
* @since 3.7.0
* @access protected
*
* @global string $wp_version
*
* @param string $type The type of email to send. Can be one of 'success', 'fail', 'manual', 'critical'.
* @param object $core_update The update offer that was attempted.
* @param mixed $result Optional. The result for the core update. Can be WP_Error.
*/
protected function send_email($type, $core_update, $result = null)
{
update_network_option('auto_core_update_notified', array('type' => $type, 'email' => get_network_option('admin_email'), 'version' => $core_update->current, 'timestamp' => time()));
$next_user_core_update = get_preferred_from_update_core();
// If the update transient is empty, use the update we just performed
if (!$next_user_core_update) {
$next_user_core_update = $core_update;
}
$newer_version_available = 'upgrade' == $next_user_core_update->response && version_compare($next_user_core_update->version, $core_update->version, '>');
/**
* Filter whether to send an email following an automatic background core update.
*
* @since 3.7.0
*
* @param bool $send Whether to send the email. Default true.
* @param string $type The type of email to send. Can be one of
* 'success', 'fail', 'critical'.
* @param object $core_update The update offer that was attempted.
* @param mixed $result The result for the core update. Can be WP_Error.
*/
if ('manual' !== $type && !apply_filters('auto_core_update_send_email', true, $type, $core_update, $result)) {
return;
}
switch ($type) {
case 'success':
// We updated.
/* translators: 1: Site name, 2: WordPress version number. */
$subject = __('[%1$s] Your site has updated to WordPress %2$s');
break;
case 'fail':
// We tried to update but couldn't.
// We tried to update but couldn't.
case 'manual':
// We can't update (and made no attempt).
/* translators: 1: Site name, 2: WordPress version number. */
$subject = __('[%1$s] WordPress %2$s is available. Please update!');
break;
case 'critical':
// We tried to update, started to copy files, then things went wrong.
/* translators: 1: Site name. */
$subject = __('[%1$s] URGENT: Your site may be down due to a failed update');
break;
default:
return;
}
// If the auto update is not to the latest version, say that the current version of WP is available instead.
$version = 'success' === $type ? $core_update->current : $next_user_core_update->current;
$subject = sprintf($subject, wp_specialchars_decode(get_option('blogname'), ENT_QUOTES), $version);
$body = '';
switch ($type) {
case 'success':
$body .= sprintf(__('Howdy! Your site at %1$s has been updated automatically to WordPress %2$s.'), home_url(), $core_update->current);
$body .= "\n\n";
if (!$newer_version_available) {
$body .= __('No further action is needed on your part.') . ' ';
}
// Can only reference the About screen if their update was successful.
list($about_version) = explode('-', $core_update->current, 2);
$body .= sprintf(__("For more on version %s, see the About WordPress screen:"), $about_version);
$body .= "\n" . admin_url('about.php');
if ($newer_version_available) {
$body .= "\n\n" . sprintf(__('WordPress %s is also now available.'), $next_user_core_update->current) . ' ';
$body .= __('Updating is easy and only takes a few moments:');
$body .= "\n" . network_admin_url('update-core.php');
}
break;
case 'fail':
case 'manual':
$body .= sprintf(__('Please update your site at %1$s to WordPress %2$s.'), home_url(), $next_user_core_update->current);
$body .= "\n\n";
// Don't show this message if there is a newer version available.
// Potential for confusion, and also not useful for them to know at this point.
if ('fail' == $type && !$newer_version_available) {
$body .= __('We tried but were unable to update your site automatically.') . ' ';
}
$body .= __('Updating is easy and only takes a few moments:');
$body .= "\n" . network_admin_url('update-core.php');
break;
case 'critical':
if ($newer_version_available) {
$body .= sprintf(__('Your site at %1$s experienced a critical failure while trying to update WordPress to version %2$s.'), home_url(), $core_update->current);
} else {
$body .= sprintf(__('Your site at %1$s experienced a critical failure while trying to update to the latest version of WordPress, %2$s.'), home_url(), $core_update->current);
}
$body .= "\n\n" . __("This means your site may be offline or broken. Don't panic; this can be fixed.");
$body .= "\n\n" . __("Please check out your site now. It's possible that everything is working. If it says you need to update, you should do so:");
$body .= "\n" . network_admin_url('update-core.php');
break;
//.........这里部分代码省略.........
示例8: prepare_items
/**
*
* @global string $status
* @global type $plugins
* @global array $totals
* @global int $page
* @global string $orderby
* @global string $order
* @global string $s
*/
public function prepare_items()
{
global $status, $plugins, $totals, $page, $orderby, $order, $s;
wp_reset_vars(array('orderby', 'order', 's'));
/**
* Filter the full array of plugins to list in the Plugins list table.
*
* @since 3.0.0
*
* @see get_plugins()
*
* @param array $plugins An array of plugins to display in the list table.
*/
$plugins = array('all' => apply_filters('all_plugins', get_plugins()), 'search' => array(), 'active' => array(), 'inactive' => array(), 'recently_activated' => array(), 'upgrade' => array(), 'mustuse' => array(), 'dropins' => array());
$screen = $this->screen;
if (!is_multisite() || $screen->in_admin('network') && current_user_can('manage_network_plugins')) {
/**
* Filter whether to display the advanced plugins list table.
*
* There are two types of advanced plugins - must-use and drop-ins -
* which can be used in a single site or Multisite network.
*
* The $type parameter allows you to differentiate between the type of advanced
* plugins to filter the display of. Contexts include 'mustuse' and 'dropins'.
*
* @since 3.0.0
*
* @param bool $show Whether to show the advanced plugins for the specified
* plugin type. Default true.
* @param string $type The plugin type. Accepts 'mustuse', 'dropins'.
*/
if (apply_filters('show_advanced_plugins', true, 'mustuse')) {
$plugins['mustuse'] = get_mu_plugins();
}
/** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
if (apply_filters('show_advanced_plugins', true, 'dropins')) {
$plugins['dropins'] = get_dropins();
}
if (current_user_can('update_plugins')) {
$current = get_site_transient('update_plugins');
foreach ((array) $plugins['all'] as $plugin_file => $plugin_data) {
if (isset($current->response[$plugin_file])) {
$plugins['all'][$plugin_file]['update'] = true;
$plugins['upgrade'][$plugin_file] = $plugins['all'][$plugin_file];
}
}
}
}
set_transient('plugin_slugs', array_keys($plugins['all']), DAY_IN_SECONDS);
if ($screen->in_admin('network')) {
$recently_activated = get_network_option('recently_activated', array());
} else {
$recently_activated = get_option('recently_activated', array());
}
foreach ($recently_activated as $key => $time) {
if ($time + WEEK_IN_SECONDS < time()) {
unset($recently_activated[$key]);
}
}
if ($screen->in_admin('network')) {
update_network_option('recently_activated', $recently_activated);
} else {
update_option('recently_activated', $recently_activated);
}
$plugin_info = get_site_transient('update_plugins');
foreach ((array) $plugins['all'] as $plugin_file => $plugin_data) {
// Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide.
if (isset($plugin_info->response[$plugin_file])) {
$plugins['all'][$plugin_file] = $plugin_data = array_merge((array) $plugin_info->response[$plugin_file], $plugin_data);
// Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade
if (isset($plugins['upgrade'][$plugin_file])) {
$plugins['upgrade'][$plugin_file] = $plugin_data = array_merge((array) $plugin_info->response[$plugin_file], $plugin_data);
}
} elseif (isset($plugin_info->no_update[$plugin_file])) {
$plugins['all'][$plugin_file] = $plugin_data = array_merge((array) $plugin_info->no_update[$plugin_file], $plugin_data);
// Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade
if (isset($plugins['upgrade'][$plugin_file])) {
$plugins['upgrade'][$plugin_file] = $plugin_data = array_merge((array) $plugin_info->no_update[$plugin_file], $plugin_data);
}
}
// Filter into individual sections
if (is_multisite() && !$screen->in_admin('network') && is_network_only_plugin($plugin_file) && !is_plugin_active($plugin_file)) {
// On the non-network screen, filter out network-only plugins as long as they're not individually activated
unset($plugins['all'][$plugin_file]);
} elseif (!$screen->in_admin('network') && is_plugin_active_for_network($plugin_file)) {
// On the non-network screen, filter out network activated plugins
unset($plugins['all'][$plugin_file]);
} elseif (!$screen->in_admin('network') && is_plugin_active($plugin_file) || $screen->in_admin('network') && is_plugin_active_for_network($plugin_file)) {
// On the non-network screen, populate the active list with plugins that are individually activated
// On the network-admin screen, populate the active list with plugins that are network activated
//.........这里部分代码省略.........
示例9: undismiss_core_update
/**
*
* @param string $version
* @param string $locale
* @return bool
*/
function undismiss_core_update($version, $locale)
{
$dismissed = get_network_option('dismissed_update_core');
$key = $version . '|' . $locale;
if (!isset($dismissed[$key])) {
return false;
}
unset($dismissed[$key]);
return update_network_option('dismissed_update_core', $dismissed);
}
示例10: wp_die
require_once ABSPATH . 'wp-admin/admin-header.php';
if (!current_user_can('manage_network')) {
wp_die(__('You do not have permission to access this page.'), 403);
}
echo '<div class="wrap">';
echo '<h1>' . __('Upgrade Network') . '</h1>';
$action = isset($_GET['action']) ? $_GET['action'] : 'show';
switch ($action) {
case "upgrade":
$n = isset($_GET['n']) ? intval($_GET['n']) : 0;
if ($n < 5) {
/**
* @global string $wp_db_version
*/
global $wp_db_version;
update_network_option('wpmu_upgrade_site', $wp_db_version);
}
$blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A);
if (empty($blogs)) {
echo '<p>' . __('All done!') . '</p>';
break;
}
echo "<ul>";
foreach ((array) $blogs as $details) {
switch_to_blog($details['blog_id']);
$siteurl = site_url();
$upgrade_url = admin_url('upgrade.php?step=upgrade_db');
restore_current_blog();
echo "<li>{$siteurl}</li>";
$response = wp_remote_get($upgrade_url, array('timeout' => 120, 'httpversion' => '1.1'));
if (is_wp_error($response)) {
示例11: handle_update_network
/**
* Handle the request to update a network
*
* @since 2.0.0
*/
private function handle_update_network()
{
// Unslash posted data for sanitization
$posted = wp_unslash($_POST);
// Cast
$network_id = !empty($posted['network_id']) ? (int) $posted['network_id'] : 0;
// Bail if invalid network
if (!get_network($network_id)) {
wp_die(esc_html__('Invalid network id.', 'wp-multi-network'));
}
// Title
$network_title = isset($posted['title']) ? sanitize_text_field($posted['title']) : '';
// Domain
$network_domain = isset($posted['domain']) ? str_replace(' ', '', strtolower(sanitize_text_field($posted['domain']))) : '';
// Punycode support
$network_domain = Requests_IDNAEncoder::encode($network_domain);
// Path
$network_path = isset($posted['path']) ? str_replace(' ', '', strtolower(sanitize_text_field($posted['path']))) : '';
// Bail if missing fields
if (empty($network_title) || empty($network_domain) || empty($network_path)) {
$this->handle_redirect(array('id' => $network_id, 'action' => 'edit_network', 'network_updated' => '0'));
}
// Update domain & path
$updated = update_network($network_id, $network_domain, $network_path);
$success = '0';
// Maybe update network title
if (!is_wp_error($updated)) {
update_network_option($network_id, 'site_name', $network_title);
$success = '1';
}
// Handle redirect
$this->handle_redirect(array('id' => $network_id, 'action' => 'edit_network', 'network_updated' => $success));
}
示例12: wp_ajax_wp_compression_test
/**
* Ajax handler for compression testing.
*
* @since 3.1.0
*/
function wp_ajax_wp_compression_test()
{
if (!current_user_can('manage_options')) {
wp_die(-1);
}
if (ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler')) {
update_network_option('can_compress_scripts', 0);
wp_die(0);
}
if (isset($_GET['test'])) {
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Content-Type: application/javascript; charset=UTF-8');
$force_gzip = defined('ENFORCE_GZIP') && ENFORCE_GZIP;
$test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
if (1 == $_GET['test']) {
echo $test_str;
wp_die();
} elseif (2 == $_GET['test']) {
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
wp_die(-1);
}
if (false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && !$force_gzip) {
header('Content-Encoding: deflate');
$out = gzdeflate($test_str, 1);
} elseif (false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode')) {
header('Content-Encoding: gzip');
$out = gzencode($test_str, 1);
} else {
wp_die(-1);
}
echo $out;
wp_die();
} elseif ('no' == $_GET['test']) {
update_network_option('can_compress_scripts', 0);
} elseif ('yes' == $_GET['test']) {
update_network_option('can_compress_scripts', 1);
}
}
wp_die(0);
}
示例13: deactivate_plugins
/**
* Deactivate a single plugin or multiple plugins.
*
* The deactivation hook is disabled by the plugin upgrader by using the $silent
* parameter.
*
* @since 2.5.0
*
* @param string|array $plugins Single plugin or list of plugins to deactivate.
* @param bool $silent Prevent calling deactivation hooks. Default is false.
* @param mixed $network_wide Whether to deactivate the plugin for all sites in the network.
* A value of null (the default) will deactivate plugins for both the site and the network.
*/
function deactivate_plugins($plugins, $silent = false, $network_wide = null)
{
if (is_multisite()) {
$network_current = get_network_option('active_sitewide_plugins', array());
}
$current = get_option('active_plugins', array());
$do_blog = $do_network = false;
foreach ((array) $plugins as $plugin) {
$plugin = plugin_basename(trim($plugin));
if (!is_plugin_active($plugin)) {
continue;
}
$network_deactivating = false !== $network_wide && is_plugin_active_for_network($plugin);
if (!$silent) {
/**
* Fires before a plugin is deactivated.
*
* If a plugin is silently deactivated (such as during an update),
* this hook does not fire.
*
* @since 2.9.0
*
* @param string $plugin Plugin path to main plugin file with plugin data.
* @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network
* or just the current site. Multisite only. Default is false.
*/
do_action('deactivate_plugin', $plugin, $network_deactivating);
}
if (false !== $network_wide) {
if (is_plugin_active_for_network($plugin)) {
$do_network = true;
unset($network_current[$plugin]);
} elseif ($network_wide) {
continue;
}
}
if (true !== $network_wide) {
$key = array_search($plugin, $current);
if (false !== $key) {
$do_blog = true;
unset($current[$key]);
}
}
if (!$silent) {
/**
* Fires as a specific plugin is being deactivated.
*
* This hook is the "deactivation" hook used internally by
* {@see register_deactivation_hook()}. The dynamic portion of the
* hook name, `$plugin`, refers to the plugin basename.
*
* If a plugin is silently deactivated (such as during an update),
* this hook does not fire.
*
* @since 2.0.0
*
* @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network
* or just the current site. Multisite only. Default is false.
*/
do_action('deactivate_' . $plugin, $network_deactivating);
/**
* Fires after a plugin is deactivated.
*
* If a plugin is silently deactivated (such as during an update),
* this hook does not fire.
*
* @since 2.9.0
*
* @param string $plugin Plugin basename.
* @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network
* or just the current site. Multisite only. Default false.
*/
do_action('deactivated_plugin', $plugin, $network_deactivating);
}
}
if ($do_blog) {
update_option('active_plugins', $current);
}
if ($do_network) {
update_network_option('active_sitewide_plugins', $network_current);
}
}
示例14: upgrade_network
/**
* Executes network-level upgrade routines.
*
* @since 3.0.0
*
* @global int $wp_current_db_version
* @global wpdb $wpdb
*/
function upgrade_network()
{
global $wp_current_db_version, $wpdb;
// Always.
if (is_main_network()) {
/*
* Deletes all expired transients. The multi-table delete syntax is used
* to delete the transient record from table a, and the corresponding
* transient_timeout record from table b.
*/
$time = time();
$sql = "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b\n\t\t\tWHERE a.meta_key LIKE %s\n\t\t\tAND a.meta_key NOT LIKE %s\n\t\t\tAND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )\n\t\t\tAND b.meta_value < %d";
$wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', $time));
}
// 2.8.
if ($wp_current_db_version < 11549) {
$wpmu_sitewide_plugins = get_network_option('wpmu_sitewide_plugins');
$active_sitewide_plugins = get_network_option('active_sitewide_plugins');
if ($wpmu_sitewide_plugins) {
if (!$active_sitewide_plugins) {
$sitewide_plugins = (array) $wpmu_sitewide_plugins;
} else {
$sitewide_plugins = array_merge((array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins);
}
update_network_option('active_sitewide_plugins', $sitewide_plugins);
}
delete_network_option('wpmu_sitewide_plugins');
delete_network_option('deactivated_sitewide_plugins');
$start = 0;
while ($rows = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT {$start}, 20")) {
foreach ($rows as $row) {
$value = $row->meta_value;
if (!@unserialize($value)) {
$value = stripslashes($value);
}
if ($value !== $row->meta_value) {
update_network_option($row->meta_key, $value);
}
}
$start += 20;
}
}
// 3.0
if ($wp_current_db_version < 13576) {
update_network_option('global_terms_enabled', '1');
}
// 3.3
if ($wp_current_db_version < 19390) {
update_network_option('initial_db_version', $wp_current_db_version);
}
if ($wp_current_db_version < 19470) {
if (false === get_network_option('active_sitewide_plugins')) {
update_network_option('active_sitewide_plugins', array());
}
}
// 3.4
if ($wp_current_db_version < 20148) {
// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
$allowedthemes = get_network_option('allowedthemes');
$allowed_themes = get_network_option('allowed_themes');
if (false === $allowedthemes && is_array($allowed_themes) && $allowed_themes) {
$converted = array();
$themes = wp_get_themes();
foreach ($themes as $stylesheet => $theme_data) {
if (isset($allowed_themes[$theme_data->get('Name')])) {
$converted[$stylesheet] = true;
}
}
update_network_option('allowedthemes', $converted);
delete_network_option('allowed_themes');
}
}
// 3.5
if ($wp_current_db_version < 21823) {
update_network_option('ms_files_rewriting', '1');
}
// 3.5.2
if ($wp_current_db_version < 24448) {
$illegal_names = get_network_option('illegal_names');
if (is_array($illegal_names) && count($illegal_names) === 1) {
$illegal_name = reset($illegal_names);
$illegal_names = explode(' ', $illegal_name);
update_network_option('illegal_names', $illegal_names);
}
}
// 4.2
if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
if (wp_should_upgrade_global_tables()) {
$wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
$wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
$wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
$wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
//.........这里部分代码省略.........
示例15: wp_update_network_user_counts
/**
* Update the network-wide user count.
*
* @since 3.7.0
*
* @global wpdb $wpdb
*/
function wp_update_network_user_counts()
{
global $wpdb;
$count = $wpdb->get_var("SELECT COUNT(ID) as c FROM {$wpdb->users} WHERE spam = '0' AND deleted = '0'");
update_network_option('user_count', $count);
}