Make WordPress Core


Ignore:
Timestamp:
05/19/2014 05:19:36 AM (10 years ago)
Author:
wonderboymusic
Message:

Add access modifiers to methods/members in WP_Roles. Add a magic __call() method for BC.

See #27881, #22234.

File:
1 edited

Legend:

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

    r27390 r28503  
    3535     * @var array
    3636     */
    37     var $roles;
     37    public $roles;
    3838
    3939    /**
     
    4444     * @var array
    4545     */
    46     var $role_objects = array();
     46    public $role_objects = array();
    4747
    4848    /**
     
    5353     * @var array
    5454     */
    55     var $role_names = array();
     55    public $role_names = array();
    5656
    5757    /**
     
    6262     * @var string
    6363     */
    64     var $role_key;
     64    public $role_key;
    6565
    6666    /**
     
    7171     * @var bool
    7272     */
    73     var $use_db = true;
     73    public $use_db = true;
    7474
    7575    /**
     
    7878     * @since 2.0.0
    7979     */
    80     function __construct() {
     80    public function __construct() {
    8181        $this->_init();
     82    }
     83
     84    /**
     85     * Make private/protected methods readable for backwards compatibility
     86     *
     87     * @since 4.0.0
     88     * @param string $name
     89     * @param array $arguments
     90     * @return mixed
     91     */
     92    public function __call( $name, $arguments ) {
     93        return call_user_func_array( array( $this, $name ), $arguments );
    8294    }
    8395
     
    94106     * @global array $wp_user_roles Used to set the 'roles' property value.
    95107     */
    96     function _init () {
     108    protected function _init() {
    97109        global $wpdb, $wp_user_roles;
    98110        $this->role_key = $wpdb->get_blog_prefix() . 'user_roles';
     
    124136     * @access public
    125137     */
    126     function reinit() {
     138    public function reinit() {
    127139        // There is no need to reinit if using the wp_user_roles global.
    128140        if ( ! $this->use_db )
     
    161173     * @return WP_Role|null WP_Role object if role is added, null if already exists.
    162174     */
    163     function add_role( $role, $display_name, $capabilities = array() ) {
     175    public function add_role( $role, $display_name, $capabilities = array() ) {
    164176        if ( isset( $this->roles[$role] ) )
    165177            return;
     
    184196     * @param string $role Role name.
    185197     */
    186     function remove_role( $role ) {
     198    public function remove_role( $role ) {
    187199        if ( ! isset( $this->role_objects[$role] ) )
    188200            return;
     
    209221     * @param bool $grant Optional, default is true. Whether role is capable of performing capability.
    210222     */
    211     function add_cap( $role, $cap, $grant = true ) {
     223    public function add_cap( $role, $cap, $grant = true ) {
    212224        if ( ! isset( $this->roles[$role] ) )
    213225            return;
     
    227239     * @param string $cap Capability name.
    228240     */
    229     function remove_cap( $role, $cap ) {
     241    public function remove_cap( $role, $cap ) {
    230242        if ( ! isset( $this->roles[$role] ) )
    231243            return;
     
    245257     * @return WP_Role|null WP_Role object if found, null if the role does not exist.
    246258     */
    247     function get_role( $role ) {
     259    public function get_role( $role ) {
    248260        if ( isset( $this->role_objects[$role] ) )
    249261            return $this->role_objects[$role];
     
    260272     * @return array List of role names.
    261273     */
    262     function get_names() {
     274    public function get_names() {
    263275        return $this->role_names;
    264276    }
     
    273285     * @return bool
    274286     */
    275     function is_role( $role ) {
     287    public function is_role( $role ) {
    276288        return isset( $this->role_names[$role] );
    277289    }
Note: See TracChangeset for help on using the changeset viewer.