/** * Get the "dashboard blog", the blog where users without a blog edit their profile data. * Dashboard blog functionality was removed in WordPress 3.1, replaced by the user admin. * * @since MU * @deprecated 3.1.0 Use get_blog_details() * @see get_blog_details() * * @return int Current site ID. */ function get_dashboard_blog() { _deprecated_function(__FUNCTION__, '3.1'); if ($blog = get_network_option('dashboard_blog')) { return get_blog_details($blog); } return get_blog_details($GLOBALS['current_site']->blog_id); }
/** * Deactivates the given plugins network-wide. * * @since 3.0.0 * * @param string[] $plugins Plugin base names (or partials). These will be matched against all active plugins. * * @return string[] An array with all plugins that were deactivated. */ public function deactivate_plugins(array $plugins) { $active_plugins = (array) get_network_option(null, NetworkPluginDeactivator::OPTION, []); $plugins_to_deactivate = $this->get_plugins_to_deactivate(array_keys($active_plugins), $plugins); if (!$plugins_to_deactivate) { return $plugins_to_deactivate; } $active_plugins = array_diff_key($active_plugins, array_flip($plugins_to_deactivate)); update_site_option(NetworkPluginDeactivator::OPTION, $active_plugins); return $plugins_to_deactivate; }
/** * Retrieves the current locale. * * If the locale is set, then it will filter the locale in the {@see 'locale'} * filter hook and return the value. * * If the locale is not set already, then the WPLANG constant is used if it is * defined. Then it is filtered through the {@see 'locale'} filter hook and * the value for the locale global set and the locale is returned. * * The process to get the locale should only be done once, but the locale will * always be filtered using the {@see 'locale'} hook. * * @since 1.5.0 * * @global string $locale * @global string $wp_local_package * * @return string The locale of the blog or from the {@see 'locale'} hook. */ function get_locale() { global $locale, $wp_local_package; if (isset($locale)) { /** * Filter WordPress install's locale ID. * * @since 1.5.0 * * @param string $locale The locale ID. */ return apply_filters('locale', $locale); } if (isset($wp_local_package)) { $locale = $wp_local_package; } // WPLANG was defined in wp-config. if (defined('WPLANG')) { $locale = WPLANG; } // If multisite, check options. if (is_multisite()) { // Don't check blog option when installing. if (defined('WP_INSTALLING') || false === ($ms_locale = get_option('WPLANG'))) { $ms_locale = get_network_option('WPLANG'); } if ($ms_locale !== false) { $locale = $ms_locale; } } else { $db_locale = get_option('WPLANG'); if ($db_locale !== false) { $locale = $db_locale; } } if (empty($locale)) { $locale = 'en_US'; } /** This filter is documented in wp-includes/l10n.php */ return apply_filters('locale', $locale); }
/** * Defines Multisite upload constants. * * Exists for backward compatibility with legacy file-serving through * wp-includes/ms-files.php (wp-content/blogs.php in MU). * * @since 3.0.0 * * @global wpdb $wpdb */ function ms_upload_constants() { global $wpdb; // This filter is attached in ms-default-filters.php but that file is not included during SHORTINIT. add_filter('default_site_option_ms_files_rewriting', '__return_true'); if (!get_network_option('ms_files_rewriting')) { return; } // Base uploads dir relative to ABSPATH if (!defined('UPLOADBLOGSDIR')) { define('UPLOADBLOGSDIR', 'wp-content/blogs.dir'); } // Note, the main site in a post-MU network uses wp-content/uploads. // This is handled in wp_upload_dir() by ignoring UPLOADS for this case. if (!defined('UPLOADS')) { define('UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/"); // Uploads dir relative to ABSPATH if ('wp-content/blogs.dir' == UPLOADBLOGSDIR && !defined('BLOGUPLOADDIR')) { define('BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/"); } } }
/** * 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; }
if (!is_multisite()) { wp_die(__('Multisite support is not enabled.')); } if (!current_user_can('manage_network_themes')) { wp_die(__('You do not have sufficient permissions to manage network themes.')); } $wp_list_table = _get_list_table('WP_MS_Themes_List_Table'); $pagenum = $wp_list_table->get_pagenum(); $action = $wp_list_table->current_action(); $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; // Clean up request URI from temporary args for screen options/paging uri's to work as expected. $temp_args = array('enabled', 'disabled', 'deleted', 'error'); $_SERVER['REQUEST_URI'] = remove_query_arg($temp_args, $_SERVER['REQUEST_URI']); $referer = remove_query_arg($temp_args, wp_get_referer()); if ($action) { $allowed_themes = get_network_option('allowedthemes'); switch ($action) { case 'enable': check_admin_referer('enable-theme_' . $_GET['theme']); $allowed_themes[$_GET['theme']] = true; update_network_option('allowedthemes', $allowed_themes); if (false === strpos($referer, '/network/themes.php')) { wp_redirect(network_admin_url('themes.php?enabled=1')); } else { wp_safe_redirect(add_query_arg('enabled', 1, $referer)); } exit; case 'disable': check_admin_referer('disable-theme_' . $_GET['theme']); unset($allowed_themes[$_GET['theme']]); update_network_option('allowedthemes', $allowed_themes);
/** * 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; }
/** * @dataProvider data_network_id_parameter * * @param $network_id * @param $expected_response */ function test_get_network_option_network_id_parameter($network_id, $expected_response) { $option = rand_str(); $this->assertEquals($expected_response, get_network_option($network_id, $option, true)); }
<td><input name="blog[title]" type="text" class="regular-text" id="site-title" /></td> </tr> <?php $languages = get_available_languages(); $translations = wp_get_available_translations(); if (!empty($languages) || !empty($translations)) { ?> <tr class="form-field form-required"> <th scope="row"><label for="site-language"><?php _e('Site Language'); ?> </label></th> <td> <?php // Network default. $lang = get_network_option('WPLANG'); // Use English if the default isn't available. if (!in_array($lang, $languages)) { $lang = ''; } wp_dropdown_languages(array('name' => 'WPLANG', 'id' => 'site-language', 'selected' => $lang, 'languages' => $languages, 'translations' => $translations, 'show_available_translations' => wp_can_install_language_pack())); ?> </td> </tr> <?php } // Languages. ?> <tr class="form-field form-required"> <th scope="row"><label for="admin-email"><?php _e('Admin Email');
/** * Determine the concatenation and compression settings for scripts and styles. * * @since 2.8.0 * * @global bool $concatenate_scripts * @global bool $compress_scripts * @global bool $compress_css */ function script_concat_settings() { global $concatenate_scripts, $compress_scripts, $compress_css; $compressed_output = ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler'); if (!isset($concatenate_scripts)) { $concatenate_scripts = defined('CONCATENATE_SCRIPTS') ? CONCATENATE_SCRIPTS : true; if (!is_admin() || defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) { $concatenate_scripts = false; } } if (!isset($compress_scripts)) { $compress_scripts = defined('COMPRESS_SCRIPTS') ? COMPRESS_SCRIPTS : true; if ($compress_scripts && (!get_network_option('can_compress_scripts') || $compressed_output)) { $compress_scripts = false; } } if (!isset($compress_css)) { $compress_css = defined('COMPRESS_CSS') ? COMPRESS_CSS : true; if ($compress_css && (!get_network_option('can_compress_scripts') || $compressed_output)) { $compress_css = false; } } }
/** * Retrieve a list of super admins. * * @since 3.0.0 * * @global array $super_admins * * @return array List of super admin logins */ function get_super_admins() { global $super_admins; if (isset($super_admins)) { return $super_admins; } else { return get_network_option('site_admins', array('admin')); } }
/** * Prints step 2 for Network installation process. * * @since 3.0.0 * * @global wpdb $wpdb * * @param WP_Error $errors */ function network_step2($errors = false) { global $wpdb; $hostname = get_clean_basedomain(); $slashed_home = trailingslashit(get_option('home')); $base = parse_url($slashed_home, PHP_URL_PATH); $document_root_fix = str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT'])); $abspath_fix = str_replace('\\', '/', ABSPATH); $home_path = 0 === strpos($abspath_fix, $document_root_fix) ? $document_root_fix . $base : get_home_path(); $wp_siteurl_subdir = preg_replace('#^' . preg_quote($home_path, '#') . '#', '', $abspath_fix); $rewrite_base = !empty($wp_siteurl_subdir) ? ltrim(trailingslashit($wp_siteurl_subdir), '/') : ''; $location_of_wp_config = $abspath_fix; if (!file_exists(ABSPATH . 'wp-config.php') && file_exists(dirname(ABSPATH) . '/wp-config.php')) { $location_of_wp_config = dirname($abspath_fix); } $location_of_wp_config = trailingslashit($location_of_wp_config); // Wildcard DNS message. if (is_wp_error($errors)) { echo '<div class="error">' . $errors->get_error_message() . '</div>'; } if ($_POST) { if (allow_subdomain_install()) { $subdomain_install = allow_subdirectory_install() ? !empty($_POST['subdomain_install']) : true; } else { $subdomain_install = false; } } else { if (is_multisite()) { $subdomain_install = is_subdomain_install(); ?> <p><?php _e('The original configuration steps are shown here for reference.'); ?> </p> <?php } else { $subdomain_install = (bool) $wpdb->get_var("SELECT meta_value FROM {$wpdb->sitemeta} WHERE site_id = 1 AND meta_key = 'subdomain_install'"); ?> <div class="error"><p><strong><?php _e('Warning:'); ?> </strong> <?php _e('An existing WordPress network was detected.'); ?> </p></div> <p><?php _e('Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.'); ?> </p> <?php } } $subdir_match = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?'; $subdir_replacement_01 = $subdomain_install ? '' : '$1'; $subdir_replacement_12 = $subdomain_install ? '$1' : '$2'; if ($_POST || !is_multisite()) { ?> <h3><?php esc_html_e('Enabling the Network'); ?> </h3> <p><?php _e('Complete the following steps to enable the features for creating a network of sites.'); ?> </p> <div class="updated inline"><p><?php if (file_exists($home_path . '.htaccess')) { printf(__('<strong>Caution:</strong> We recommend you back up your existing %1$s and %2$s files.'), '<code>wp-config.php</code>', '<code>.htaccess</code>'); } elseif (file_exists($home_path . 'web.config')) { printf(__('<strong>Caution:</strong> We recommend you back up your existing %1$s and %2$s files.'), '<code>wp-config.php</code>', '<code>web.config</code>'); } else { printf(__('<strong>Caution:</strong> We recommend you back up your existing %s file.'), '<code>wp-config.php</code>'); } ?> </p></div> <?php } ?> <ol> <li><p><?php printf(__('Add the following to your %1$s file in %2$s <strong>above</strong> the line reading <code>/* That’s all, stop editing! Happy blogging. */</code>:'), '<code>wp-config.php</code>', '<code>' . $location_of_wp_config . '</code>'); ?> </p> <textarea class="code" readonly="readonly" cols="100" rows="7"> define('MULTISITE', true); define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> ); define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?> '); define('PATH_CURRENT_SITE', '<?php echo $base; ?> '); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); </textarea> <?php $keys_salts = array('AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => ''); foreach ($keys_salts as $c => $v) { if (defined($c)) { unset($keys_salts[$c]); } } if (!empty($keys_salts)) { $keys_salts_str = ''; $from_api = wp_remote_get('https://api.wordpress.org/secret-key/1.1/salt/'); if (is_wp_error($from_api)) { foreach ($keys_salts as $c => $v) { $keys_salts_str .= "\ndefine( '{$c}', '" . wp_generate_password(64, true, true) . "' );"; } } else { $from_api = explode("\n", wp_remote_retrieve_body($from_api)); foreach ($keys_salts as $c => $v) { $keys_salts_str .= "\ndefine( '{$c}', '" . substr(array_shift($from_api), 28, 64) . "' );"; } } $num_keys_salts = count($keys_salts); ?> <p> <?php if (1 == $num_keys_salts) { printf(__('This unique authentication key is also missing from your %s file.'), '<code>wp-config.php</code>'); } else { printf(__('These unique authentication keys are also missing from your %s file.'), '<code>wp-config.php</code>'); } ?> <?php _e('To make your installation more secure, you should also add:'); ?> </p> <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?> "><?php echo esc_textarea($keys_salts_str); ?> </textarea> <?php } ?> </li> <?php if (iis7_supports_permalinks()) { // IIS doesn't support RewriteBase, all your RewriteBase are belong to us $iis_subdir_match = ltrim($base, '/') . $subdir_match; $iis_rewrite_base = ltrim($base, '/') . $rewrite_base; $iis_subdir_replacement = $subdomain_install ? '' : '{R:1}'; $web_config_file = '<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="WordPress Rule 1" stopProcessing="true"> <match url="^index\\.php$" ignoreCase="false" /> <action type="None" /> </rule>'; if (is_multisite() && get_network_option('ms_files_rewriting')) { $web_config_file .= ' <rule name="WordPress Rule for Files" stopProcessing="true"> <match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" /> <action type="Rewrite" url="' . $iis_rewrite_base . WPINC . '/ms-files.php?file={R:1}" appendQueryString="false" /> </rule>'; } $web_config_file .= ' <rule name="WordPress Rule 2" stopProcessing="true"> <match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" /> <action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" /> </rule> <rule name="WordPress Rule 3" stopProcessing="true"> <match url="^" ignoreCase="false" /> <conditions logicalGrouping="MatchAny"> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> </conditions> <action type="None" /> </rule> <rule name="WordPress Rule 4" stopProcessing="true"> <match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" /> <action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" /> </rule> <rule name="WordPress Rule 5" stopProcessing="true"> <match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\\.php)$" ignoreCase="false" /> <action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" /> </rule> <rule name="WordPress Rule 6" stopProcessing="true"> <match url="." ignoreCase="false" /> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration> '; echo '<li><p>'; printf(__('Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:'), '<code>web.config</code>', '<code>' . $home_path . '</code>'); echo '</p>'; if (!$subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content') { echo '<p><strong>' . __('Warning:') . ' ' . __('Subdirectory networks may not be fully compatible with custom wp-content directories.') . '</strong></p>'; } ?> <textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea($web_config_file); ?> </textarea></li> </ol> <?php } else { // end iis7_supports_permalinks(). construct an htaccess file instead: $ms_files_rewriting = ''; if (is_multisite() && get_network_option('ms_files_rewriting')) { $ms_files_rewriting = "\n# uploaded files\nRewriteRule ^"; $ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n"; } $htaccess_file = <<<EOF RewriteEngine On RewriteBase {$base} RewriteRule ^index\\.php\$ - [L] {$ms_files_rewriting} # add a trailing slash to /wp-admin RewriteRule ^{$subdir_match}wp-admin\$ {$subdir_replacement_01}wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L] RewriteRule ^{$subdir_match}(.*\\.php)\$ {$rewrite_base}{$subdir_replacement_12} [L] RewriteRule . index.php [L] EOF; echo '<li><p>'; printf(__('Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:'), '<code>.htaccess</code>', '<code>' . $home_path . '</code>'); echo '</p>'; if (!$subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content') { echo '<p><strong>' . __('Warning:') . ' ' . __('Subdirectory networks may not be fully compatible with custom wp-content directories.') . '</strong></p>'; } ?> <textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count($htaccess_file, "\n") + 1; ?> "> <?php echo esc_textarea($htaccess_file); ?> </textarea></li> </ol> <?php } // end IIS/Apache code branches. if (!is_multisite()) { ?> <p><?php _e('Once you complete these steps, your network is enabled and configured. You will have to log in again.'); ?> <a href="<?php echo esc_url(wp_login_url()); ?> "><?php _e('Log In'); ?> </a></p> <?php } }
check_admin_referer('edit-plugin_' . $file); $newcontent = wp_unslash($_POST['newcontent']); if (is_writeable($real_file)) { $f = fopen($real_file, 'w+'); fwrite($f, $newcontent); fclose($f); $network_wide = is_plugin_active_for_network($file); // Deactivate so we can test it. if (is_plugin_active($file) || isset($_POST['phperror'])) { if (is_plugin_active($file)) { deactivate_plugins($file, true); } if (!is_network_admin()) { update_option('recently_activated', array($file => time()) + (array) get_option('recently_activated')); } else { update_network_option('recently_activated', array($file => time()) + (array) get_network_option('recently_activated')); } wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file={$file}&liveupdate=1&scrollto={$scrollto}&networkwide=" . $network_wide)); exit; } wp_redirect(self_admin_url("plugin-editor.php?file={$file}&a=te&scrollto={$scrollto}")); } else { wp_redirect(self_admin_url("plugin-editor.php?file={$file}&scrollto={$scrollto}")); } exit; default: if (isset($_GET['liveupdate'])) { check_admin_referer('edit-plugin-test_' . $file); $error = validate_plugin($file); if (is_wp_error($error)) { wp_die($error);
/** * Remove deleted blog from 'inpsyde_multilingual' site option and clean up linked elements table. * * @wp-hook delete_blog * * @param int $blog_id ID of the deleted blog. * * @return void */ public function delete_blog($blog_id) { global $wpdb; // Delete relations $site_relations = $this->plugin_data->get('site_relations'); $site_relations->delete_relation($blog_id); // Update network option. $blogs = get_network_option(null, 'inpsyde_multilingual', []); if (isset($blogs[$blog_id])) { unset($blogs[$blog_id]); update_site_option('inpsyde_multilingual', $blogs); } $table = $this->container['multilingualpress.content_relations_table']->name(); // Clean up linked elements table $sql = "\n\t\t\tDELETE\n\t\t\tFROM {$table}\n\t\t\tWHERE ml_source_blogid = %d\n\t\t\t\tOR ml_blogid = %d"; $sql = $wpdb->prepare($sql, $blog_id, $blog_id); $wpdb->query($sql); }
<li><p><?php _e('Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.'); ?> </p></li> <li><?php printf(__('Have you entered your email correctly? You have entered %s, if it’s incorrect, you will not receive your email.'), $user_email); ?> </li> </ul> </p> <?php /** This action is documented in wp-signup.php */ do_action('signup_finished'); } // Main $active_signup = get_network_option('registration', 'none'); /** * Filter the type of site sign-up. * * @since 3.0.0 * * @param string $active_signup String that returns registration type. The value can be * 'all', 'none', 'blog', or 'user'. */ $active_signup = apply_filters('wpmu_active_signup', $active_signup); // Make the signup type translatable. $i18n_signup['all'] = _x('all', 'Multisite active signup type'); $i18n_signup['none'] = _x('none', 'Multisite active signup type'); $i18n_signup['blog'] = _x('blog', 'Multisite active signup type'); $i18n_signup['user'] = _x('user', 'Multisite active signup type'); if (is_super_admin()) {
/** * * @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 $plugins['active'][$plugin_file] = $plugin_data; } else { if (isset($recently_activated[$plugin_file])) { // Populate the recently activated list with plugins that have been recently activated $plugins['recently_activated'][$plugin_file] = $plugin_data; } // Populate the inactive list with plugins that aren't activated $plugins['inactive'][$plugin_file] = $plugin_data; } } if ($s) { $status = 'search'; $plugins['search'] = array_filter($plugins['all'], array($this, '_search_callback')); } $totals = array(); foreach ($plugins as $type => $list) { $totals[$type] = count($list); } if (empty($plugins[$status]) && !in_array($status, array('all', 'search'))) { $status = 'all'; } $this->items = array(); foreach ($plugins[$status] as $plugin_file => $plugin_data) { // Translate, Don't Apply Markup, Sanitize HTML $this->items[$plugin_file] = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true); } $total_this_page = $totals[$status]; if (!$orderby) { $orderby = 'Name'; } else { $orderby = ucfirst($orderby); } $order = strtoupper($order); uasort($this->items, array($this, '_order_callback')); $plugins_per_page = $this->get_items_per_page(str_replace('-', '_', $screen->id . '_per_page'), 999); $start = ($page - 1) * $plugins_per_page; if ($total_this_page > $plugins_per_page) { $this->items = array_slice($this->items, $start, $plugins_per_page); } $this->set_pagination_args(array('total_items' => $total_this_page, 'per_page' => $plugins_per_page)); }
echo '<option value="" selected="selected">' . __('— No role for this site —') . '</option>'; } ?> </select></td></tr> <?php } //!IS_PROFILE_PAGE if (is_multisite() && is_network_admin() && !IS_PROFILE_PAGE && current_user_can('manage_network_options') && !isset($super_admins)) { ?> <tr class="user-super-admin-wrap"><th><?php _e('Super Admin'); ?> </th> <td> <?php if ($profileuser->user_email != get_network_option('admin_email') || !is_super_admin($profileuser->ID)) { ?> <p><label><input type="checkbox" id="super_admin" name="super_admin"<?php checked(is_super_admin($profileuser->ID)); ?> /> <?php _e('Grant this user super admin privileges for the Network.'); ?> </label></p> <?php } else { ?> <p><?php _e('Super admin privileges cannot be removed because this user has the network admin email.'); ?> </p>
/** * Set up the user contact methods. * * Default contact methods were removed in 3.6. A filter dictates contact methods. * * @since 3.7.0 * * @param WP_User $user Optional. WP_User object. * @return array Array of contact methods and their labels. */ function wp_get_user_contact_methods($user = null) { $methods = array(); if (get_network_option('initial_db_version') < 23588) { $methods = array('aim' => __('AIM'), 'yim' => __('Yahoo IM'), 'jabber' => __('Jabber / Google Talk')); } /** * Filter the user contact methods. * * @since 2.9.0 * * @param array $methods Array of contact methods and their labels. * @param WP_User $user WP_User object. */ return apply_filters('user_contactmethods', $methods, $user); }
} } $blog_id = $current_blog->blog_id; $public = $current_blog->public; if (empty($current_blog->site_id)) { // This dates to [MU134] and shouldn't be relevant anymore, // but it could be possible for arguments passed to insert_blog() etc. $current_blog->site_id = 1; } $site_id = $current_blog->site_id; wp_load_core_site_options($site_id); } $wpdb->set_prefix($table_prefix, false); // $table_prefix can be set in sunrise.php $wpdb->set_blog_id($current_blog->blog_id, $current_blog->site_id); $table_prefix = $wpdb->get_blog_prefix(); $_wp_switched_stack = array(); $switched = false; // need to init cache again after blog_id is set wp_start_object_cache(); if (!$current_site instanceof WP_Network) { $current_site = new WP_Network($current_site); } if (empty($current_site->site_name)) { $current_site->site_name = get_network_option('site_name'); if (!$current_site->site_name) { $current_site->site_name = ucfirst($current_site->domain); } } // Define upload directory constants ms_upload_constants();
/** * Metabox used to publish the network * * @since 1.7.0 * * @param WP_Network $network */ function wpmn_edit_network_publish_metabox($network = null) { // Network ID $network_id = empty($network) ? 0 : $network->id; // Button text $button_text = empty($network) ? esc_html__('Create', 'wp-multi-network') : esc_html__('Update', 'wp-multi-network'); // Button action $action = empty($network) ? 'create' : 'update'; // Cancel URL $cancel_url = add_query_arg(array('page' => 'networks'), network_admin_url('admin.php')); ?> <div class="submitbox"> <div id="minor-publishing"> <div id="misc-publishing-actions"> <?php if (!empty($network)) { ?> <div class="misc-pub-section misc-pub-section-first" id="network"> <span><?php printf(__('Name: <strong>%1$s</strong>', 'wp-multi-network'), get_network_option($network->id, 'site_name')); ?> </span> </div> <div class="misc-pub-section misc-pub-section-last" id="sites"> <span><?php printf(__('Sites: <strong>%1$s</strong>', 'wp-multi-network'), get_network_option($network->id, 'blog_count')); ?> </span> </div> <?php } else { ?> <div class="misc-pub-section misc-pub-section-first" id="sites"> <span><?php esc_html_e('Creating a network with 1 new site.', 'wp-multi-network'); ?> </span> </div> <?php } ?> </div> <div class="clear"></div> </div> <div id="major-publishing-actions"> <a class="button" href="<?php echo esc_url($cancel_url); ?> "><?php esc_html_e('Cancel', 'wp-multi-network'); ?> </a> <div id="publishing-action"> <?php wp_nonce_field('edit_network', 'network_edit'); submit_button($button_text, 'primary', 'submit', false); ?> <input type="hidden" name="action" value="<?php echo esc_attr($action); ?> "> <input type="hidden" name="network_id" value="<?php echo esc_attr($network_id); ?> "> </div> <div class="clear"></div> </div> </div> <?php }
/** * Set the site name assigned to the network if one has not been populated. * * @since 4.4.0 * @access private */ private function _set_site_name() { if (!empty($this->site_name)) { return; } $default = ucfirst($this->domain); $this->site_name = get_network_option($this->id, 'site_name', $default); }
/** * * @global int $upgrading * @return false|void */ function maintenance_nag() { include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version global $upgrading; $nag = isset($upgrading); if (!$nag) { $failed = get_network_option('auto_core_update_failed'); /* * If an update failed critically, we may have copied over version.php but not other files. * In that case, if the install claims we're running the version we attempted, nag. * This is serious enough to err on the side of nagging. * * If we simply failed to update before we tried to copy any files, then assume things are * OK if they are now running the latest. * * This flag is cleared whenever a successful update occurs using Core_Upgrader. */ $comparison = !empty($failed['critical']) ? '>=' : '>'; if (version_compare($failed['attempted'], $wp_version, $comparison)) { $nag = true; } } if (!$nag) { return false; } if (current_user_can('update_core')) { $msg = sprintf(__('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php'); } else { $msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.'); } echo "<div class='update-nag'>{$msg}</div>"; }
/** * Prepares and sends an email of a full log of background update results, useful for debugging and geekery. * * @since 3.7.0 * @access protected */ protected function send_debug_email() { $update_count = 0; foreach ($this->update_results as $type => $updates) { $update_count += count($updates); } $body = array(); $failures = 0; $body[] = sprintf(__('WordPress site: %s'), network_home_url('/')); // Core if (isset($this->update_results['core'])) { $result = $this->update_results['core'][0]; if ($result->result && !is_wp_error($result->result)) { $body[] = sprintf(__('SUCCESS: WordPress was successfully updated to %s'), $result->name); } else { $body[] = sprintf(__('FAILED: WordPress failed to update to %s'), $result->name); $failures++; } $body[] = ''; } // Plugins, Themes, Translations foreach (array('plugin', 'theme', 'translation') as $type) { /** * Filter to control whether a notification email is sent to the site admin email address for * plugin, theme, and translation updates. * * By default, this only has an effect when automatic background updates are enabled and a * development version of WordPress is in use. * * @since 4.4.0 * * @param bool $notify Whether the site administrator is notified. * @param string $type The type of update. One of 'plugin', 'theme', or 'translation'. * @param WP_Automatic_Updater $this The WP_Automatic_Updater instance. */ if (!apply_filters('send_update_notification_email', true, $type, $this)) { continue; } if (!isset($this->update_results[$type])) { continue; } $success_items = wp_list_filter($this->update_results[$type], array('result' => true)); if ($success_items) { $messages = array('plugin' => __('The following plugins were successfully updated:'), 'theme' => __('The following themes were successfully updated:'), 'translation' => __('The following translations were successfully updated:')); $body[] = $messages[$type]; foreach (wp_list_pluck($success_items, 'name') as $name) { $body[] = ' * ' . sprintf(__('SUCCESS: %s'), $name); } } if ($success_items != $this->update_results[$type]) { // Failed updates $messages = array('plugin' => __('The following plugins failed to update:'), 'theme' => __('The following themes failed to update:'), 'translation' => __('The following translations failed to update:')); $body[] = $messages[$type]; foreach ($this->update_results[$type] as $item) { if (!$item->result || is_wp_error($item->result)) { $body[] = ' * ' . sprintf(__('FAILED: %s'), $item->name); $failures++; } } } $body[] = ''; } if (empty($body)) { return; } $site_title = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($failures) { $body[] = trim(__("BETA TESTING?\n=============\n\nThis debugging email is sent when you are using a development version of WordPress.\n\nIf you think these failures might be due to a bug in WordPress, could you report it?\n * Open a thread in the support forums: https://wordpress.org/support/forum/alphabeta\n * Or, if you're comfortable writing a bug report: https://core.trac.wordpress.org/\n\nThanks! -- The WordPress Team")); $body[] = ''; $subject = sprintf(__('[%s] There were failures during background updates'), $site_title); } else { $subject = sprintf(__('[%s] Background updates have finished'), $site_title); } $body[] = trim(__('UPDATE LOG ==========')); $body[] = ''; foreach (array('core', 'plugin', 'theme', 'translation') as $type) { if (!isset($this->update_results[$type])) { continue; } foreach ($this->update_results[$type] as $update) { $body[] = $update->name; $body[] = str_repeat('-', strlen($update->name)); foreach ($update->messages as $message) { $body[] = " " . html_entity_decode(str_replace('…', '...', $message)); } if (is_wp_error($update->result)) { $results = array('update' => $update->result); // If we rolled back, we want to know an error that occurred then too. if ('rollback_was_required' === $update->result->get_error_code()) { $results = (array) $update->result->get_error_data(); } foreach ($results as $result_type => $result) { if (!is_wp_error($result)) { continue; } if ('rollback' === $result_type) { /* translators: 1: Error code, 2: Error message. */ $body[] = ' ' . sprintf(__('Rollback Error: [%1$s] %2$s'), $result->get_error_code(), $result->get_error_message()); } else { /* translators: 1: Error code, 2: Error message. */ $body[] = ' ' . sprintf(__('Error: [%1$s] %2$s'), $result->get_error_code(), $result->get_error_message()); } if ($result->get_error_data()) { $body[] = ' ' . implode(', ', (array) $result->get_error_data()); } } } $body[] = ''; } } $email = array('to' => get_network_option('admin_email'), 'subject' => $subject, 'body' => implode("\n", $body), 'headers' => ''); /** * Filter the debug email that can be sent following an automatic * background core update. * * @since 3.8.0 * * @param array $email { * Array of email arguments that will be passed to wp_mail(). * * @type string $to The email recipient. An array of emails * can be returned, as handled by wp_mail(). * @type string $subject Email subject. * @type string $body Email message body. * @type string $headers Any email headers. Default empty. * } * @param int $failures The number of failures encountered while upgrading. * @param mixed $results The results of all attempted updates. */ $email = apply_filters('automatic_updates_debug_email', $email, $failures, $this->update_results); wp_mail($email['to'], wp_specialchars_decode($email['subject']), $email['body'], $email['headers']); }
/** * Constructor. * * @since 160524 Initial release. * * @param array $instance_base Instance base. * @param array $instance Instance args. * @param Classes\App|null $Parent Parent app (optional). */ public function __construct(array $instance_base = [], array $instance = [], Classes\App $Parent = null) { # WordPress common properties. $this->Wp = $Parent ? $Parent->Wp : new Wp(); # Define a few reflection-based properties. $this->Reflection = new \ReflectionClass($this); $this->class = $this->Reflection->getName(); $this->namespace = $this->Reflection->getNamespaceName(); $this->file = $this->Reflection->getFileName(); $this->base_dir = dirname($this->file, 4); $this->base_dir_basename = basename($this->base_dir); $this->is_core = $this->class === self::class; # Establish specs & brand for parent constructor. $default_specs = ['§is_pro' => null, '§has_pro' => null, '§in_wp' => null, '§is_network_wide' => false, '§type' => '', '§file' => '']; $brand_defaults = ['©acronym' => '', '©name' => '', '©slug' => '', '©var' => '', '©short_slug' => '', '©short_var' => '', '§product_name' => '', '§product_slug' => '', '©text_domain' => '', '§domain' => '', '§domain_path' => '', '§domain_pro_path' => '', '§domain_short_var' => '', '§api_domain' => '', '§api_domain_path' => '', '§api_domain_short_var' => '', '§cdn_domain' => '', '§cdn_domain_path' => '', '§cdn_domain_short_var' => '', '§stats_domain' => '', '§stats_domain_path' => '', '§stats_domain_short_var' => '']; if ($this->is_core) { $Parent = null; // Core. $specs = array_merge($default_specs, ['§is_pro' => false, '§has_pro' => false, '§in_wp' => false, '§is_network_wide' => false, '§type' => 'plugin', '§file' => $this->base_dir . '/plugin.php'], $instance_base['§specs'] ?? [], $instance['§specs'] ?? []); $specs['§is_network_wide'] = $specs['§is_network_wide'] && $this->Wp->is_multisite; $brand = array_merge($brand_defaults, ['©acronym' => 'WPS Core', '©name' => 'WP Sharks Core', '©slug' => 'wp-sharks-core', '©var' => 'wp_sharks_core', '©short_slug' => 'wps-core', '©short_var' => 'wps_core', '§product_name' => 'WP Sharks Core', '§product_slug' => 'wp-sharks-core', '©text_domain' => 'wp-sharks-core', '§domain' => 'wpsharks.com', '§domain_path' => '/product/wp-sharks-core', '§domain_pro_path' => '', '§domain_short_var' => 'wps', '§api_domain' => 'api.wpsharks.com', '§api_domain_path' => '/', '§api_domain_short_var' => 'wps', '§cdn_domain' => 'cdn.wpsharks.com', '§cdn_domain_path' => '/', '§cdn_domain_short_var' => 'wps', '§stats_domain' => 'stats.wpsharks.io', '§stats_domain_path' => '/', '§stats_domain_short_var' => 'wps'], $instance_base['©brand'] ?? [], $instance['©brand'] ?? []); } else { if (!isset($GLOBALS[self::class])) { throw new Exception('Missing core instance.'); } $Parent = $Parent ?? $GLOBALS[self::class]; $specs = array_merge($default_specs, $instance_base['§specs'] ?? [], $instance['§specs'] ?? []); $specs['§is_pro'] = $specs['§is_pro'] ?? mb_stripos($this->namespace, '\\Pro\\') !== false; $specs['§has_pro'] = $specs['§is_pro'] ?: true; // Assume this is true. $specs['§in_wp'] = $specs['§is_pro'] ? false : $specs['§in_wp'] ?? false; $specs['§is_network_wide'] = $specs['§is_network_wide'] && $this->Wp->is_multisite; if (!$specs['§type'] || !$specs['§file']) { if (is_file($this->base_dir . '/plugin.php')) { $specs['§type'] = 'plugin'; $specs['§file'] = $this->base_dir . '/plugin.php'; } elseif (is_file($this->base_dir . '/style.css')) { $specs['§type'] = 'theme'; $specs['§file'] = $this->base_dir . '/style.css'; } elseif (is_file($this->base_dir . '/src/wp-content/mu-plugins/site.php')) { $specs['§type'] = 'mu-plugin'; $specs['§file'] = $this->base_dir . '/src/wp-content/mu-plugins/site.php'; } else { // Hard failure in this unexpected case. throw new Exception('Unable to determine `§type`/`§file`.'); } // The app will need to give its §type/§file explicitly. } $brand = array_merge($brand_defaults, $instance_base['©brand'] ?? [], $instance['©brand'] ?? []); if (!$brand['©slug']) { // This is the basis for others. $brand['©slug'] = $Parent->c::nameToSlug($this->base_dir_basename); $brand['©slug'] = preg_replace('/[_\\-]+(?:lite|pro)/ui', '', $brand['©slug']); } $brand['©var'] = $brand['©var'] ?: $Parent->c::slugToVar($brand['©slug']); $brand['©name'] = $brand['©name'] ?: $Parent->c::slugToName($brand['©slug']); $brand['©acronym'] = $brand['©acronym'] ?: $Parent->c::nameToAcronym($brand['©name']); $brand['©short_slug'] = $brand['©short_slug'] ?: (strlen($brand['©slug']) <= 10 ? $brand['©slug'] : 's' . substr(md5($brand['©slug']), 0, 9)); $brand['©short_var'] = $brand['©short_var'] ?: $Parent->c::slugToVar($brand['©short_slug']); $brand['§product_name'] = $brand['§product_name'] ?: $brand['©name'] . ($specs['§is_pro'] ? ' Pro' : ''); $brand['§product_slug'] = $brand['§product_slug'] ?: $this->base_dir_basename; $brand['©text_domain'] = $brand['©text_domain'] ?: $brand['©slug']; if (!$brand['§domain'] || !$brand['§domain_path'] || !$brand['§domain_short_var']) { $brand['§domain'] = $Parent->Config->©brand['§domain']; $brand['§domain_path'] = '/product/' . $brand['§product_slug']; $brand['§domain_pro_path'] = $specs['§is_pro'] ? $brand['§domain_path'] : ($specs['§has_pro'] ? '/product/' . $brand['§product_slug'] . '-pro' : ''); $brand['§domain_short_var'] = $Parent->Config->©brand['§domain_short_var']; } if ($this->Wp->debug) { if (preg_match('/(?:LITE|PRO)$/ui', $brand['©acronym'])) { throw new Exception('Please remove `LITE|PRO` suffix from `©acronym`.'); } elseif (preg_match('/\\s+(?:Lite|Pro)$/ui', $brand['©name'])) { throw new Exception('Please remove `Lite|Pro` suffix from `©name`.'); // } elseif (!$Parent->c::isSlug($brand['©slug'])) { throw new Exception('Please fix; `©slug` has invalid chars.'); } elseif (preg_match('/[_\\-]+(?:lite|pro)$/ui', $brand['©slug'])) { throw new Exception('Please remove `lite|pro` suffix from `©slug`.'); // } elseif (!$Parent->c::isVar($brand['©var'])) { throw new Exception('Please fix; `©var` has invalid chars.'); } elseif (preg_match('/[_\\-]+(?:lite|pro)$/ui', $brand['©var'])) { throw new Exception('Please remove `lite|pro` suffix from `©var`.'); // } elseif (strlen($brand['©short_slug']) > 10) { throw new Exception('Please fix; `©short_slug` is > 10 bytes.'); } elseif (!$Parent->c::isSlug($brand['©short_slug'])) { throw new Exception('Please fix; `©short_slug` has invalid chars.'); } elseif (preg_match('/[_\\-]+(?:lite|pro)$/ui', $brand['©short_slug'])) { throw new Exception('Please remove `lite|pro` suffix from `©short_slug`.'); // } elseif (strlen($brand['©short_var']) > 10) { throw new Exception('Please fix; `©short_var` is > 10 bytes.'); } elseif (!$Parent->c::isVar($brand['©short_var'])) { throw new Exception('Please fix; `©short_var` has invalid chars.'); } elseif (preg_match('/[_\\-]+(?:lite|pro)$/ui', $brand['©short_var'])) { throw new Exception('Please remove `lite|pro` suffix from `©short_var`.'); // } elseif (!$Parent->c::isSlug($brand['©text_domain'])) { throw new Exception('Please fix; `©text_domain` has invalid chars.'); // } elseif (!$Parent->c::isSlug($brand['§product_slug'])) { throw new Exception('Please fix; `§product_slug` has invalid chars.'); } } } # Collect additional WordPress config values. if (!($wp_app_salt_key = hash('sha256', $this->Wp->salt . $brand['©slug']))) { throw new Exception('Failed to generate a unique salt/key.'); } if ($specs['§type'] === 'plugin') { if (!($wp_app_url_parts = parse_url(plugin_dir_url($specs['§file'])))) { throw new Exception('Failed to parse plugin dir URL parts.'); } } elseif ($specs['§type'] === 'theme') { if (!($wp_app_url_parts = $this->Wp->template_directory_url_parts)) { throw new Exception('Failed to parse theme dir URL parts.'); } } elseif ($specs['§type'] === 'mu-plugin') { if (!($wp_app_url_parts = $this->Wp->site_url_parts)) { throw new Exception('Failed to parse app URL parts.'); } } else { // Unexpected application `§type` in this case. throw new Exception('Failed to parse URL for unexpected `§type`.'); } $wp_app_url_base_path = rtrim($wp_app_url_parts['path'] ?? '', '/'); $wp_app_url_base_path .= in_array($specs['§type'], ['theme', 'plugin'], true) ? '/src' : ''; $wp_app_url_base_path .= '/'; // Always; i.e., this is a directory location. # Build the core/default instance base. $default_instance_base = ['©use_server_cfgs' => false, '©debug' => ['©enable' => $this->Wp->debug, '©edge' => $this->Wp->debug_edge, '©log' => $this->Wp->debug_log, '©log_callback' => false, '©er_enable' => false, '©er_display' => false, '©er_assertions' => false], '©handle_throwables' => false, '©di' => ['©default_rule' => ['new_instances' => [Classes\SCore\Base\Widget::class, Classes\SCore\MenuPageForm::class, Classes\SCore\PostMetaBoxForm::class, Classes\SCore\WidgetForm::class]]], '©sub_namespace_map' => ['SCore' => ['©utils' => '§', '©facades' => 's']], '§specs' => $default_specs, '©brand' => $brand_defaults, '©urls' => ['©hosts' => ['©app' => $this->Wp->site_url_host, '©cdn' => 'cdn.' . $this->Wp->site_url_root_host, '©roots' => ['©app' => $this->Wp->site_url_root_host, '©cdn' => $this->Wp->site_url_root_host]], '©base_paths' => ['©app' => $wp_app_url_base_path, '©cdn' => '/'], '©cdn_filter_enable' => false, '©default_scheme' => $this->Wp->site_default_scheme, '©sig_key' => $wp_app_salt_key], '§setup' => ['§hook' => 'after_setup_theme', '§hook_priority' => 0, '§enable_hooks' => true, '§complete' => false], '©fs_paths' => ['©logs_dir' => $this->Wp->tmp_dir . '/.' . $this::CORE_CONTAINER_SLUG . '/' . $brand['©slug'] . '/logs', '©cache_dir' => $this->Wp->tmp_dir . '/.' . $this::CORE_CONTAINER_SLUG . '/' . $brand['©slug'] . '/cache', '§templates_theme_base_dir' => $this::CORE_CONTAINER_SLUG . '/' . $brand['©slug'], '©templates_dir' => $this->base_dir . '/src/includes/templates', '©routes_dir' => '', '©errors_dir' => '', '§mysql' => ['§tables_dir' => $this->base_dir . '/src/includes/mysql/tables', '§indexes_dir' => $this->base_dir . '/src/includes/mysql/indexes', '§triggers_dir' => $this->base_dir . '/src/includes/mysql/triggers']], '©encryption' => ['©key' => $wp_app_salt_key], '©cookies' => ['©encryption_key' => $wp_app_salt_key], '©hash_ids' => ['©hash_key' => $wp_app_salt_key], '©passwords' => ['©hash_key' => $wp_app_salt_key], '§conflicts' => ['§plugins' => [], '§themes' => [], '§deactivatable_plugins' => []], '§dependencies' => ['§plugins' => [], '§themes' => [], '§others' => []], '§caps' => ['§manage' => $specs['§is_network_wide'] && $this->Wp->is_multisite ? 'manage_network_plugins' : 'activate_plugins'], '§pro_option_keys' => [], '§default_options' => ['§for_version' => $this::VERSION, '§for_product_slug' => $brand['§product_slug'], '§license_key' => ''], '§options' => [], '§force_install' => false, '§uninstall' => false]; # Automatically add lite/pro conflict to the array. if ($specs['§type'] === 'plugin') { // Only for plugins. Only one theme can be active at a time. $_lp_conflicting_name = $brand['©name'] . ($specs['§is_pro'] ? ' Lite' : ' Pro'); $_lp_conflicting_slug = $brand['©slug'] . ($specs['§is_pro'] ? '' : '-pro'); $default_instance_base['§conflicts']['§plugins'][$_lp_conflicting_slug] = $_lp_conflicting_name; $default_instance_base['§conflicts']['§deactivatable_plugins'][$_lp_conflicting_slug] = $_lp_conflicting_name; } # Merge `$default_instance_base` w/ `$instance_base` param. $instance_base = $this->mergeConfig($default_instance_base, $instance_base); $instance_base['§specs'] =& $specs; // Already established (in full) above. $instance_base['©brand'] =& $brand; // Already established (in full) above. # Give plugins/extensions a chance to filter `$instance`. $instance = apply_filters($brand['©var'] . '_instance', $instance, $instance_base); unset($instance['§specs'], $instance['©brand']); // Already established (in full) above. # Call parent app-constructor (i.e., websharks/core). parent::__construct($instance_base, $instance, $Parent); /* Post-construct sub-routines are run now -------------------------------------------------------------- */ # Merge site owner options (highest precedence). if ($this->Config->§specs['§is_network_wide'] && $this->Wp->is_multisite) { if (!is_array($site_owner_options = get_network_option(null, $this->Config->©brand['©var'] . '_options'))) { update_network_option(null, $this->Config->©brand['©var'] . '_options', $site_owner_options = []); } } elseif (!is_array($site_owner_options = get_option($this->Config->©brand['©var'] . '_options'))) { update_option($this->Config->©brand['©var'] . '_options', $site_owner_options = []); } $this->Config->§options = $this->s::mergeOptions($this->Config->§default_options, $this->Config->§options); $this->Config->§options = $this->s::mergeOptions($this->Config->§options, $site_owner_options); $this->Config->§options = $this->s::applyFilters('options', $this->Config->§options); # Handle option transitions from one variation of the software to another; e.g., pro upgrade. if ($this->Config->§options['§for_product_slug'] !== $this->Config->©brand['§product_slug']) { $this->Config->§options['§for_product_slug'] = $this->Config->©brand['§product_slug']; $this->Config->§options['§license_key'] = ''; // No longer applicable. if ($this->Config->§specs['§is_network_wide'] && $this->Wp->is_multisite) { update_network_option(null, $this->Config->©brand['©var'] . '_options', $this->Config->§options); } else { update_option($this->Config->©brand['©var'] . '_options', $this->Config->§options); } $this->Config->§force_install = !$this->Config->§uninstall; // Force reinstall (if not uninstalling). } # Sanity check; must be on (or after) `plugins_loaded` hook. # If uninstalling, must be on (or after) `init` hook. if (!did_action('plugins_loaded')) { throw new Exception('`plugins_loaded` action not done yet.'); } elseif ($this->Config->§uninstall && !did_action('init')) { throw new Exception('`init` action not done yet.'); } # Check for any known conflicts. if ($this->s::conflictsExist()) { return; // Stop here. } # Check for any unsatisfied dependencies. if ($this->s::dependenciesUnsatisfied()) { return; // Stop here. } # Add app instance to collection. if ($this->Parent && $this->Parent->is_core && !$this->Config->§uninstall) { // NOTE: If uninstalling, don't expose it to the parent/core. $this->Parent->s::addApp($this); } # Remaining routines are driven by setup hook. if ($this->Config->§uninstall || did_action($this->Config->§setup['§hook'])) { $this->onSetup(); // Run setup immediately. } else { // Delay setup routines; i.e., attach to hook. add_action($this->Config->§setup['§hook'], [$this, 'onSetup'], $this->Config->§setup['§hook_priority']); } }
/** * Update the value of a network option that was already added. * * @since 4.4.0 * * @see update_option() * * @global wpdb $wpdb * * @param int $network_id ID of the network. Can be null to default to the current network ID. * @param string $option Name of option. Expected to not be SQL-escaped. * @param mixed $value Option value. Expected to not be SQL-escaped. * @return bool False if value was not updated and true if value was updated. */ function update_network_option($network_id, $option, $value) { global $wpdb; if ($network_id && !is_numeric($network_id)) { return false; } $network_id = (int) $network_id; // Fallback to the current network if a network ID is not specified. if (!$network_id) { $network_id = get_current_network_id(); } wp_protect_special_option($option); $old_value = get_network_option($network_id, $option, false); /** * Filters a specific network option before its value is updated. * * The dynamic portion of the hook name, `$option`, refers to the option name. * * @since 2.9.0 As 'pre_update_site_option_' . $key * @since 3.0.0 * @since 4.4.0 The `$option` parameter was added. * @since 4.7.0 The `$network_id` parameter was added. * * @param mixed $value New value of the network option. * @param mixed $old_value Old value of the network option. * @param string $option Option name. * @param int $network_id ID of the network. */ $value = apply_filters("pre_update_site_option_{$option}", $value, $old_value, $option, $network_id); if ($value === $old_value) { return false; } if (false === $old_value) { return add_network_option($network_id, $option, $value); } $notoptions_key = "{$network_id}:notoptions"; $notoptions = wp_cache_get($notoptions_key, 'site-options'); if (is_array($notoptions) && isset($notoptions[$option])) { unset($notoptions[$option]); wp_cache_set($notoptions_key, $notoptions, 'site-options'); } if (!is_multisite()) { $result = update_option($option, $value, 'no'); } else { $value = sanitize_option($option, $value); $serialized_value = maybe_serialize($value); $result = $wpdb->update($wpdb->sitemeta, array('meta_value' => $serialized_value), array('site_id' => $network_id, 'meta_key' => $option)); if ($result) { $cache_key = "{$network_id}:{$option}"; wp_cache_set($cache_key, $value, 'site-options'); } } if ($result) { /** * Fires after the value of a specific network option has been successfully updated. * * The dynamic portion of the hook name, `$option`, refers to the option name. * * @since 2.9.0 As "update_site_option_{$key}" * @since 3.0.0 * @since 4.7.0 The `$network_id` parameter was added. * * @param string $option Name of the network option. * @param mixed $value Current value of the network option. * @param mixed $old_value Old value of the network option. * @param int $network_id ID of the network. */ do_action("update_site_option_{$option}", $option, $value, $old_value, $network_id); /** * Fires after the value of a network option has been successfully updated. * * @since 3.0.0 * @since 4.7.0 The `$network_id` parameter was added. * * @param string $option Name of the network option. * @param mixed $value Current value of the network option. * @param mixed $old_value Old value of the network option. * @param int $network_id ID of the network. */ do_action('update_site_option', $option, $value, $old_value, $network_id); return true; } return false; }
/** * Determine whether global terms are enabled. * * @since 3.0.0 * * @staticvar bool $global_terms * * @return bool True if multisite and global terms enabled. */ function global_terms_enabled() { if (!is_multisite()) { return false; } static $global_terms = null; if (is_null($global_terms)) { /** * Filter whether global terms are enabled. * * Passing a non-null value to the filter will effectively short-circuit the function, * returning the value of the 'global_terms_enabled' site option instead. * * @since 3.0.0 * * @param null $enabled Whether global terms are enabled. */ $filter = apply_filters('global_terms_enabled', null); if (!is_null($filter)) { $global_terms = (bool) $filter; } else { $global_terms = (bool) get_network_option('global_terms_enabled', false); } } return $global_terms; }
/** * Install an empty blog. * * Creates the new blog tables and options. If calling this function * directly, be sure to use switch_to_blog() first, so that $wpdb * points to the new blog. * * @since MU * * @global wpdb $wpdb * @global WP_Roles $wp_roles * * @param int $blog_id The value returned by insert_blog(). * @param string $blog_title The title of the new site. */ function install_blog($blog_id, $blog_title = '') { global $wpdb, $wp_roles, $current_site; // Cast for security $blog_id = (int) $blog_id; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $suppress = $wpdb->suppress_errors(); if ($wpdb->get_results("DESCRIBE {$wpdb->posts}")) { die('<h1>' . __('Already Installed') . '</h1><p>' . __('You appear to have already installed WordPress. To reinstall please clear your old database tables first.') . '</p></body></html>'); } $wpdb->suppress_errors($suppress); $url = get_blogaddress_by_id($blog_id); // Set everything up make_db_current_silent('blog'); populate_options(); populate_roles(); // populate_roles() clears previous role definitions so we start over. $wp_roles = new WP_Roles(); $siteurl = $home = untrailingslashit($url); if (!is_subdomain_install()) { if ('https' === parse_url(get_network_option('siteurl'), PHP_URL_SCHEME)) { $siteurl = set_url_scheme($siteurl, 'https'); } if ('https' === parse_url(get_home_url($current_site->blog_id), PHP_URL_SCHEME)) { $home = set_url_scheme($home, 'https'); } } update_option('siteurl', $siteurl); update_option('home', $home); if (get_site_option('ms_files_rewriting')) { update_option('upload_path', UPLOADBLOGSDIR . "/{$blog_id}/files"); } else { update_option('upload_path', get_blog_option(get_current_site()->blog_id, 'upload_path')); } update_option('blogname', wp_unslash($blog_title)); update_option('admin_email', ''); // remove all perms $table_prefix = $wpdb->get_blog_prefix(); delete_metadata('user', 0, $table_prefix . 'user_level', null, true); // delete all delete_metadata('user', 0, $table_prefix . 'capabilities', null, true); // delete all }
/** * Network-active plugins. * * @since 160524 First documented version. * * @param bool $slugify Slugs w/ basename keys? * * @internal If false you'll get numerically indexed basenames. * * @return array Network-active plugin basenames. */ public function networkActive(bool $slugify = true) : array { $cache_key = '_' . (int) $slugify; // Network wide. if (isset(static::$cache[__FUNCTION__][$cache_key])) { return static::$cache[__FUNCTION__][$cache_key]; } if (!$this->Wp->is_multisite) { // Not applicable. return static::$cache[__FUNCTION__][$cache_key] = []; } $network_active = get_network_option(null, 'active_sitewide_plugins'); $network_active = is_array($network_active) ? $network_active : []; $network_active = array_keys($network_active); if ($slugify) { // Slugs w/ basename keys. $network_active = $this->s::pluginSlugs($network_active); } return static::$cache[__FUNCTION__][$cache_key] = $network_active; }
/** * Display file upload quota on dashboard. * * Runs on the activity_box_end hook in wp_dashboard_right_now(). * * @since 3.0.0 * * @return bool|null True if not multisite, user can't upload files, or the space check option is disabled. */ function wp_dashboard_quota() { if (!is_multisite() || !current_user_can('upload_files') || get_network_option('upload_space_check_disabled')) { return true; } $quota = get_space_allowed(); $used = get_space_used(); if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $used_class = $percentused >= 70 ? ' warning' : ''; $used = round($used, 2); $percentused = number_format($percentused); ?> <h4 class="mu-storage"><?php _e('Storage Space'); ?> </h4> <div class="mu-storage"> <ul> <li class="storage-count"> <?php $text = sprintf(__('%s MB Space Allowed'), number_format_i18n($quota)); printf('<a href="%1$s" title="%2$s">%3$s</a>', esc_url(admin_url('upload.php')), __('Manage Uploads'), $text); ?> </li><li class="storage-count <?php echo $used_class; ?> "> <?php $text = sprintf(__('%1$s MB (%2$s%%) Space Used'), number_format_i18n($used, 2), $percentused); printf('<a href="%1$s" title="%2$s" class="musublink">%3$s</a>', esc_url(admin_url('upload.php')), __('Manage Uploads'), $text); ?> </li> </ul> </div> <?php }
delete_option('adminhash'); delete_option('new_admin_email'); wp_redirect(admin_url('options-general.php?updated=true')); exit; } } if (is_multisite() && !is_super_admin() && 'update' != $action) { wp_die('<h1>' . __('Cheatin’ uh?') . '</h1>' . '<p>' . __('You are not allowed to delete these items.') . '</p>', 403); } $whitelist_options = array('general' => array('blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG'), 'discussion' => array('default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration'), 'media' => array('thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type'), 'reading' => array('posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public'), 'writing' => array('default_category', 'default_email_category', 'default_link_category', 'default_post_format')); $whitelist_options['misc'] = $whitelist_options['options'] = $whitelist_options['privacy'] = array(); $mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass'); if (!in_array(get_option('blog_charset'), array('utf8', 'utf-8', 'UTF8', 'UTF-8'))) { $whitelist_options['reading'][] = 'blog_charset'; } if (get_network_option('initial_db_version') < 32453) { $whitelist_options['writing'][] = 'use_smilies'; $whitelist_options['writing'][] = 'use_balanceTags'; } if (!is_multisite()) { if (!defined('WP_SITEURL')) { $whitelist_options['general'][] = 'siteurl'; } if (!defined('WP_HOME')) { $whitelist_options['general'][] = 'home'; } $whitelist_options['general'][] = 'admin_email'; $whitelist_options['general'][] = 'users_can_register'; $whitelist_options['general'][] = 'default_role'; $whitelist_options['writing'] = array_merge($whitelist_options['writing'], $mail_options); $whitelist_options['writing'][] = 'ping_sites';