Changeset 32775 for trunk/src/wp-includes/functions.php
- Timestamp:
- 06/14/2015 09:44:45 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r32650 r32775 3874 3874 * @since 3.7.0 3875 3875 * 3876 * @global wpdb $wpdb3877 *3878 3876 * @param int $network_id Optional. Network ID to test. Defaults to current network. 3879 3877 * @return bool True if $network_id is the main network, or if not running Multisite. 3880 3878 */ 3881 3879 function is_main_network( $network_id = null ) { 3880 if ( ! is_multisite() ) { 3881 return true; 3882 } 3883 3884 $current_network_id = (int) get_current_site()->id; 3885 3886 if ( null === $network_id ) { 3887 $network_id = $current_network_id; 3888 } 3889 3890 $network_id = (int) $network_id; 3891 3892 return ( $network_id === get_main_network_id() ); 3893 } 3894 3895 /** 3896 * Get the main network ID. 3897 * 3898 * @since 4.3.0 3899 * 3900 * @global wpdb $wpdb 3901 * 3902 * @return int The ID of the main network. 3903 */ 3904 function get_main_network_id() { 3882 3905 global $wpdb; 3883 3906 3884 if ( ! is_multisite() ) 3885 return true; 3886 3887 $current_network_id = (int) get_current_site()->id; 3888 3889 if ( ! $network_id ) 3890 $network_id = $current_network_id; 3891 $network_id = (int) $network_id; 3892 3893 if ( defined( 'PRIMARY_NETWORK_ID' ) ) 3894 return $network_id === (int) PRIMARY_NETWORK_ID; 3895 3896 if ( 1 === $current_network_id ) 3897 return $network_id === $current_network_id; 3898 3899 $primary_network_id = (int) wp_cache_get( 'primary_network_id', 'site-options' ); 3900 3901 if ( $primary_network_id ) 3902 return $network_id === $primary_network_id; 3903 3904 $primary_network_id = (int) $wpdb->get_var( "SELECT id FROM $wpdb->site ORDER BY id LIMIT 1" ); 3905 wp_cache_add( 'primary_network_id', $primary_network_id, 'site-options' ); 3906 3907 return $network_id === $primary_network_id; 3907 if ( ! is_multisite() ) { 3908 return 1; 3909 } 3910 3911 if ( defined( 'PRIMARY_NETWORK_ID' ) ) { 3912 $main_network_id = PRIMARY_NETWORK_ID; 3913 } elseif ( 1 === (int) get_current_site()->id ) { 3914 // If the current network has an ID of 1, assume it is the main network. 3915 $main_network_id = 1; 3916 } else { 3917 $main_network_id = wp_cache_get( 'primary_network_id', 'site-options' ); 3918 3919 if ( false === $main_network_id ) { 3920 $main_network_id = (int) $wpdb->get_var( "SELECT id FROM {$wpdb->site} ORDER BY id LIMIT 1" ); 3921 wp_cache_add( 'primary_network_id', $main_network_id, 'site-options' ); 3922 } 3923 } 3924 3925 /** 3926 * Filter the main network ID. 3927 * 3928 * @since 4.3.0 3929 * 3930 * @param int $main_network_id The ID of the main network. 3931 */ 3932 return (int) apply_filters( 'get_main_network_id', $main_network_id ); 3908 3933 } 3909 3934
Note:
See TracChangeset
for help on using the changeset viewer.