@@ 510-529 (lines=20) @@ | ||
507 | * |
|
508 | * @param string $role Role name. |
|
509 | */ |
|
510 | public function add_role( $role ) { |
|
511 | if ( empty( $role ) ) { |
|
512 | return; |
|
513 | } |
|
514 | ||
515 | $this->caps[$role] = true; |
|
516 | update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
517 | $this->get_role_caps(); |
|
518 | $this->update_user_level_from_caps(); |
|
519 | ||
520 | /** |
|
521 | * Fires immediately after the user has been given a new role. |
|
522 | * |
|
523 | * @since 4.3.0 |
|
524 | * |
|
525 | * @param int $user_id The user ID. |
|
526 | * @param string $role The new role. |
|
527 | */ |
|
528 | do_action( 'add_user_role', $this->ID, $role ); |
|
529 | } |
|
530 | ||
531 | /** |
|
532 | * Remove role from user. |
|
@@ 539-556 (lines=18) @@ | ||
536 | * |
|
537 | * @param string $role Role name. |
|
538 | */ |
|
539 | public function remove_role( $role ) { |
|
540 | if ( !in_array($role, $this->roles) ) |
|
541 | return; |
|
542 | unset( $this->caps[$role] ); |
|
543 | update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
544 | $this->get_role_caps(); |
|
545 | $this->update_user_level_from_caps(); |
|
546 | ||
547 | /** |
|
548 | * Fires immediately after a role as been removed from a user. |
|
549 | * |
|
550 | * @since 4.3.0 |
|
551 | * |
|
552 | * @param int $user_id The user ID. |
|
553 | * @param string $role The removed role. |
|
554 | */ |
|
555 | do_action( 'remove_user_role', $this->ID, $role ); |
|
556 | } |
|
557 | ||
558 | /** |
|
559 | * Set the role of the user. |