get_blog_prefix example


function get_author_user_ids() {
    _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' );

    global $wpdb;
    if ( !is_multisite() )
        $level_key = $wpdb->get_blog_prefix() . 'user_level';
    else
        $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // WPMU site admins don't have user_levels.
    return $wpdb->get_col( $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value != '0'", $level_key) );
}

/** * Gets author users who can edit posts. * * @deprecated 3.1.0 Use get_users() * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $user_id User ID. * @return array|false List of editable authors. False if no editable users. */

    protected function _init_caps( $cap_key = '' ) {
        global $wpdb;

        _deprecated_function( __METHOD__, '4.9.0', 'WP_User::for_site()' );

        if ( empty( $cap_key ) ) {
            $this->cap_key = $wpdb->get_blog_prefix( $this->site_id ) . 'capabilities';
        } else {
            $this->cap_key = $cap_key;
        }

        $this->caps = $this->get_caps_data();

        $this->get_role_caps();
    }

    /** * Retrieves all of the capabilities of the user's roles, and merges them with * individual user capabilities. * * All of the capabilities of the user's roles are merged with the user's individual * capabilities. This means that the user can be denied specific capabilities that * their role might have, but the user is specifically denied. * * @since 2.0.0 * * @return bool[] Array of key/value pairs where keys represent a capability name * and boolean values represent whether the user has that capability. */
// This dates to [MU134] and shouldn't be relevant anymore,         // but it could be possible for arguments passed to insert_blog() etc.         $current_blog->site_id = 1;
    }

    $site_id = $current_blog->site_id;
    wp_load_core_site_options( $site_id );
}

$wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php. $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
$table_prefix       = $wpdb->get_blog_prefix();
$_wp_switched_stack = array();
$switched           = false;

// Need to init cache again after blog_id is set. wp_start_object_cache();

if ( ! $current_site instanceof WP_Network ) {
    $current_site = new WP_Network( $current_site );
}

if ( ! $current_blog instanceof WP_Site ) {
    
if ( $qv['has_published_posts'] && $blog_id ) {
            if ( true === $qv['has_published_posts'] ) {
                $post_types = get_post_types( array( 'public' => true ) );
            } else {
                $post_types = (array) $qv['has_published_posts'];
            }

            foreach ( $post_types as &$post_type ) {
                $post_type = $wpdb->prepare( '%s', $post_type );
            }

            $posts_table        = $wpdb->get_blog_prefix( $blog_id ) . 'posts';
            $this->query_where .= " AND $wpdb->users.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( " . implode( ', ', $post_types ) . ' ) )';
        }

        // nicename         if ( '' !== $qv['nicename'] ) {
            $this->query_where .= $wpdb->prepare( ' AND user_nicename = %s', $qv['nicename'] );
        }

        if ( ! empty( $qv['nicename__in'] ) ) {
            $sanitized_nicename__in = array_map( 'esc_sql', $qv['nicename__in'] );
            $nicename__in           = implode( "','", $sanitized_nicename__in );
            

function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) {
    _deprecated_function( __FUNCTION__, '3.0.0', 'wp_get_sites()' );

    global $wpdb;
    $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", get_current_network_id() ), ARRAY_A );

    $blog_list = array();
    foreach ( (array) $blogs as $details ) {
        $blog_list[ $details['blog_id'] ] = $details;
        $blog_list[ $details['blog_id'] ]['postcount'] = $wpdb->get_var( "SELECT COUNT(ID) FROM " . $wpdb->get_blog_prefix( $details['blog_id'] ). "posts WHERE post_status='publish' AND post_type='post'" );
    }

    if ( ! $blog_list ) {
        return array();
    }

    if ( 'all' === $num ) {
        return array_slice( $blog_list$startcount( $blog_list ) );
    } else {
        return array_slice( $blog_list$start$num );
    }
}

    public function for_site( $site_id = null ) {
        global $wpdb;

        if ( ! empty( $site_id ) ) {
            $this->site_id = absint( $site_id );
        } else {
            $this->site_id = get_current_blog_id();
        }

        $this->role_key = $wpdb->get_blog_prefix( $this->site_id ) . 'user_roles';

        if ( ! empty( $this->roles ) && ! $this->use_db ) {
            return;
        }

        $this->roles = $this->get_roles_data();

        $this->init_roles();
    }

    /** * Gets the ID of the site for which roles are currently initialized. * * @since 4.9.0 * * @return int Site ID. */

    $minimum_site_name_length = apply_filters( 'minimum_site_name_length', 4 );

    if ( strlen( $blogname ) < $minimum_site_name_length ) {
        /* translators: %s: Minimum site name length. */
        $errors->add( 'blogname', sprintf( _n( 'Site name must be at least %s character.', 'Site name must be at least %s characters.', $minimum_site_name_length )number_format_i18n( $minimum_site_name_length ) ) );
    }

    // Do not allow users to create a site that conflicts with a page on the main blog.     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 ) ) ) {
        $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) );
    }

    // All numeric?     if ( preg_match( '/^[0-9]*$/', $blogname ) ) {
        $errors->add( 'blogname', __( 'Sorry, site names must have letters too!' ) );
    }

    /** * Filters the new site name during registration. * * The name is the site's subdomain or the site's subdirectory * path depending on the network settings. * * @since MU (3.0.0) * * @param string $blogname Site name. */
