WordPress.org

Make WordPress Core

Ticket #21788: 21788.diff

File 21788.diff, 6.4 KB (added by jeremyfelt, 4 years ago)
  • src/wp-admin/includes/ms.php

     
    852852}
    853853
    854854/**
    855  * Grants Super Admin privileges.
    856  *
    857  * @since 3.0.0
    858  *
    859  * @global array $super_admins
    860  *
    861  * @param int $user_id ID of the user to be granted Super Admin privileges.
    862  * @return bool True on success, false on failure. This can fail when the user is
    863  *              already a super admin or when the `$super_admins` global is defined.
    864  */
    865 function grant_super_admin( $user_id ) {
    866         // If global super_admins override is defined, there is nothing to do here.
    867         if ( isset( $GLOBALS['super_admins'] ) ) {
    868                 return false;
    869         }
    870 
    871         /**
    872          * Fires before the user is granted Super Admin privileges.
    873          *
    874          * @since 3.0.0
    875          *
    876          * @param int $user_id ID of the user that is about to be granted Super Admin privileges.
    877          */
    878         do_action( 'grant_super_admin', $user_id );
    879 
    880         // Directly fetch site_admins instead of using get_super_admins()
    881         $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
    882 
    883         $user = get_userdata( $user_id );
    884         if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
    885                 $super_admins[] = $user->user_login;
    886                 update_site_option( 'site_admins' , $super_admins );
    887 
    888                 /**
    889                  * Fires after the user is granted Super Admin privileges.
    890                  *
    891                  * @since 3.0.0
    892                  *
    893                  * @param int $user_id ID of the user that was granted Super Admin privileges.
    894                  */
    895                 do_action( 'granted_super_admin', $user_id );
    896                 return true;
    897         }
    898         return false;
    899 }
    900 
    901 /**
    902  * Revokes Super Admin privileges.
    903  *
    904  * @since 3.0.0
    905  *
    906  * @global array $super_admins
    907  *
    908  * @param int $user_id ID of the user Super Admin privileges to be revoked from.
    909  * @return bool True on success, false on failure. This can fail when the user's email
    910  *              is the network admin email or when the `$super_admins` global is defined.
    911  */
    912 function revoke_super_admin( $user_id ) {
    913         // If global super_admins override is defined, there is nothing to do here.
    914         if ( isset( $GLOBALS['super_admins'] ) ) {
    915                 return false;
    916         }
    917 
    918         /**
    919          * Fires before the user's Super Admin privileges are revoked.
    920          *
    921          * @since 3.0.0
    922          *
    923          * @param int $user_id ID of the user Super Admin privileges are being revoked from.
    924          */
    925         do_action( 'revoke_super_admin', $user_id );
    926 
    927         // Directly fetch site_admins instead of using get_super_admins()
    928         $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
    929 
    930         $user = get_userdata( $user_id );
    931         if ( $user && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) {
    932                 if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
    933                         unset( $super_admins[$key] );
    934                         update_site_option( 'site_admins', $super_admins );
    935 
    936                         /**
    937                          * Fires after the user's Super Admin privileges are revoked.
    938                          *
    939                          * @since 3.0.0
    940                          *
    941                          * @param int $user_id ID of the user Super Admin privileges were revoked from.
    942                          */
    943                         do_action( 'revoked_super_admin', $user_id );
    944                         return true;
    945                 }
    946         }
    947         return false;
    948 }
    949 
    950 /**
    951855 * Whether or not we can edit this network from this page.
    952856 *
    953857 * By default editing of network is restricted to the Network Admin for that `$site_id`
  • src/wp-includes/capabilities.php

     
    619619
    620620        return false;
    621621}
     622
     623/**
     624 * Grants Super Admin privileges.
     625 *
     626 * @since 3.0.0
     627 *
     628 * @global array $super_admins
     629 *
     630 * @param int $user_id ID of the user to be granted Super Admin privileges.
     631 * @return bool True on success, false on failure. This can fail when the user is
     632 *              already a super admin or when the `$super_admins` global is defined.
     633 */
     634function grant_super_admin( $user_id ) {
     635        // If global super_admins override is defined, there is nothing to do here.
     636        if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) {
     637                return false;
     638        }
     639
     640        /**
     641         * Fires before the user is granted Super Admin privileges.
     642         *
     643         * @since 3.0.0
     644         *
     645         * @param int $user_id ID of the user that is about to be granted Super Admin privileges.
     646         */
     647        do_action( 'grant_super_admin', $user_id );
     648
     649        // Directly fetch site_admins instead of using get_super_admins()
     650        $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
     651
     652        $user = get_userdata( $user_id );
     653        if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
     654                $super_admins[] = $user->user_login;
     655                update_site_option( 'site_admins' , $super_admins );
     656
     657                /**
     658                 * Fires after the user is granted Super Admin privileges.
     659                 *
     660                 * @since 3.0.0
     661                 *
     662                 * @param int $user_id ID of the user that was granted Super Admin privileges.
     663                 */
     664                do_action( 'granted_super_admin', $user_id );
     665                return true;
     666        }
     667        return false;
     668}
     669
     670/**
     671 * Revokes Super Admin privileges.
     672 *
     673 * @since 3.0.0
     674 *
     675 * @global array $super_admins
     676 *
     677 * @param int $user_id ID of the user Super Admin privileges to be revoked from.
     678 * @return bool True on success, false on failure. This can fail when the user's email
     679 *              is the network admin email or when the `$super_admins` global is defined.
     680 */
     681function revoke_super_admin( $user_id ) {
     682        // If global super_admins override is defined, there is nothing to do here.
     683        if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) {
     684                return false;
     685        }
     686
     687        /**
     688         * Fires before the user's Super Admin privileges are revoked.
     689         *
     690         * @since 3.0.0
     691         *
     692         * @param int $user_id ID of the user Super Admin privileges are being revoked from.
     693         */
     694        do_action( 'revoke_super_admin', $user_id );
     695
     696        // Directly fetch site_admins instead of using get_super_admins()
     697        $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
     698
     699        $user = get_userdata( $user_id );
     700        if ( $user && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) {
     701                if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
     702                        unset( $super_admins[$key] );
     703                        update_site_option( 'site_admins', $super_admins );
     704
     705                        /**
     706                         * Fires after the user's Super Admin privileges are revoked.
     707                         *
     708                         * @since 3.0.0
     709                         *
     710                         * @param int $user_id ID of the user Super Admin privileges were revoked from.
     711                         */
     712                        do_action( 'revoked_super_admin', $user_id );
     713                        return true;
     714                }
     715        }
     716        return false;
     717}