WordPress.org

Make WordPress Core

Changeset 32541


Ignore:
Timestamp:
05/22/2015 04:46:36 AM (6 years ago)
Author:
wonderboymusic
Message:

Create a function, wp_roles(), to DRY the inline instantiation of the $wp_roles global.

Add missing doc blocks for capabilities.php.

See #32444.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/capabilities.php

    r32530 r32541  
    139139     * @since 3.5.0
    140140     * @access public
     141     *
     142     * @global wpdb $wpdb
    141143     */
    142144    public function reinit() {
     
    340342     * Assign role a capability.
    341343     *
    342      * @see WP_Roles::add_cap() Method uses implementation for role.
    343344     * @since 2.0.0
    344345     * @access public
     
    348349     */
    349350    public function add_cap( $cap, $grant = true ) {
    350         global $wp_roles;
    351 
    352         if ( ! isset( $wp_roles ) )
    353             $wp_roles = new WP_Roles();
    354 
    355351        $this->capabilities[$cap] = $grant;
    356         $wp_roles->add_cap( $this->name, $cap, $grant );
     352        wp_roles()->add_cap( $this->name, $cap, $grant );
    357353    }
    358354
     
    371367     */
    372368    public function remove_cap( $cap ) {
    373         global $wp_roles;
    374 
    375         if ( ! isset( $wp_roles ) )
    376             $wp_roles = new WP_Roles();
    377 
    378369        unset( $this->capabilities[$cap] );
    379         $wp_roles->remove_cap( $this->name, $cap );
     370        wp_roles()->remove_cap( $this->name, $cap );
    380371    }
    381372
     
    509500     * @access public
    510501     *
     502     * @global wpdb $wpdb
     503     *
    511504     * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB.
    512505     * @param string $name Optional. User's username
     
    569562     *
    570563     * @since 3.3.0
     564     *
     565     * @global wpdb $wpdb
    571566     *
    572567     * @param string $field The field to query against: 'id', 'slug', 'email' or 'login'
     
    756751     * @since 2.1.0
    757752     *
     753     * @global wpdb $wpdb
     754     *
    758755     * @param string $cap_key Optional capability key
    759756     */
     
    783780     *
    784781     * @since 2.0.0
    785      * @uses $wp_roles
    786782     * @access public
    787783     *
     
    789785     */
    790786    public function get_role_caps() {
    791         global $wp_roles;
    792 
    793         if ( ! isset( $wp_roles ) )
    794             $wp_roles = new WP_Roles();
     787        $wp_roles = wp_roles();
    795788
    796789        //Filter out caps that are not role names and assign to $this->roles
     
    923916     * @since 2.0.0
    924917     * @access public
     918     *
     919     * @global wpdb $wpdb
    925920     */
    926921    public function update_user_level_from_caps() {
     
    969964     * @since 2.1.0
    970965     * @access public
     966     *
     967     * @global wpdb $wpdb
    971968     */
    972969    public function remove_all_caps() {
     
    10491046     *
    10501047     * @since 3.0.0
     1048     *
     1049     * @global wpdb $wpdb
    10511050     *
    10521051     * @param int $blog_id Optional Blog ID, defaults to current blog.
     
    14761475
    14771476/**
     1477 * Retrieve the global WP_Roles instance, instantiate if necessary
     1478 *
     1479 * @global WP_Roles $wp_roles
     1480 * @return WP_Roles global instance
     1481 */
     1482function wp_roles() {
     1483    global $wp_roles;
     1484
     1485    if ( ! isset( $wp_roles ) ) {
     1486        $wp_roles = new WP_Roles();
     1487    }
     1488    return $wp_roles;
     1489}
     1490
     1491/**
    14781492 * Retrieve role object.
    14791493 *
    1480  * @see WP_Roles::get_role() Uses method to retrieve role object.
    14811494 * @since 2.0.0
    14821495 *
     
    14851498 */
    14861499function get_role( $role ) {
    1487     global $wp_roles;
    1488 
    1489     if ( ! isset( $wp_roles ) )
    1490         $wp_roles = new WP_Roles();
    1491 
    1492     return $wp_roles->get_role( $role );
     1500    return wp_roles()->get_role( $role );
    14931501}
    14941502
     
    14961504 * Add role, if it does not exist.
    14971505 *
    1498  * @see WP_Roles::add_role() Uses method to add role.
    14991506 * @since 2.0.0
    15001507 *
     
    15051512 */
    15061513function add_role( $role, $display_name, $capabilities = array() ) {
    1507     global $wp_roles;
    1508 
    1509     if ( ! isset( $wp_roles ) )
    1510         $wp_roles = new WP_Roles();
    1511 
    1512     return $wp_roles->add_role( $role, $display_name, $capabilities );
     1514    return wp_roles()->add_role( $role, $display_name, $capabilities );
    15131515}
    15141516
     
    15161518 * Remove role, if it exists.
    15171519 *
    1518  * @see WP_Roles::remove_role() Uses method to remove role.
    15191520 * @since 2.0.0
    15201521 *
     
    15221523 */
    15231524function remove_role( $role ) {
    1524     global $wp_roles;
    1525 
    1526     if ( ! isset( $wp_roles ) )
    1527         $wp_roles = new WP_Roles();
    1528 
    1529     $wp_roles->remove_role( $role );
     1525    wp_roles()->remove_role( $role );
    15301526}
    15311527
     
    15351531 * @since 3.0.0
    15361532 *
    1537  * @uses $super_admins Super admins global variable, if set.
     1533 * @global array $super_admins
    15381534 *
    15391535 * @return array List of super admin logins
  • trunk/src/wp-includes/user.php

    r32524 r32541  
    13351335 */
    13361336function count_users($strategy = 'time') {
    1337     global $wpdb, $wp_roles;
     1337    global $wpdb;
    13381338
    13391339    // Initialize
     
    13431343
    13441344    if ( 'time' == $strategy ) {
    1345         global $wp_roles;
    1346 
    1347         if ( ! isset( $wp_roles ) )
    1348             $wp_roles = new WP_Roles();
    1349 
    1350         $avail_roles = $wp_roles->get_names();
     1345        $avail_roles = wp_roles()->get_names();
    13511346
    13521347        // Build a CPU-intensive query that will return concise information.
Note: See TracChangeset for help on using the changeset viewer.