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