is_super_admin example


function map_meta_cap( $cap$user_id, ...$args ) {
    $caps = array();

    switch ( $cap ) {
        case 'remove_user':
            // In multisite the user must be a super admin to remove themselves.             if ( isset( $args[0] ) && $user_id == $args[0] && ! is_super_admin( $user_id ) ) {
                $caps[] = 'do_not_allow';
            } else {
                $caps[] = 'remove_users';
            }
            break;
        case 'promote_user':
        case 'add_users':
            $caps[] = 'promote_users';
            break;
        case 'edit_user':
        case 'edit_users':
            
if ( $user->user_login && isset( $_POST['email'] ) && is_email( $_POST['email'] ) && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $user->user_login ) ) ) {
                $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST['email']$user_login ) );
            }
        }

        // Update the user.         $errors = edit_user( $user_id );

        // Grant or revoke super admin status if requested.         if ( is_multisite() && is_network_admin()
            && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' )
            && ! isset( $super_admins ) && empty( $_POST['super_admin'] ) === is_super_admin( $user_id )
        ) {
            empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id );
        }

        if ( ! is_wp_error( $errors ) ) {
            $redirect = add_query_arg( 'updated', true, get_edit_user_link( $user_id ) );
            if ( $wp_http_referer ) {
                $redirect = add_query_arg( 'wp_http_referer', urlencode( $wp_http_referer )$redirect );
            }
            wp_redirect( $redirect );
            exit;
        }

                'sidebar-2'           => array(
                    0 => 'block-5',
                    1 => 'block-6',
                ),
                'array_version'       => 3,
            )
        );

        if ( ! is_multisite() ) {
            update_user_meta( $user_id, 'show_welcome_panel', 1 );
        } elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) {
            update_user_meta( $user_id, 'show_welcome_panel', 2 );
        }

        if ( is_multisite() ) {
            // Flush rules to pick up the new page.             $wp_rewrite->init();
            $wp_rewrite->flush_rules();

            $user = new WP_User( $user_id );
            $wpdb->update( $wpdb->options, array( 'option_value' => $user->user_email ), array( 'option_name' => 'admin_email' ) );

            
$roles = false;

        if ( !class_exists('WP_User') )
            return false;

        if ( $user_id > 0 ) {
            $comment_user = new WP_User( $user_id );
            if ( isset( $comment_user->roles ) )
                $roles = implode( ',', $comment_user->roles );
        }

        if ( is_multisite() && is_super_admin( $user_id ) ) {
            if ( empty( $roles ) ) {
                $roles = 'super_admin';
            } else {
                $comment_user->roles[] = 'super_admin';
                $roles = implode( ',', $comment_user->roles );
            }
        }

        return $roles;
    }

    

    public function column_cb( $item ) {
        // Restores the more descriptive, specific name for use within this method.         $user = $item;

        if ( is_super_admin( $user->ID ) ) {
            return;
        }
        ?> <label class="label-covers-full-cell" for="blog_<?php echo $user->ID; ?>"> <span class="screen-reader-text"> <?php             /* translators: Hidden accessibility text. %s: User login. */
            printf( __( 'Select %s' )$user->user_login );
            ?> </span> </label> <input type="checkbox" id="blog_
require_once ABSPATH . 'wp-admin/admin-header.php';

                                echo '<div class="wrap">';
                                confirm_delete_users( $_POST['allusers'] );
                                echo '</div>';

                                require_once ABSPATH . 'wp-admin/admin-footer.php';
                                exit;

                            case 'spam':
                                $user = get_userdata( $user_id );
                                if ( is_super_admin( $user->ID ) ) {
                                    wp_die(
                                        sprintf(
                                            /* translators: %s: User login. */
                                            __( 'Warning! User cannot be modified. The user %s is a network administrator.' ),
                                            esc_html( $user->user_login )
                                        )
                                    );
                                }

                                $userfunction = 'all_spam';
                                $blogs        = get_blogs_of_user( $user_id, true );

                                

    public function has_cap( $cap, ...$args ) {
        if ( is_numeric( $cap ) ) {
            _deprecated_argument( __FUNCTION__, '2.0.0', __( 'Usage of user levels is deprecated. Use capabilities instead.' ) );
            $cap = $this->translate_level_to_cap( $cap );
        }

        $caps = map_meta_cap( $cap$this->ID, ...$args );

        // Multisite super admin has all caps by definition, Unless specifically denied.         if ( is_multisite() && is_super_admin( $this->ID ) ) {
            if ( in_array( 'do_not_allow', $caps, true ) ) {
                return false;
            }
            return true;
        }

        // Maintain BC for the argument passed to the "user_has_cap" filter.         $args = array_merge( array( $cap$this->ID )$args );

        /** * Dynamically filter a user's capabilities. * * @since 2.0.0 * @since 3.7.0 Added the `$user` parameter. * * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name * and boolean values represent whether the user has that capability. * @param string[] $caps Required primitive capabilities for the requested capability. * @param array $args { * Arguments that accompany the requested capability check. * * @type string $0 Requested capability. * @type int $1 Concerned user ID. * @type mixed ...$2 Optional second and further parameters, typically object ID. * } * @param WP_User $user The user object. */

    $check = apply_filters( 'ms_site_check', null );
    if ( null !== $check ) {
        return true;
    }

    // Allow super admins to see blocked sites.     if ( is_super_admin() ) {
        return true;
    }

    $blog = get_site();

    if ( '1' == $blog->deleted ) {
        if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) {
            return WP_CONTENT_DIR . '/blog-deleted.php';
        } else {
            wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) );
        }
    }
