restore_current_blog example

<h2><?php _e( 'Your account is now active!' ); ?></h2> <div id="signup-welcome"> <p><span class="h3"><?php _e( 'Username:' ); ?></span> <?php echo $user->user_login; ?></p> <p><span class="h3"><?php _e( 'Password:' ); ?></span> <?php echo $result['password']; ?></p> </div> <?php             if ( $url && network_home_url( '', 'http' ) !== $url ) :
                switch_to_blog( (int) $result['blog_id'] );
                $login_url = wp_login_url();
                restore_current_blog();
                ?> <p class="view"> <?php                     /* translators: 1: Site URL, 2: Login URL. */
                    printf( __( 'Your account is now activated. <a href="%1$s">View your site</a> or <a href="%2$s">Log in</a>' )$urlesc_url( $login_url ) );
                ?> </p> <?php else : ?> <p class="view"> <?php                     printf(
                        


        // Build $allcaps from role caps, overlay user's $caps.         $this->allcaps = array();
        foreach ( (array) $this->roles as $role ) {
            $the_role      = $wp_roles->get_role( $role );
            $this->allcaps = array_merge( (array) $this->allcaps, (array) $the_role->capabilities );
        }
        $this->allcaps = array_merge( (array) $this->allcaps, (array) $this->caps );

        if ( $switch_site ) {
            restore_current_blog();
        }

        return $this->allcaps;
    }

    /** * Adds role to user. * * Updates the user's meta data option with capabilities and roles. * * @since 2.0.0 * * @param string $role Role name. */

        );
        if ( empty( $site_ids ) ) {
            echo '<p>' . __( 'All done!' ) . '</p>';
            break;
        }
        echo '<ul>';
        foreach ( (array) $site_ids as $site_id ) {
            switch_to_blog( $site_id );
            $siteurl     = site_url();
            $upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' );
            restore_current_blog();

            echo "<li>$siteurl</li>";

            $response = wp_remote_get(
                $upgrade_url,
                array(
                    'timeout'     => 120,
                    'httpversion' => '1.1',
                    'sslverify'   => false,
                )
            );

            
remove_user_from_blog( $user_id$blog_id );
            }
        }

        update_blog_status( $blog_id, 'deleted', 1 );

        /** This action is documented in wp-includes/ms-blogs.php */
        do_action_deprecated( 'deleted_blog', array( $blog_id, false ), '5.1.0' );
    }

    if ( $switch ) {
        restore_current_blog();
    }
}

/** * Deletes a user and all of their posts from the network. * * This function: * * - Deletes all posts (of all post types) authored by the user on all sites on the network * - Deletes all links owned by the user on all sites on the network * - Removes the user from all sites on the network * - Deletes the user from the database * * @since 3.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $id The user ID. * @return bool True if the user was deleted, false otherwise. */

function confirm_another_blog_signup( $domain$path$blog_title$user_name$user_email = '', $meta = array()$blog_id = 0 ) {

    if ( $blog_id ) {
        switch_to_blog( $blog_id );
        $home_url  = home_url( '/' );
        $login_url = wp_login_url();
        restore_current_blog();
    } else {
        $home_url  = 'http://' . $domain . $path;
        $login_url = 'http://' . $domain . $path . 'wp-login.php';
    }

    $site = sprintf(
        '<a href="%1$s">%2$s</a>',
        esc_url( $home_url ),
        $blog_title
    );

    
/** * Fires after the site options are updated. * * @since 3.0.0 * @since 4.4.0 Added `$id` parameter. * * @param int $id The ID of the site being updated. */
    do_action( 'wpmu_update_blog_options', $id );

    restore_current_blog();
    wp_redirect(
        add_query_arg(
            array(
                'update' => 'updated',
                'id'     => $id,
            ),
            'site-settings.php'
        )
    );
    exit;
}



        if ( $args['has_published_posts'] || in_array( 'post_count', $ordersby, true ) ) {
            $switch = $blog_id && get_current_blog_id() !== $blog_id;
            if ( $switch ) {
                switch_to_blog( $blog_id );
            }

            $last_changed .= wp_cache_get_last_changed( 'posts' );

            if ( $switch ) {
                restore_current_blog();
            }
        }

        return "get_users:$key:$last_changed";
    }

    /** * Parses an 'order' query variable and casts it to ASC or DESC as necessary. * * @since 4.2.0 * * @param string $order The 'order' query variable. * @return string The sanitized 'order' query variable. */
/* * Need to back up wpdb table names, and create a new wp_blogs entry for new blog. * Need to get blog_id from wp_blogs, and create new table names. * Must restore table names at the end of function. */

    if ( ! $blog_id = insert_blog($domain$path$site_id) )
        return __( '<strong>Error:</strong> There was a problem creating site entry.' );

    switch_to_blog($blog_id);
    install_blog($blog_id);
    restore_current_blog();

    return $blog_id;
}

