equal
deleted
inserted
replaced
93 /** |
93 /** |
94 * Make private/protected methods readable for backward compatibility. |
94 * Make private/protected methods readable for backward compatibility. |
95 * |
95 * |
96 * @since 4.0.0 |
96 * @since 4.0.0 |
97 * |
97 * |
98 * @param string $name Method to call. |
98 * @param string $name Method to call. |
99 * @param array $arguments Arguments to pass when calling. |
99 * @param array $arguments Arguments to pass when calling. |
100 * @return mixed|false Return value of the callback, false otherwise. |
100 * @return mixed|false Return value of the callback, false otherwise. |
101 */ |
101 */ |
102 public function __call( $name, $arguments ) { |
102 public function __call( $name, $arguments ) { |
103 if ( '_init' === $name ) { |
103 if ( '_init' === $name ) { |
104 return call_user_func_array( array( $this, $name ), $arguments ); |
104 return $this->_init( ...$arguments ); |
105 } |
105 } |
106 return false; |
106 return false; |
107 } |
107 } |
108 |
108 |
109 /** |
109 /** |
145 * The capabilities are defined in the following format `array( 'read' => true );` |
145 * The capabilities are defined in the following format `array( 'read' => true );` |
146 * To explicitly deny a role a capability you set the value for that capability to false. |
146 * To explicitly deny a role a capability you set the value for that capability to false. |
147 * |
147 * |
148 * @since 2.0.0 |
148 * @since 2.0.0 |
149 * |
149 * |
150 * @param string $role Role name. |
150 * @param string $role Role name. |
151 * @param string $display_name Role display name. |
151 * @param string $display_name Role display name. |
152 * @param array $capabilities List of role capabilities in the above format. |
152 * @param bool[] $capabilities List of capabilities keyed by the capability name, |
|
153 * e.g. array( 'edit_posts' => true, 'delete_posts' => false ). |
153 * @return WP_Role|void WP_Role object, if role is added. |
154 * @return WP_Role|void WP_Role object, if role is added. |
154 */ |
155 */ |
155 public function add_role( $role, $display_name, $capabilities = array() ) { |
156 public function add_role( $role, $display_name, $capabilities = array() ) { |
156 if ( empty( $role ) || isset( $this->roles[ $role ] ) ) { |
157 if ( empty( $role ) || isset( $this->roles[ $role ] ) ) { |
157 return; |
158 return; |
197 /** |
198 /** |
198 * Add capability to role. |
199 * Add capability to role. |
199 * |
200 * |
200 * @since 2.0.0 |
201 * @since 2.0.0 |
201 * |
202 * |
202 * @param string $role Role name. |
203 * @param string $role Role name. |
203 * @param string $cap Capability name. |
204 * @param string $cap Capability name. |
204 * @param bool $grant Optional, default is true. Whether role is capable of performing capability. |
205 * @param bool $grant Optional. Whether role is capable of performing capability. |
|
206 * Default true. |
205 */ |
207 */ |
206 public function add_cap( $role, $cap, $grant = true ) { |
208 public function add_cap( $role, $cap, $grant = true ) { |
207 if ( ! isset( $this->roles[ $role ] ) ) { |
209 if ( ! isset( $this->roles[ $role ] ) ) { |
208 return; |
210 return; |
209 } |
211 } |
218 * Remove capability from role. |
220 * Remove capability from role. |
219 * |
221 * |
220 * @since 2.0.0 |
222 * @since 2.0.0 |
221 * |
223 * |
222 * @param string $role Role name. |
224 * @param string $role Role name. |
223 * @param string $cap Capability name. |
225 * @param string $cap Capability name. |
224 */ |
226 */ |
225 public function remove_cap( $role, $cap ) { |
227 public function remove_cap( $role, $cap ) { |
226 if ( ! isset( $this->roles[ $role ] ) ) { |
228 if ( ! isset( $this->roles[ $role ] ) ) { |
227 return; |
229 return; |
228 } |
230 } |
353 |
355 |
354 if ( ! empty( $wp_user_roles ) ) { |
356 if ( ! empty( $wp_user_roles ) ) { |
355 return $wp_user_roles; |
357 return $wp_user_roles; |
356 } |
358 } |
357 |
359 |
358 if ( is_multisite() && $this->site_id != get_current_blog_id() ) { |
360 if ( is_multisite() && get_current_blog_id() != $this->site_id ) { |
359 remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 ); |
361 remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 ); |
360 |
362 |
361 $roles = get_blog_option( $this->site_id, $this->role_key, array() ); |
363 $roles = get_blog_option( $this->site_id, $this->role_key, array() ); |
362 |
364 |
363 add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 ); |
365 add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 ); |