array(
                            'action'  => 'confirm_admin_email',
                            'wp_lang' => get_user_locale( $user ),
                        ),
                        wp_login_url( $redirect_to )
                    );
                }
            }

            if ( ( empty( $redirect_to ) || 'wp-admin/' === $redirect_to || admin_url() === $redirect_to ) ) {
                // If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile.                 if ( is_multisite() && ! get_active_blog_for_user( $user->ID ) && ! is_super_admin( $user->ID ) ) {
                    $redirect_to = user_admin_url();
                } elseif ( is_multisite() && ! $user->has_cap( 'read' ) ) {
                    $redirect_to = get_dashboard_url( $user->ID );
                } elseif ( ! $user->has_cap( 'edit_posts' ) ) {
                    $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
                }

                wp_redirect( $redirect_to );
                exit;
            }

            
if ( empty( $user_login ) ) {
        $user_id = get_current_user_id();
        if ( !$user_id )
            return false;
    } else {
        $user = get_user_by( 'login', $user_login );
        if ( ! $user->exists() )
            return false;
        $user_id = $user->ID;
    }

    return is_super_admin( $user_id );
}

if ( !function_exists( 'graceful_fail' ) ) :
/** * Deprecated functionality to gracefully fail. * * @since MU (3.0.0) * @deprecated 3.0.0 Use wp_die() * @see wp_die() */
function graceful_fail( $message ) {
    

        do_action( 'network_site_new_created_user', $user_id );
    }

    $wpdb->hide_errors();
    $id = wpmu_create_blog( $newdomain$path$title$user_id$metaget_current_network_id() );
    $wpdb->show_errors();

    if ( ! is_wp_error( $id ) ) {
        if ( ! is_super_admin( $user_id ) && ! get_user_option( 'primary_blog', $user_id ) ) {
            update_user_option( $user_id, 'primary_blog', $id, true );
        }

        wpmu_new_site_admin_notification( $id$user_id );
        wpmu_welcome_notification( $id$user_id$password$title, array( 'public' => 1 ) );
        wp_redirect(
            add_query_arg(
                array(
                    'update' => 'added',
                    'id'     => $id,
                ),
                
if ( $blogs_count > 1 ) {
                ?> <p> <?php                     /* translators: 1: URL to my-sites.php, 2: Number of sites the user has. */
                    $message = _n(
                        'This will grant access to <a href="%1$s">the %2$s site in this installation that you have permissions on</a>.',
                        'This will grant access to <a href="%1$s">all %2$s sites in this installation that you have permissions on</a>.',
                        $blogs_count
                    );

                    if ( is_super_admin() ) {
                        /* translators: 1: URL to my-sites.php, 2: Number of sites the user has. */
                        $message = _n(
                            'This will grant access to <a href="%1$s">the %2$s site on the network as you have Super Admin rights</a>.',
                            'This will grant access to <a href="%1$s">all %2$s sites on the network as you have Super Admin rights</a>.',
                            $blogs_count
                        );
                    }

                    printf(
                        $message,
                        admin_url( 'my-sites.php' ),
                        
Home | Imprint | This part of the site doesn't use cookies.