function global_home_url($path = '', $scheme = null) { if (!is_multinetwork()) { return network_home_url($path, $scheme); } $main_site_id = get_main_network_id(); $main_site = get_network($main_site_id); $orig_scheme = $scheme; if (!in_array($scheme, array('http', 'https', 'relative'))) { $scheme = is_ssl() && !is_admin() ? 'https' : 'http'; } if ('relative' == $scheme) { $url = $main_site->path; } else { $url = set_url_scheme('http://' . $main_site->domain . $main_site->path, $scheme); } if ($path && is_string($path)) { $url .= ltrim($path, '/'); } /** * Filters the global home URL. * * @since 1.0.0 * * @param string $url The complete global home URL including scheme and path. * @param string $path Path relative to the global home URL. Blank string * if no path is specified. * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https', * 'relative' or null. */ return apply_filters('global_home_url', $url, $path, $orig_scheme); }
/** * Determine whether a network is the main network of the Multisite install. * * @since 3.7.0 * * @param int $network_id Optional. Network ID to test. Defaults to current network. * @return bool True if $network_id is the main network, or if not running Multisite. */ function is_main_network($network_id = null) { if (!is_multisite()) { return true; } $current_network_id = (int) get_current_site()->id; if (null === $network_id) { $network_id = $current_network_id; } $network_id = (int) $network_id; return $network_id === get_main_network_id(); }
/** * Get the main network * * Uses the same logic as {@see is_main_network}, but returns the network object * instead. * * @return stdClass|null */ function wp_get_main_network() { global $wpdb; if (!is_multisite()) { return null; } // Added in 4.3.0 if (function_exists('get_main_network_id')) { $primary_network_id = get_main_network_id(); // 4.2.0 } else { // Override if (defined('PRIMARY_NETWORK_ID')) { return wp_get_network((int) PRIMARY_NETWORK_ID); } // Check cache $primary_network_id = (int) wp_cache_get('primary_network_id', 'site-options'); if (!empty($primary_network_id)) { return wp_get_network($primary_network_id); } $primary_network_id = (int) $wpdb->get_var("SELECT id FROM {$wpdb->site} ORDER BY id LIMIT 1"); wp_cache_add('primary_network_id', $primary_network_id, 'site-options'); } return wp_get_network($primary_network_id); }
/** * Retrieves the current network ID. * * @since 4.6.0 * * @return int The ID of the current network. */ function get_current_network_id() { if (!is_multisite()) { return 1; } $current_network = get_network(); if (!isset($current_network->id)) { return get_main_network_id(); } return absint($current_network->id); }
} die('WordPress Core directory could not be detected.'); } define('WP_GLOBAL_ADMIN', true); /** Load WordPress Administration Bootstrap */ require_once _ga_detect_abspath() . '/wp-admin/admin.php'; // This would be it if it was part of Core. //require_once( dirname( dirname( __FILE__ ) ) . '/admin.php' ); if (!is_multisite()) { wp_die(__('Multisite support is not enabled.')); } if (!is_multinetwork()) { wp_die(__('Multinetwork support is not enabled.', 'global-admin')); } $current_network = get_network(); $main_network_id = get_main_network_id(); $main_network = get_network($main_network_id); $redirect_global_admin_request = 0 !== strcasecmp($current_network->domain, $main_network->domain) || 0 !== strcasecmp($current_network->path, $main_network->path); /** * Filters whether to redirect the request to the Global Admin. * * @since 1.0.0 * * @param bool $redirect_global_admin_request Whether the request should be redirected. */ $redirect_global_admin_request = apply_filters('redirect_global_admin_request', $redirect_global_admin_request); if ($redirect_global_admin_request) { wp_redirect(global_admin_url()); exit; } unset($current_network);
/** * Get the main network * * Uses the same logic as {@see is_main_network}, but returns the network object * instead. * * @return stdClass|null */ function wp_get_main_network() { // Bail if not multisite if (!is_multisite()) { return null; } // Return main network ID return wp_get_network(get_main_network_id()); }
function test_get_main_network_id_filtered() { add_filter('get_main_network_id', array($this, '_get_main_network_id')); $this->assertEquals(3, get_main_network_id()); remove_filter('get_main_network_id', array($this, '_get_main_network_id')); }
/** * Output the delete multiple networks page * * @since 2.0.0 */ private function page_delete_networks() { // Get posted networks $network_id = get_main_network_id(); $all_networks = isset($_POST['all_networks']) ? array_map('absint', $_POST['all_networks']) : array(); // Prevent primary network from being deleted $all_networks = array_diff($all_networks, array($network_id)); // Query for networks $networks = get_networks(array('network__in' => $all_networks)); // Bail if no networks if (empty($networks)) { wp_die(esc_html__('You have selected an invalid network or networks for deletion', 'wp-multi-network')); } // Ensure each network is valid foreach ($networks as $network) { if (!get_network($network)) { wp_die(esc_html__('You have selected an invalid network for deletion.', 'wp-multi-network')); } } // Query for sites in selected networks $sites = get_sites(array('network__in' => $all_networks)); ?> <div class="wrap"> <h1><?php esc_html_e('Networks', 'wp-multi-network'); ?> </h1> <h3><?php esc_html_e('Delete Multiple Networks', 'wp-multi-network'); ?> </h3> <form method="post" action="<?php echo esc_url($this->admin_url()); ?> "> <?php if (!empty($sites)) { ?> <div class="error inline"> <h3><?php esc_html_e('You have selected the following networks for deletion', 'wp-multi-network'); ?> :</h3> <ul> <?php foreach ($networks as $deleted_network) { ?> <li><input type="hidden" name="deleted_networks[]" value="<?php echo esc_attr($deleted_network->id); ?> "><?php echo esc_html($deleted_network->domain . $deleted_network->path); ?> </li> <?php } ?> </ul> <p><?php // Messaging wp_should_rescue_orphaned_sites() ? esc_html_e('One or more of these networks has existing sites. Deleting these networks will orphan these sites.', 'wp-multi-network') : esc_html_e('One or more of these networks has existing sites. Deleting these networks will permanently delete these sites.', 'wp-multi-network'); ?> </p> <p> <label for="override"><?php esc_html_e('Please confirm that you still want to delete these networks', 'wp-multi-network'); ?> :</label> <input type="checkbox" name="override" id="override"> </p> </div> <?php } else { ?> <div id="message inline"> <h3><?php esc_html_e('You have selected the following networks for deletion', 'wp-multi-network'); ?> :</h3> <ul><?php foreach ($networks as $deleted_network) { ?> <li><input type="hidden" name="deleted_networks[]" value="<?php echo esc_attr($deleted_network->id); ?> "><?php echo esc_html($deleted_network->domain . $deleted_network->path); ?> </li><?php } ?> </ul> </div> <?php } ?> <p><?php esc_html_e('Are you sure you want to delete these networks?', 'wp-multi-network'); ?> </p> <?php wp_nonce_field('edit_network', 'network_edit'); submit_button(esc_html__('Delete Networks', 'wp-multi-network'), 'primary', 'delete_multiple', false); ?> <a class="button" href="<?php echo esc_url($this->admin_url()); ?> "><?php esc_html_e('Cancel', 'wp-multi-network'); ?> </a> </form> </div> <?php }
function global_step2() { $main_network_id = get_main_network_id(); $main_network = get_network($main_network_id); $hostname = $main_network->domain; $abspath_fix = str_replace('\\', '/', ABSPATH); $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); if ($_POST || !is_multinetwork()) { ?> <h3><?php esc_html_e('Enabling the Multinetwork'); ?> </h3> <p><?php _e('Complete the following steps to enable the global admin panel for creating multiple networks.'); ?> </p> <div class="updated inline"><p> <?php printf(__('We recommend you back up your existing %s file.', 'global-admin'), '<code>wp-config.php</code>'); ?> </p></div> <?php } else { ?> <p><?php _e('The original configuration steps are shown here for reference.', 'global-admin'); ?> </p> <?php } ?> <ol> <li> <p><?php printf(__('Add the following to your %1$s file in %2$s <strong>above</strong> the line reading %3$s:', 'global-admin'), '<code>wp-config.php</code>', '<code>' . $location_of_wp_config . '</code>', '<code>/* ' . __('That’s all, stop editing! Happy blogging.', 'global-admin') . ' */</code>'); ?> </p> <textarea class="code" readonly="readonly" cols="100" rows="2"> define('MULTINETWORK', true); </textarea> </li> </ol> <?php if (!is_multinetwork()) { ?> <p><?php _e('Once you complete these steps, your multinetwork is enabled and configured.', 'global-admin'); ?> </p> <?php } }