WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/19/2016 04:46:14 AM (3 years ago)
Author:
jeremyfelt
Message:

Multisite: Use get_network() and get_current_network_id() for current network data.

get_network() falls back to the current network when called without any arguments. Between this and get_current_network_id(), we can replace almost all instances of the global $current_site and all instances of get_current_site().

This effectively deprecates get_current_site(), something that we'll do in a future ticket.

Props flixos90.
Fixes #37414.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-functions.php

    r38655 r38814  
    547547    global $wpdb, $domain;
    548548
    549     $current_site = get_current_site();
    550     $base = $current_site->path;
     549    $current_network = get_network();
     550    $base = $current_network->path;
    551551
    552552    $blog_title = strip_tags( $blog_title );
     
    581581
    582582    // do not allow users to create a blog that conflicts with a page on the main blog.
    583     if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) )
     583    if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_network->site_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) )
    584584        $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) );
    585585
     
    613613        $path = $base.$blogname.'/';
    614614    }
    615     if ( domain_exists($mydomain, $path, $current_site->id) )
     615    if ( domain_exists($mydomain, $path, $current_network->id) )
    616616        $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) );
    617617
     
    790790
    791791    // Send email with activation link.
    792     if ( !is_subdomain_install() || get_current_site()->id != 1 )
     792    if ( !is_subdomain_install() || get_current_network_id() != 1 )
    793793        $activate_url = network_site_url("wp-activate.php?key=$key");
    794794    else
     
    13351335 */
    13361336function install_blog( $blog_id, $blog_title = '' ) {
    1337     global $wpdb, $wp_roles, $current_site;
     1337    global $wpdb, $wp_roles;
    13381338
    13391339    // Cast for security
     
    13641364            $siteurl = set_url_scheme( $siteurl, 'https' );
    13651365        }
    1366         if ( 'https' === parse_url( get_home_url( $current_site->blog_id ), PHP_URL_SCHEME ) ) {
     1366        if ( 'https' === parse_url( get_home_url( get_network()->site_id ), PHP_URL_SCHEME ) ) {
    13671367            $home = set_url_scheme( $home, 'https' );
    13681368        }
     
    13761376        update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" );
    13771377    else
    1378         update_option( 'upload_path', get_blog_option( get_current_site()->blog_id, 'upload_path' ) );
     1378        update_option( 'upload_path', get_blog_option( get_network()->site_id, 'upload_path' ) );
    13791379
    13801380    update_option( 'blogname', wp_unslash( $blog_title ) );
     
    14311431 */
    14321432function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) {
    1433     $current_site = get_current_site();
     1433    $current_network = get_network();
    14341434
    14351435    /**
     
    14711471    $user = get_userdata( $user_id );
    14721472
    1473     $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
     1473    $welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email );
    14741474    $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email );
    14751475    $welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email );
     
    15011501    $message = $welcome_email;
    15021502
    1503     if ( empty( $current_site->site_name ) )
    1504         $current_site->site_name = 'WordPress';
     1503    if ( empty( $current_network->site_name ) )
     1504        $current_network->site_name = 'WordPress';
    15051505
    15061506    /**
     
    15111511     * @param string $subject Subject of the email.
    15121512     */
    1513     $subject = apply_filters( 'update_welcome_subject', sprintf( __( 'New %1$s Site: %2$s' ), $current_site->site_name, wp_unslash( $title ) ) );
     1513    $subject = apply_filters( 'update_welcome_subject', sprintf( __( 'New %1$s Site: %2$s' ), $current_network->site_name, wp_unslash( $title ) ) );
    15141514    wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
    15151515    return true;
     
    15321532 */
    15331533function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) {
    1534     $current_site = get_current_site();
     1534    $current_network = get_network();
    15351535
    15361536    /**
     
    15651565     */
    15661566    $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta );
    1567     $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
     1567    $welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email );
    15681568    $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
    15691569    $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
     
    15791579    $message = $welcome_email;
    15801580
    1581     if ( empty( $current_site->site_name ) )
    1582         $current_site->site_name = 'WordPress';
     1581    if ( empty( $current_network->site_name ) )
     1582        $current_network->site_name = 'WordPress';
    15831583
    15841584    /**
     
    15891589     * @param string $subject Subject of the email.
    15901590     */
    1591     $subject = apply_filters( 'update_welcome_user_subject', sprintf( __( 'New %1$s User: %2$s' ), $current_site->site_name, $user->user_login) );
     1591    $subject = apply_filters( 'update_welcome_user_subject', sprintf( __( 'New %1$s User: %2$s' ), $current_network->site_name, $user->user_login) );
    15921592    wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
    15931593    return true;
     
    18781878 */
    18791879function redirect_this_site( $deprecated = '' ) {
    1880     return array( get_current_site()->domain );
     1880    return array( get_network()->domain );
    18811881}
    18821882
     
    20252025        $blog_id = $meta[ 'add_to_blog' ];
    20262026        $role = $meta[ 'new_role' ];
    2027         remove_user_from_blog($user_id, get_current_site()->blog_id); // remove user from main blog.
     2027        remove_user_from_blog($user_id, get_network()->site_id); // remove user from main blog.
    20282028        add_user_to_blog( $blog_id, $user_id, $role );
    20292029        update_user_meta( $user_id, 'primary_blog', $blog_id );
     
    20392039 */
    20402040function fix_phpmailer_messageid( $phpmailer ) {
    2041     $phpmailer->Hostname = get_current_site()->domain;
     2041    $phpmailer->Hostname = get_network()->domain;
    20422042}
    20432043
Note: See TracChangeset for help on using the changeset viewer.