/**
* @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]));
}
/**
* 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);
}
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
/**
* 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;
}
/**
* 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;
}
/**
* 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;
//.........这里部分代码省略.........
/**
*
* @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
//.........这里部分代码省略.........
/**
* 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);
}
/**
* 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);
}
}
/**
* 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);
}
require_once ABSPATH . 'wp-admin/admin-footer.php';
exit;
} else {
$plugins_to_delete = count($plugins);
}
// endif verify-delete
$delete_result = delete_plugins($plugins);
set_transient('plugins_delete_result_' . $user_ID, $delete_result);
//Store the result in a cache rather than a URL param due to object type & length
wp_redirect(self_admin_url("plugins.php?deleted={$plugins_to_delete}&plugin_status={$status}&paged={$page}&s={$s}"));
exit;
case 'clear-recent-list':
if (!is_network_admin()) {
update_option('recently_activated', array());
} else {
update_network_option('recently_activated', array());
}
break;
}
}
$wp_list_table->prepare_items();
wp_enqueue_script('plugin-install');
add_thickbox();
add_screen_option('per_page', array('default' => 999));
get_current_screen()->add_help_tab(array('id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.') . '</p>' . '<p>' . sprintf(__('You can find additional plugins for your site by using the <a href="%1$s">Plugin Browser/Installer</a> functionality or by browsing the <a href="%2$s" target="_blank">WordPress Plugin Directory</a> directly and installing new plugins manually. To manually install a plugin you generally just need to upload the plugin file into your %3$s directory. Once a plugin has been installed, you can activate it here.'), 'plugin-install.php', 'https://wordpress.org/plugins/', '<code>/wp-content/plugins</code>') . '</p>'));
get_current_screen()->add_help_tab(array('id' => 'compatibility-problems', 'title' => __('Troubleshooting'), 'content' => '<p>' . __('Most of the time, plugins play nicely with the core of WordPress and with other plugins. Sometimes, though, a plugin’s code will get in the way of another plugin, causing compatibility issues. If your site starts doing strange things, this may be the problem. Try deactivating all your plugins and re-activating them in various combinations until you isolate which one(s) caused the issue.') . '</p>' . '<p>' . sprintf(__('If something goes wrong with a plugin and you can’t use WordPress, delete or rename that file in the %s directory and it will be automatically deactivated.'), '<code>' . WP_PLUGIN_DIR . '</code>') . '</p>'));
get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="https://codex.wordpress.org/Managing_Plugins#Plugin_Management" target="_blank">Documentation on Managing Plugins</a>') . '</p>' . '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>');
$title = __('Plugins');
$parent_file = 'plugins.php';
require_once ABSPATH . 'wp-admin/admin-header.php';
$invalid = validate_active_plugins();
请发表评论