| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace WP_Syntex\Polylang\Capabilities\User; |
| 7 |
|
| 8 |
use WP_User; |
| 9 |
use PLL_Language; |
| 10 |
|
| 11 |
/** |
| 12 |
* An interface for user with translation management feature. |
| 13 |
* Implements decorator pattern for `WP_User`. |
| 14 |
* |
| 15 |
* @since 3.8 |
| 16 |
*/ |
| 17 |
interface User_Interface { |
| 18 |
/** |
| 19 |
* Returns the user ID. |
| 20 |
* |
| 21 |
* @since 3.8 |
| 22 |
* |
| 23 |
* @return int |
| 24 |
*/ |
| 25 |
public function get_id(): int; |
| 26 |
|
| 27 |
/** |
| 28 |
* Tells if the user is a translator (has a translator capability). |
| 29 |
* Note: returns `true` if the user has a capability for a language that doesn't exist anymore. This is intentional, |
| 30 |
* to prevent the user to suddenly have the rights to translate in all languages while it wasn't allowed until then. |
| 31 |
* |
| 32 |
* @since 3.8 |
| 33 |
* |
| 34 |
* @return bool |
| 35 |
*/ |
| 36 |
public function is_translator(): bool; |
| 37 |
|
| 38 |
/** |
| 39 |
* Tells if the user can translate to the given language. |
| 40 |
* |
| 41 |
* @since 3.8 |
| 42 |
* |
| 43 |
* @param PLL_Language $language A language object. |
| 44 |
* @return bool |
| 45 |
*/ |
| 46 |
public function can_translate( PLL_Language $language ): bool; |
| 47 |
|
| 48 |
/** |
| 49 |
* Tells if the user can translate to all the given languages. |
| 50 |
* |
| 51 |
* @since 3.8 |
| 52 |
* |
| 53 |
* @param array $languages List of language slugs. |
| 54 |
* @return bool |
| 55 |
* |
| 56 |
* @phpstan-param array<non-empty-string> $languages |
| 57 |
*/ |
| 58 |
public function can_translate_all( array $languages ): bool; |
| 59 |
|
| 60 |
/** |
| 61 |
* Tells if the user has the specified capability. |
| 62 |
* |
| 63 |
* @since 3.8 |
| 64 |
* |
| 65 |
* @param string $capability Capability name. |
| 66 |
* @param mixed ...$args Optional further parameters, typically starting with an object ID. |
| 67 |
* @return bool |
| 68 |
*/ |
| 69 |
public function has_cap( $capability, ...$args ): bool; |
| 70 |
|
| 71 |
/** |
| 72 |
* Returns the preferred language of the user. |
| 73 |
* |
| 74 |
* @since 3.8 |
| 75 |
* |
| 76 |
* @return string The preferred language slug, empty string if no preferred language is found. |
| 77 |
*/ |
| 78 |
public function get_preferred_language_slug(): string; |
| 79 |
|
| 80 |
/** |
| 81 |
* Checks if the current user has the rights to assign a language to an object and dies if not. |
| 82 |
* |
| 83 |
* @since 3.8 |
| 84 |
* |
| 85 |
* @param PLL_Language $language The language to assign. |
| 86 |
* @return void|never Dies if the user does not have the rights, does nothing otherwise. |
| 87 |
*/ |
| 88 |
public function can_translate_or_die( PLL_Language $language ): void; |
| 89 |
} |
| 90 |
|