'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );',
                'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );',
                sprintf(
                    'wp.apiFetch.nonceEndpoint = "%s";',
                    admin_url( 'admin-ajax.php?action=rest-nonce' )
                ),
            )
        ),
        'after'
    );

    $meta_key     = $wpdb->get_blog_prefix() . 'persisted_preferences';
    $user_id      = get_current_user_id();
    $preload_data = get_user_meta( $user_id$meta_key, true );
    $scripts->add_inline_script(
        'wp-preferences',
        sprintf(
            '( function() { var serverData = %s; var userId = "%d"; var persistenceLayer = wp.preferencesPersistence.__unstableCreatePersistenceLayer( serverData, userId ); var preferencesStore = wp.preferences.store; wp.data.dispatch( preferencesStore ).setPersistenceLayer( persistenceLayer ); } ) ();',


    if ( empty( $user ) ) {
        $user = get_current_user_id();
    }

    $user = get_userdata( $user );
    if ( ! $user ) {
        return false;
    }

    $prefix = $wpdb->get_blog_prefix();
    if ( $user->has_prop( $prefix . $option ) ) { // Blog-specific.         $result = $user->get( $prefix . $option );
    } elseif ( $user->has_prop( $option ) ) { // User-specific and cross-blog.         $result = $user->get( $option );
    } else {
        $result = false;
    }

    /** * Filters a specific user option value. * * The dynamic portion of the hook name, `$option`, refers to the user option name. * * @since 2.5.0 * * @param mixed $result Value for the user's option. * @param string $option Name of the option being retrieved. * @param WP_User $user WP_User object of the user whose option is being retrieved. */
// Clean blog cache after populating options.     clean_blog_cache( $site );

    // Populate the site's roles.     populate_roles();
    $wp_roles = new WP_Roles();

    // Populate metadata for the site.     populate_site_meta( $site->id, $args['meta'] );

    // Remove all permissions that may exist for the site.     $table_prefix = $wpdb->get_blog_prefix();
    delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true );   // Delete all.     delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // Delete all.
    // Install default site content.     wp_install_defaults( $args['user_id'] );

    // Set the site administrator.     add_user_to_blog( $site->id, $args['user_id'], 'administrator' );
    if ( ! user_can( $args['user_id'], 'manage_network' ) && ! get_user_meta( $args['user_id'], 'primary_blog', true ) ) {
        update_user_meta( $args['user_id'], 'primary_blog', $site->id );
    }

    
$this->base_prefix = $prefix;

        if ( $set_table_names ) {
            foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) {
                $this->$table = $prefixed_table;
            }

            if ( is_multisite() && empty( $this->blogid ) ) {
                return $old_prefix;
            }

            $this->prefix = $this->get_blog_prefix();

            foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) {
                $this->$table = $prefixed_table;
            }

            foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) {
                $this->$table = $prefixed_table;
            }
        }
        return $old_prefix;
    }

    

        do_action( 'switch_blog', $new_blog_id$prev_blog_id, 'switch' );

        $GLOBALS['switched'] = true;

        return true;
    }

    $wpdb->set_blog_id( $new_blog_id );
    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    $GLOBALS['blog_id']      = $new_blog_id;

    if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
        wp_cache_switch_to_blog( $new_blog_id );
    } else {
        global $wp_object_cache;

        if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) {
            $global_groups = $wp_object_cache->global_groups;
        } else {
            $global_groups = false;
        }
if ( ! empty( $messages ) ) {
    foreach ( $messages as $msg ) {
        echo '<div id="message" class="notice notice-success is-dismissible"><p>' . $msg . '</p></div>';
    }
}
?> <form method="post" action="site-settings.php?action=update-site"> <?php wp_nonce_field( 'edit-site' ); ?> <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" /> <table class="form-table" role="presentation"> <?php         $blog_prefix = $wpdb->get_blog_prefix( $id );
        $sql         = "SELECT * FROM {$blog_prefix}options WHERE option_name NOT LIKE %s AND option_name NOT LIKE %s";
        $query       = $wpdb->prepare(
            $sql,
            $wpdb->esc_like( '_' ) . '%',
            '%' . $wpdb->esc_like( 'user_roles' )
        );
        $options     = $wpdb->get_results( $query );

        foreach ( $options as $option ) {
            

function get_users_of_blog( $id = '' ) {
    _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' );

    global $wpdb;
    if ( empty( $id ) ) {
        $id = get_current_blog_id();
    }
    $blog_prefix = $wpdb->get_blog_prefix($id);
    $users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" );
    return $users;
}

/** * Enable/disable automatic general feed link outputting. * * @since 2.8.0 * @deprecated 3.0.0 Use add_theme_support() * @see add_theme_support() * * @param bool $add Optional. Add or remove links. Default true. */
Home | Imprint | This part of the site doesn't use cookies.