Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
wp-includes
/
blocks
/
classic
:
ms-blogs-20250306092619.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php /** * Site/blog functions that work with the blogs table and related data. * * @package WordPress * @subpackage Multisite * @since MU (3.0.0) */ require_once ABSPATH . WPINC . '/ms-site.php'; require_once ABSPATH . WPINC . '/ms-network.php'; /** * Updates the last_updated field for the current site. * * @since MU (3.0.0) */ function wpmu_update_blogs_date() { $site_id = get_current_blog_id(); update_blog_details( $site_id, array( 'last_updated' => current_time( 'mysql', true ) ) ); /** * Fires after the blog details are updated. * * @since MU (3.0.0) * * @param int $blog_id Site ID. */ do_action( 'wpmu_blog_updated', $site_id ); } /** * Gets a full site URL, given a site ID. * * @since MU (3.0.0) * * @param int $blog_id Site ID. * @return string Full site URL if found. Empty string if not. */ function get_blogaddress_by_id( $blog_id ) { $bloginfo = get_site( (int) $blog_id ); if ( empty( $bloginfo ) ) { return ''; } $scheme = parse_url( $bloginfo->home, PHP_URL_SCHEME ); $scheme = empty( $scheme ) ? 'http' : $scheme; return esc_url( $scheme . '://' . $bloginfo->domain . $bloginfo->path ); } /** * Gets a full site URL, given a site name. * * @since MU (3.0.0) * * @param string $blogname Name of the subdomain or directory. * @return string */ function get_blogaddress_by_name( $blogname ) { if ( is_subdomain_install() ) { if ( 'main' === $blogname ) { $blogname = 'www'; } $url = rtrim( network_home_url(), '/' ); if ( ! empty( $blogname ) ) { $url = preg_replace( '|^([^\.]+://)|', '${1}' . $blogname . '.', $url ); } } else { $url = network_home_url( $blogname ); } return esc_url( $url . '/' ); } /** * Retrieves a site's ID given its (subdomain or directory) slug. * * @since MU (3.0.0) * @since 4.7.0 Converted to use `get_sites()`. * * @param string $slug A site's slug. * @return int|null The site ID, or null if no site is found for the given slug. */ function get_id_from_blogname( $slug ) { $current_network = get_network(); $slug = trim( $slug, '/' ); if ( is_subdomain_install() ) { $domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain ); $path = $current_network->path; } else { $domain = $current_network->domain; $path = $current_network->path . $slug . '/'; } $site_ids = get_sites( array( 'number' => 1, 'fields' => 'ids', 'domain' => $domain, 'path' => $path, 'update_site_meta_cache' => false, ) ); if ( empty( $site_ids ) ) { return null; } return array_shift( $site_ids ); } /** * Retrieves the details for a blog from the blogs table and blog options. * * @since MU (3.0.0) * * @global wpdb $wpdb WordPress database abstraction object. * * @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against. * Defaults to the current blog ID. * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. * Default is true. * @return WP_Site|false Blog details on success. False on failure. */ function get_blog_details( $fields = null, $get_all = true ) { global $wpdb; if ( is_array( $fields ) ) { if ( isset( $fields['blog_id'] ) ) { $blog_id = $fields['blog_id']; } elseif ( isset( $fields['domain'] ) && isset( $fields['path'] ) ) { $key = md5( $fields['domain'] . $fields['path'] ); $blog = wp_cache_get( $key, 'blog-lookup' ); if ( false !== $blog ) { return $blog; } if ( str_starts_with( $fields['domain'], 'www.' ) ) { $nowww = substr( $fields['domain'], 4 ); $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) ); } else { $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) ); } if ( $blog ) { wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' ); $blog_id = $blog->blog_id; } else { return false; } } elseif ( isset( $fields['domain'] ) && is_subdomain_install() ) { $key = md5( $fields['domain'] ); $blog = wp_cache_get( $key, 'blog-lookup' ); if ( false !== $blog ) { return $blog; } if ( str_starts_with( $fields['domain'], 'www.' ) ) { $nowww = substr( $fields['domain'], 4 ); $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) ); } else { $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) ); } if ( $blog ) { wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' ); $blog_id = $blog->blog_id; } else { return false; } } else { return false; } } else { if ( ! $fields ) { $blog_id = get_current_blog_id(); } elseif ( ! is_numeric( $fields ) ) { $blog_id = get_id_from_blogname( $fields ); } else { $blog_id = $fields; } } $blog_id = (int) $blog_id; $all = $get_all ? '' : 'short'; $details = wp_cache_get( $blog_id . $all, 'blog-details' ); if ( $details ) { if ( ! is_object( $details ) ) { if ( -1 == $details ) { return false; } else { // Clear old pre-serialized objects. Cache clients do better with that. wp_cache_delete( $blog_id . $all, 'blog-details' ); unset( $details ); } } else { return $details; } } // Try the other cache. if ( $get_all ) { $details = wp_cache_get( $blog_id . 'short', 'blog-details' ); } else { $details = wp_cache_get( $blog_id, 'blog-details' ); // If short was requested and full cache is set, we can return. if ( $details ) { if ( ! is_object( $details ) ) { if ( -1 == $details ) { return false; } else { // Clear old pre-serialized objects. Cache clients do better with that. wp_cache_delete( $blog_id, 'blog-details' ); unset( $details ); } } else { return $details; } } } if ( empty( $details ) ) { $details = WP_Site::get_instance( $blog_id ); if ( ! $details ) { // Set the full cache. wp_cache_set( $blog_id, -1, 'blog-details' ); return false; } } if ( ! $details instanceof WP_Site ) { $details = new WP_Site( $details ); } if ( ! $get_all ) { wp_cache_set( $blog_id . $all, $details, 'blog-details' ); return $details; } $switched_blog = false; if ( get_current_blog_id() !== $blog_id ) { switch_to_blog( $blog_id ); $switched_blog = true; } $details->blogname = get_option( 'blogname' ); $details->siteurl = get_option( 'siteurl' ); $details->post_count = get_option( 'post_count' ); $details->home = get_option( 'home' ); if ( $switched_blog ) { restore_current_blog(); } /** * Filters a blog's details. * * @since MU (3.0.0) * @deprecated 4.7.0 Use {@see 'site_details'} instead. * * @param WP_Site $details The blog details. */ $details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' ); wp_cache_set( $blog_id . $all, $details, 'blog-details' ); $key = md5( $details->domain . $details->path ); wp_cache_set( $key, $details, 'blog-lookup' ); return $details; } /** * Clears the blog details cache. * * @since MU (3.0.0) * * @param int $blog_id Optional. Blog ID. Defaults to current blog. */ function refresh_blog_details( $blog_id = 0 ) { $blog_id = (int) $blog_id; if ( ! $blog_id ) { $blog_id = get_current_blog_id(); } clean_blog_cache( $blog_id ); } /** * Updates the details for a blog and the blogs table for a given blog ID. * * @since MU (3.0.0) * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $blog_id Blog ID. * @param array $details Array of details keyed by blogs table field names. * @return bool True if update succeeds, false otherwise. */ function update_blog_details( $blog_id, $details = array() ) { global $