Make WordPress Core

Ticket #32444: 32444.diff

File 32444.diff, 5.7 KB (added by wonderboymusic, 10 years ago)
  • src/wp-includes/capabilities.php

     
    138138         *
    139139         * @since 3.5.0
    140140         * @access public
     141         *
     142         * @global wpdb $wpdb
    141143         */
    142144        public function reinit() {
    143145                // There is no need to reinit if using the wp_user_roles global.
     
    339341        /**
    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
    345346         *
     
    347348         * @param bool $grant Whether role has capability privilege.
    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
    359355        /**
     
    370366         * @param string $cap Capability name.
    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
    382373        /**
     
    508499         * @since 2.0.0
    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
    513506         * @param int $blog_id Optional Blog ID, defaults to current blog.
     
    569562         *
    570563         * @since 3.3.0
    571564         *
     565         * @global wpdb $wpdb
     566         *
    572567         * @param string $field The field to query against: 'id', 'slug', 'email' or 'login'
    573568         * @param string|int $value The field value
    574569         * @return object|false Raw user object
     
    755750         * @access protected
    756751         * @since 2.1.0
    757752         *
     753         * @global wpdb $wpdb
     754         *
    758755         * @param string $cap_key Optional capability key
    759756         */
    760757        function _init_caps( $cap_key = '' ) {
     
    782779         * granted permission to.
    783780         *
    784781         * @since 2.0.0
    785          * @uses $wp_roles
    786782         * @access public
    787783         *
    788784         * @return array List of all capabilities for the user.
    789785         */
    790786        public function get_role_caps() {
    791                 global $wp_roles;
     787                $wp_roles = wp_roles();
    792788
    793                 if ( ! isset( $wp_roles ) )
    794                         $wp_roles = new WP_Roles();
    795 
    796789                //Filter out caps that are not role names and assign to $this->roles
    797790                if ( is_array( $this->caps ) )
    798791                        $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) );
     
    922915         *
    923916         * @since 2.0.0
    924917         * @access public
     918         *
     919         * @global wpdb $wpdb
    925920         */
    926921        public function update_user_level_from_caps() {
    927922                global $wpdb;
     
    968963         *
    969964         * @since 2.1.0
    970965         * @access public
     966         *
     967         * @global wpdb $wpdb
    971968         */
    972969        public function remove_all_caps() {
    973970                global $wpdb;
     
    10491046         *
    10501047         * @since 3.0.0
    10511048         *
     1049         * @global wpdb $wpdb
     1050         *
    10521051         * @param int $blog_id Optional Blog ID, defaults to current blog.
    10531052         */
    10541053        public function for_blog( $blog_id = '' ) {
     
    14751474}
    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 *
    14831496 * @param string $role Role name.
     
    14841497 * @return WP_Role|null WP_Role object if found, null if the role does not exist.
    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
    14951503/**
    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 *
    15011508 * @param string $role Role name.
     
    15041511 * @return WP_Role|null WP_Role object if role is added, null if already exists.
    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
    15151517/**
    15161518 * Remove role, if it exists.
    15171519 *
    1518  * @see WP_Roles::remove_role() Uses method to remove role.
    15191520 * @since 2.0.0
    15201521 *
    15211522 * @param string $role Role name.
    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
    15321528/**
     
    15341530 *
    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
    15401536 */
  • src/wp-includes/user.php

     
    13341334 * @return array Includes a grand total and an array of counts indexed by role strings.
    13351335 */
    13361336function count_users($strategy = 'time') {
    1337         global $wpdb, $wp_roles;
     1337        global $wpdb;
    13381338
    13391339        // Initialize
    13401340        $id = get_current_blog_id();
     
    13421342        $result = array();
    13431343
    13441344        if ( 'time' == $strategy ) {
    1345                 global $wp_roles;
     1345                $avail_roles = wp_roles()->get_names();
    13461346
    1347                 if ( ! isset( $wp_roles ) )
    1348                         $wp_roles = new WP_Roles();
    1349 
    1350                 $avail_roles = $wp_roles->get_names();
    1351 
    13521347                // Build a CPU-intensive query that will return concise information.
    13531348                $select_count = array();
    13541349                foreach ( $avail_roles as $this_role => $name ) {