WordPressを読む 10-18 /blog/wp-includes/functions.php 18
2014/11/29
目次
/blog/wp-includes/functions.php 18
読込元 : /blog/wp-settings.php
読込元 : /blog/wp-load.php
関数
wp_guess_url()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /** * Guess the URL for the site. * * Will remove wp-admin links to retrieve only return URLs not in the wp-admin * directory. * * @since 2.6.0 * * @return string The guessed URL. */ function wp_guess_url() { if ( defined('WP_SITEURL') && '' != WP_SITEURL ) { $url = WP_SITEURL; } else { $abspath_fix = str_replace( '\\', '/', ABSPATH ); $script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] ); // The request is for the admin if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) { $path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] ); // The request is for a file in ABSPATH } elseif ( $script_filename_dir . '/' == $abspath_fix ) { // Strip off any file/query params in the path $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] ); } else { if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) { // Request is hitting a file inside ABSPATH $directory = str_replace( ABSPATH, '', $script_filename_dir ); // Strip off the sub directory, and any file/query paramss $path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ); } elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) { // Request is hitting a file above ABSPATH $subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) ); // Strip off any file/query params from the path, appending the sub directory to the install $path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory; } else { $path = $_SERVER['REQUEST_URI']; } } $schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet $url = $schema . $_SERVER['HTTP_HOST'] . $path; } return rtrim($url, '/'); } |
関数
wp_suspend_cache_addition()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /** * Temporarily suspend cache additions. * * Stops more data being added to the cache, but still allows cache retrieval. * This is useful for actions, such as imports, when a lot of data would otherwise * be almost uselessly added to the cache. * * Suspension lasts for a single page load at most. Remember to call this * function again if you wish to re-enable cache adds earlier. * * @since 3.3.0 * * @param bool $suspend Optional. Suspends additions if true, re-enables them if false. * @return bool The current suspend setting */ function wp_suspend_cache_addition( $suspend = null ) { static $_suspend = false; if ( is_bool( $suspend ) ) $_suspend = $suspend; return $_suspend; } |
関数
wp_suspend_cache_invalidation()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Suspend cache invalidation. * * Turns cache invalidation on and off. Useful during imports where you don't wont to do * invalidations every time a post is inserted. Callers must be sure that what they are * doing won't lead to an inconsistent cache when invalidation is suspended. * * @since 2.7.0 * * @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true. * @return bool The current suspend setting. */ function wp_suspend_cache_invalidation( $suspend = true ) { global $_wp_suspend_cache_invalidation; $current_suspend = $_wp_suspend_cache_invalidation; $_wp_suspend_cache_invalidation = $suspend; return $current_suspend; } |
関数
is_main_site()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /** * Determine whether a site is the main site of the current network. * * @since 3.0.0 * * @param int $site_id Optional. Site ID to test. Defaults to current site. * Defaults to current site. * @return bool True if $site_id is the main site of the network, or if not * running Multisite. */ function is_main_site( $site_id = null ) { // This is the current network's information; 'site' is old terminology. global $current_site; if ( ! is_multisite() ) return true; if ( ! $site_id ) $site_id = get_current_blog_id(); return (int) $site_id === (int) $current_site->blog_id; } |
関数
is_main_network()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /** * 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 ) { global $wpdb; if ( ! is_multisite() ) return true; $current_network_id = (int) get_current_site()->id; if ( ! $network_id ) $network_id = $current_network_id; $network_id = (int) $network_id; if ( defined( 'PRIMARY_NETWORK_ID' ) ) return $network_id === (int) PRIMARY_NETWORK_ID; if ( 1 === $current_network_id ) return $network_id === $current_network_id; $primary_network_id = (int) wp_cache_get( 'primary_network_id', 'site-options' ); if ( $primary_network_id ) return $network_id === $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 $network_id === $primary_network_id; } |