wp/wp-includes/class-wp-role.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    39 	 *
    39 	 *
    40 	 * @param string $role Role name.
    40 	 * @param string $role Role name.
    41 	 * @param array $capabilities List of capabilities.
    41 	 * @param array $capabilities List of capabilities.
    42 	 */
    42 	 */
    43 	public function __construct( $role, $capabilities ) {
    43 	public function __construct( $role, $capabilities ) {
    44 		$this->name = $role;
    44 		$this->name         = $role;
    45 		$this->capabilities = $capabilities;
    45 		$this->capabilities = $capabilities;
    46 	}
    46 	}
    47 
    47 
    48 	/**
    48 	/**
    49 	 * Assign role a capability.
    49 	 * Assign role a capability.
    52 	 *
    52 	 *
    53 	 * @param string $cap Capability name.
    53 	 * @param string $cap Capability name.
    54 	 * @param bool $grant Whether role has capability privilege.
    54 	 * @param bool $grant Whether role has capability privilege.
    55 	 */
    55 	 */
    56 	public function add_cap( $cap, $grant = true ) {
    56 	public function add_cap( $cap, $grant = true ) {
    57 		$this->capabilities[$cap] = $grant;
    57 		$this->capabilities[ $cap ] = $grant;
    58 		wp_roles()->add_cap( $this->name, $cap, $grant );
    58 		wp_roles()->add_cap( $this->name, $cap, $grant );
    59 	}
    59 	}
    60 
    60 
    61 	/**
    61 	/**
    62 	 * Removes a capability from a role.
    62 	 * Removes a capability from a role.
    69 	 * @since 2.0.0
    69 	 * @since 2.0.0
    70 	 *
    70 	 *
    71 	 * @param string $cap Capability name.
    71 	 * @param string $cap Capability name.
    72 	 */
    72 	 */
    73 	public function remove_cap( $cap ) {
    73 	public function remove_cap( $cap ) {
    74 		unset( $this->capabilities[$cap] );
    74 		unset( $this->capabilities[ $cap ] );
    75 		wp_roles()->remove_cap( $this->name, $cap );
    75 		wp_roles()->remove_cap( $this->name, $cap );
    76 	}
    76 	}
    77 
    77 
    78 	/**
    78 	/**
    79 	 * Determines whether the role has the given capability.
    79 	 * Determines whether the role has the given capability.
    92 		/**
    92 		/**
    93 		 * Filters which capabilities a role has.
    93 		 * Filters which capabilities a role has.
    94 		 *
    94 		 *
    95 		 * @since 2.0.0
    95 		 * @since 2.0.0
    96 		 *
    96 		 *
    97 		 * @param array  $capabilities Array of role capabilities.
    97 		 * @param bool[] $capabilities Associative array of capabilities for the role.
    98 		 * @param string $cap          Capability name.
    98 		 * @param string $cap          Capability name.
    99 		 * @param string $name         Role name.
    99 		 * @param string $name         Role name.
   100 		 */
   100 		 */
   101 		$capabilities = apply_filters( 'role_has_cap', $this->capabilities, $cap, $this->name );
   101 		$capabilities = apply_filters( 'role_has_cap', $this->capabilities, $cap, $this->name );
   102 
   102 
   103 		if ( !empty( $capabilities[$cap] ) )
   103 		if ( ! empty( $capabilities[ $cap ] ) ) {
   104 			return $capabilities[$cap];
   104 			return $capabilities[ $cap ];
   105 		else
   105 		} else {
   106 			return false;
   106 			return false;
       
   107 		}
   107 	}
   108 	}
   108 
   109 
   109 }
   110 }