| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace WP_Syntex\Polylang\Capabilities\User; |
| 7 |
|
| 8 |
use WP_User; |
| 9 |
|
| 10 |
/** |
| 11 |
* A class to create a decorated user. |
| 12 |
* Always returns a `NOOP` instance so capabilities features are disabled by default. |
| 13 |
* |
| 14 |
* @since 3.8 |
| 15 |
*/ |
| 16 |
class Creator implements Creator_Interface { |
| 17 |
/** |
| 18 |
* The user instance to be used for capability checks. |
| 19 |
* |
| 20 |
* @var NOOP |
| 21 |
*/ |
| 22 |
private ?NOOP $instance = null; |
| 23 |
|
| 24 |
/** |
| 25 |
* Creates and returns the user. |
| 26 |
* |
| 27 |
* @since 3.8 |
| 28 |
* |
| 29 |
* @param WP_User $user The user to decorate. |
| 30 |
* @return User_Interface Instance of `NOOP`. |
| 31 |
*/ |
| 32 |
public function get( WP_User $user ): User_Interface { |
| 33 |
if ( $this->instance && $user->ID === $this->instance->get_id() ) { |
| 34 |
return $this->instance; |
| 35 |
} |
| 36 |
|
| 37 |
$this->instance = new NOOP( $user ); |
| 38 |
|
| 39 |
return $this->instance; |
| 40 |
} |
| 41 |
} |
| 42 |
|