Make WordPress Core


Ignore:
Timestamp:
04/02/2010 06:46:07 AM (17 years ago)
Author:
nacin
Message:

Move add/remove super admin out of bulk edit and into user-edit.php. Introduce grant_super_admin() and revoke_super_admin(). Link to profile.php in ms-users user row for current user. Add defensive check by forcing IS_PROFILE_PAGE on user-edit if trying to edit your own user_id. see #12460

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/user-edit.php

    r13820 r13941  
    1010require_once('admin.php');
    1111
    12 if ( !defined('IS_PROFILE_PAGE') )
    13         define('IS_PROFILE_PAGE', false);
     12wp_reset_vars(array('action', 'redirect', 'profile', 'user_id', 'wp_http_referer'));
     13
     14$user_id = (int) $user_id;
     15$current_user = wp_get_current_user();
     16if ( ! defined( 'IS_PROFILE_PAGE' ) )
     17        define( 'IS_PROFILE_PAGE', ( $user_id == $current_user->ID ) );
     18
     19if ( ! $user_id && IS_PROFILE_PAGE )
     20        $user_id = $current_user->ID;
     21elseif ( ! $user_id && ! IS_PROFILE_PAGE )
     22        wp_die(__( 'Invalid user ID.' ) );
     23elseif ( ! get_userdata( $user_id ) )
     24        wp_die( __('Invalid user ID.') );
    1425
    1526wp_enqueue_script('user-profile');
    … …  
    2334$parent_file = 'users.php';
    2435
    25 wp_reset_vars(array('action', 'redirect', 'profile', 'user_id', 'wp_http_referer'));
    26 
    2736$wp_http_referer = remove_query_arg(array('update', 'delete_count'), stripslashes($wp_http_referer));
    28 
    29 $user_id = (int) $user_id;
    30 
    31 if ( !$user_id ) {
    32         if ( IS_PROFILE_PAGE ) {
    33                 $current_user = wp_get_current_user();
    34                 $user_id = $current_user->ID;
    35         } else {
    36                 wp_die(__('Invalid user ID.'));
    37         }
    38 } elseif ( !get_userdata($user_id) ) {
    39         wp_die( __('Invalid user ID.') );
    40 }
    4137
    4238$all_post_caps = array('posts', 'pages');
    … …  
    124120                $errors = edit_user($user_id);
    125121        if ( $delete_role ) // stops users being added to current blog when they are edited
    126                 update_user_meta( $user_id, $blog_prefix . 'capabilities' , '' );
     122                delete_user_meta( $user_id, $blog_prefix . 'capabilities' );
     123
     124        if ( is_multisite() && is_super_admin() && !IS_PROFILE_PAGE )
     125                empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id );
    127126}
    128127
    … …  
    143142?>
    144143
     144<?php if ( !IS_PROFILE_PAGE && is_super_admin( $profileuser->ID ) ) { ?>
     145        <div class="updated"><p><strong><?php _e('Important:'); ?></strong> <?php _e('This user has super admin privileges.'); ?></p></div>
     146<?php } ?>
    145147<?php if ( isset($_GET['updated']) ) : ?>
    146148<div id="message" class="updated">
    … …  
    166168<h2><?php echo esc_html( $title ); ?></h2>
    167169
    168 <form id="your-profile" action="<?php if ( IS_PROFILE_PAGE ) { echo admin_url('profile.php'); } else { echo admin_url('user-edit.php'); } ?>" method="post">
     170<form id="your-profile" action="<?php echo esc_url( admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post">
    169171<?php wp_nonce_field('update-user_' . $user_id) ?>
    170172<?php if ( $wp_http_referer ) : ?>
    … …  
    233235        echo '<option value="" selected="selected">' . __('&mdash; No role for this blog &mdash;') . '</option>';
    234236?>
    235 </select></td></tr>
     237</select>
     238<?php if ( is_multisite() && is_super_admin() ) { ?>
     239<p><label><input type="checkbox" id="super_admin" name="super_admin"<?php checked( is_super_admin( $profileuser->ID ) ); ?> /> <?php _e( 'Grant this user super admin privileges for the Network.'); ?></label></p>
     240<?php } ?>
     241</td></tr>
    236242<?php endif; //!IS_PROFILE_PAGE ?>
    237243
    … …  
    332338
    333339<?php
    334         if ( IS_PROFILE_PAGE ) {
    335                 do_action('show_user_profile', $profileuser);
    336         } else {
    337                 do_action('edit_user_profile', $profileuser);
    338         }
     340        if ( IS_PROFILE_PAGE )
     341                do_action( 'show_user_profile', $profileuser );
     342        else
     343                do_action( 'edit_user_profile', $profileuser );
    339344?>
    340345
Note: See TracChangeset for help on using the changeset viewer.