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