PluginProbe
Polylang / 3.8.6
Polylang v3.8.6
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / src / Capabilities / User / NOOP.php

NOOP.php in Polylang 3.8.6, at src/Capabilities/User/NOOP.php

126 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * A NOOP user class that decorates `WP_User` and deactivates language-related methods.
13 * This class allows all translations but doesn't consider the user as a translator.
14 *
15 * @since 3.8
16 */
17 class NOOP implements User_Interface {
18 /**
19 * User instance to decorate.
20 *
21 * @var WP_User
22 */
23 private WP_User $user;
24
25 /**
26 * Constructor.
27 *
28 * @since 3.8
29 *
30 * @param WP_User $user An instance of `WP_User`.
31 */
32 public function __construct( WP_User $user ) {
33 $this->user = $user;
34 }
35
36 /**
37 * Returns the user ID.
38 *
39 * @since 3.8
40 *
41 * @return int
42 */
43 public function get_id(): int {
44 return $this->user->ID;
45 }
46
47 /**
48 * Tells if the user is a translator (has a translator capability).
49 * Always returns false for NOOP user.
50 *
51 * @since 3.8
52 *
53 * @return bool
54 */
55 public function is_translator(): bool {
56 return false;
57 }
58
59 /**
60 * Tells if the user can translate to the given language.
61 * Always returns true for NOOP user.
62 *
63 * @since 3.8
64 *
65 * @param PLL_Language $language A language object.
66 * @return bool
67 */
68 public function can_translate( PLL_Language $language ): bool { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
69 return true;
70 }
71
72 /**
73 * Tells if the user can translate to all the given languages.
74 * Always returns true for NOOP user.
75 *
76 * @since 3.8
77 *
78 * @param array $languages List of language slugs.
79 * @return bool
80 *
81 * @phpstan-param array<non-empty-string> $languages
82 */
83 public function can_translate_all( array $languages ): bool { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
84 return true;
85 }
86
87 /**
88 * Tells if the user has the specified capability.
89 * Delegates to WP_User.
90 *
91 * @since 3.8
92 *
93 * @param string $capability Capability name.
94 * @param mixed ...$args Optional further parameters, typically starting with an object ID.
95 * @return bool
96 */
97 public function has_cap( $capability, ...$args ): bool {
98 return $this->user->has_cap( $capability, ...$args );
99 }
100
101 /**
102 * Returns the preferred language of the user.
103 * Always returns an empty string for NOOP user.
104 *
105 * @since 3.8
106 *
107 * @return string The preferred language slug, empty string if no preferred language is found.
108 */
109 public function get_preferred_language_slug(): string {
110 return '';
111 }
112
113 /**
114 * Checks if the current user has the rights to assign a language to an object and dies if not.
115 * Does nothing for NOOP user (always allows).
116 *
117 * @since 3.8
118 *
119 * @param PLL_Language $language The language to assign.
120 * @return void|never Dies if the user does not have the rights, does nothing otherwise.
121 */
122 public function can_translate_or_die( PLL_Language $language ): void { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
123 // Never say die!
124 }
125 }
126