wp/wp-includes/capabilities.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   818 	}
   818 	}
   819 	return $wp_roles;
   819 	return $wp_roles;
   820 }
   820 }
   821 
   821 
   822 /**
   822 /**
   823  * Retrieve role object.
   823  * Retrieves role object.
   824  *
   824  *
   825  * @since 2.0.0
   825  * @since 2.0.0
   826  *
   826  *
   827  * @param string $role Role name.
   827  * @param string $role Role name.
   828  * @return WP_Role|null WP_Role object if found, null if the role does not exist.
   828  * @return WP_Role|null WP_Role object if found, null if the role does not exist.
   830 function get_role( $role ) {
   830 function get_role( $role ) {
   831 	return wp_roles()->get_role( $role );
   831 	return wp_roles()->get_role( $role );
   832 }
   832 }
   833 
   833 
   834 /**
   834 /**
   835  * Add role, if it does not exist.
   835  * Adds a role, if it does not exist.
   836  *
   836  *
   837  * @since 2.0.0
   837  * @since 2.0.0
   838  *
   838  *
   839  * @param string $role         Role name.
   839  * @param string $role         Role name.
   840  * @param string $display_name Display name for role.
   840  * @param string $display_name Display name for role.
   848 	}
   848 	}
   849 	return wp_roles()->add_role( $role, $display_name, $capabilities );
   849 	return wp_roles()->add_role( $role, $display_name, $capabilities );
   850 }
   850 }
   851 
   851 
   852 /**
   852 /**
   853  * Remove role, if it exists.
   853  * Removes a role, if it exists.
   854  *
   854  *
   855  * @since 2.0.0
   855  * @since 2.0.0
   856  *
   856  *
   857  * @param string $role Role name.
   857  * @param string $role Role name.
   858  */
   858  */
   859 function remove_role( $role ) {
   859 function remove_role( $role ) {
   860 	wp_roles()->remove_role( $role );
   860 	wp_roles()->remove_role( $role );
   861 }
   861 }
   862 
   862 
   863 /**
   863 /**
   864  * Retrieve a list of super admins.
   864  * Retrieves a list of super admins.
   865  *
   865  *
   866  * @since 3.0.0
   866  * @since 3.0.0
   867  *
   867  *
   868  * @global array $super_admins
   868  * @global array $super_admins
   869  *
   869  *
   878 		return get_site_option( 'site_admins', array( 'admin' ) );
   878 		return get_site_option( 'site_admins', array( 'admin' ) );
   879 	}
   879 	}
   880 }
   880 }
   881 
   881 
   882 /**
   882 /**
   883  * Determine if user is a site admin.
   883  * Determines whether user is a site admin.
   884  *
   884  *
   885  * @since 3.0.0
   885  * @since 3.0.0
   886  *
   886  *
   887  * @param int|false $user_id Optional. The ID of a user. Defaults to false, to check the current user.
   887  * @param int|false $user_id Optional. The ID of a user. Defaults to false, to check the current user.
   888  * @return bool Whether the user is a site admin.
   888  * @return bool Whether the user is a site admin.
   889  */
   889  */
   890 function is_super_admin( $user_id = false ) {
   890 function is_super_admin( $user_id = false ) {
   891 	if ( ! $user_id || get_current_user_id() == $user_id ) {
   891 	if ( ! $user_id ) {
   892 		$user = wp_get_current_user();
   892 		$user = wp_get_current_user();
   893 	} else {
   893 	} else {
   894 		$user = get_userdata( $user_id );
   894 		$user = get_userdata( $user_id );
   895 	}
   895 	}
   896 
   896