/** * Get the admin for a domain/path combination. * * @since MU (3.0.0) * @deprecated 4.4.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $domain Optional. Network domain. * @param string $path Optional. Network path. * @return array|false The network admins. */
<?php         if ( 'list' !== $mode ) {
            switch_to_blog( $blog['blog_id'] );
            echo '<p>';
            printf(
                /* translators: 1: Site title, 2: Site tagline. */
                __( '%1$s &#8211; %2$s' ),
                get_option( 'blogname' ),
                '<em>' . get_option( 'blogdescription' ) . '</em>'
            );
            echo '</p>';
            restore_current_blog();
        }
    }

    /** * Handles the lastupdated column output. * * @since 4.3.0 * * @global string $mode List table view mode. * * @param array $blog Current site. */

function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
    $orig_scheme = $scheme;

    if ( empty( $blog_id ) || ! is_multisite() ) {
        $url = get_option( 'home' );
    } else {
        switch_to_blog( $blog_id );
        $url = get_option( 'home' );
        restore_current_blog();
    }

    if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
        if ( is_ssl() ) {
            $scheme = 'https';
        } else {
            $scheme = parse_url( $url, PHP_URL_SCHEME );
        }
    }

    $url = set_url_scheme( $url$scheme );

    
if ( null !== $pre ) {
        return $pre;
    }

    $blog_prefix = $wpdb->get_blog_prefix( $site_id );
    $result      = array();

    if ( 'time' === $strategy ) {
        if ( is_multisite() && get_current_blog_id() != $site_id ) {
            switch_to_blog( $site_id );
            $avail_roles = wp_roles()->get_names();
            restore_current_blog();
        } else {
            $avail_roles = wp_roles()->get_names();
        }

        // Build a CPU-intensive query that will return concise information.         $select_count = array();
        foreach ( $avail_roles as $this_role => $name ) {
            $select_count[] = $wpdb->prepare( 'COUNT(NULLIF(`meta_value` LIKE %s, false))', '%' . $wpdb->esc_like( '"' . $this_role . '"' ) . '%' );
        }
        $select_count[] = "COUNT(NULLIF(`meta_value` = 'a:0:{}', false))";
        $select_count   = implode( ', ', $select_count );

        

        $actions = apply_filters( 'myblogs_blog_actions', $actions$user_blog );

        echo "<p class='my-sites-actions'>" . $actions . '</p>';

        /** This filter is documented in wp-admin/my-sites.php */
        echo apply_filters( 'myblogs_options', '', $user_blog );

        echo '</li>';

        restore_current_blog();
    }
    ?> </ul> <?php     if ( count( $blogs ) > 1 || has_action( 'myblogs_allblogs_options' ) || has_filter( 'myblogs_options' ) ) {
        ?> <input type="hidden" name="action" value="updateblogsettings" /> <?php         wp_nonce_field( 'update-my-sites' );
        submit_button();
    }
    
switch_to_blog( $this->blog_id );
            // Create a raw copy of the object for backward compatibility with the filter below.             $details = new stdClass();
            foreach ( get_object_vars( $this ) as $key => $value ) {
                $details->$key = $value;
            }
            $details->blogname   = get_option( 'blogname' );
            $details->siteurl    = get_option( 'siteurl' );
            $details->post_count = get_option( 'post_count' );
            $details->home       = get_option( 'home' );
            restore_current_blog();

            wp_cache_set( $this->blog_id, $details, 'site-details' );
        }

        /** This filter is documented in wp-includes/ms-blogs.php */
        $details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' );

        /** * Filters a site's extended properties. * * @since 4.6.0 * * @param stdClass $details The site details. */

            return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ]$blog_id );
        }

        $current = get_current_blog_id() == $blog_id;

        if ( $current ) {
            $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
        } else {
            switch_to_blog( $blog_id );
            $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
            restore_current_blog();
        }

        /* * This is all super old MU back compat joy. * 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name. */
        if ( false === $allowed_themes[ $blog_id ] ) {
            if ( $current ) {
                $allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
            } else {
                switch_to_blog( $blog_id );
                

                $referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer$action$themes$id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores             } else {
                $action = 'error';
                $n      = 'none';
            }
    }

    update_option( 'allowedthemes', $allowed_themes );
    restore_current_blog();

    wp_safe_redirect(
        add_query_arg(
            array(
                'id'    => $id,
                $action => $n,
            ),
            $referer
        )
    );
    exit;
}
Home | Imprint | This part of the site doesn't use cookies.