PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Wrapper/Wordpress.php +635 -543 trunk → 2.1.11 View file →
@@ -1,111 +1,44 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * Wordpress.php
4 + *
5 + * The Wordpress class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
5 15 namespace UserAccessManager\Wrapper;
6 16
7 -use JetBrains\PhpStorm\NoReturn;
8 -use WP_Error;
9 -use WP_Hook;
10 -use WP_Post;
11 -use WP_Post_Type;
12 -use WP_Query;
13 -use WP_Roles;
14 -use WP_Taxonomy;
15 -use WP_Term;
16 -use WP_User;
17 -use wpdb;
18 -use function add_action;
19 -use function add_filter;
20 -use function add_menu_page;
21 -use function add_meta_box;
22 -use function add_option;
23 -use function add_query_arg;
24 -use function add_shortcode;
25 -use function add_submenu_page;
26 -use function attachment_url_to_postid;
27 -use function current_time;
28 -use function current_user_can;
29 -use function date_i18n;
30 -use function dbDelta;
31 -use function delete_option;
32 -use function do_action;
33 -use function do_shortcode;
34 -use function esc_html;
35 -use function function_exists;
36 -use function get_allowed_mime_types;
37 -use function get_attached_file;
38 -use function get_bloginfo;
39 -use function get_home_path;
40 -use function get_option;
41 -use function get_page_by_path;
42 -use function get_page_link;
43 -use function get_pages;
44 -use function get_post;
45 -use function get_post_type_object;
46 -use function get_post_types;
47 -use function get_queried_object_id;
48 -use function get_sites;
49 -use function get_taxonomies;
50 -use function get_taxonomy;
51 -use function get_term;
52 -use function get_userdata;
53 -use function get_users;
54 -use function got_mod_rewrite;
55 -use function has_filter;
56 -use function home_url;
57 -use function is_admin;
58 -use function is_feed;
59 -use function is_multisite;
60 -use function is_page;
61 -use function is_post_type_hierarchical;
62 -use function is_single;
63 -use function is_super_admin;
64 -use function is_taxonomy_hierarchical;
65 -use function is_user_logged_in;
66 -use function plugin_basename;
67 -use function plugins_url;
68 -use function register_widget;
69 -use function remove_action;
70 -use function remove_filter;
71 -use function site_url;
72 -use function switch_to_blog;
73 -use function update_option;
74 -use function wp_attachment_is_image;
75 -use function wp_create_nonce;
76 -use function wp_die;
77 -use function wp_doing_ajax;
78 -use function wp_enqueue_script;
79 -use function wp_enqueue_style;
80 -use function wp_get_attachment_metadata;
81 -use function wp_get_current_user;
82 -use function wp_login_url;
83 -use function wp_logout_url;
84 -use function wp_lostpassword_url;
85 -use function wp_nonce_field;
86 -use function wp_parse_id_list;
87 -use function wp_redirect;
88 -use function wp_register_script;
89 -use function wp_register_style;
90 -use function wp_registration_url;
91 -use function wp_upload_dir;
92 -use function wp_verify_nonce;
93 -
17 +/**
18 + * Class Wordpress
19 + *
20 + * @package UserAccessManager\Wrapper
21 + */
94 22 class Wordpress
95 23 {
96 - public const REST_READING_METHODS = ['GET', 'HEAD'];
97 -
98 - private bool $restRequestDispatched = false;
99 - private bool $editingRestRequestDetected = false;
100 -
101 - public function getDatabase(): wpdb
24 + /**
25 + * Returns the database.
26 + *
27 + * @return \wpdb
28 + */
29 + public function getDatabase()
102 30 {
103 31 global $wpdb;
104 32 return $wpdb;
105 33 }
106 34
107 - public function isNginx(): bool
35 + /**
36 + * Returns true if web server is nginx.
37 + *
38 + * @return bool
39 + */
40 + public function isNginx()
108 41 {
109 42 global $is_nginx;
110 43 return $is_nginx;
111 44 }
@@ -110,126 +43,156 @@
110 43 return $is_nginx;
111 44 }
112 45
113 46 /**
114 - * @see wp_using_ext_object_cache
47 + * @see \is_post_type_hierarchical()
48 + *
49 + * @param string $postType
50 + *
51 + * @return bool
115 52 */
116 - public function isUsingExtObjectCache(): bool
53 + public function isPostTypeHierarchical($postType)
117 54 {
118 - return function_exists('wp_using_ext_object_cache') && wp_using_ext_object_cache() === true;
55 + return \is_post_type_hierarchical($postType);
119 56 }
120 57
121 58 /**
122 - * @see apache_get_modules
59 + * @see \is_taxonomy_hierarchical()
60 + *
61 + * @param string $taxonomy
62 + *
63 + * @return bool
123 64 */
124 - public function isApacheModuleLoaded(string $module): bool
65 + public function isTaxonomyHierarchical($taxonomy)
125 66 {
126 - return function_exists('apache_get_modules') && in_array($module, apache_get_modules(), true);
67 + return \is_taxonomy_hierarchical($taxonomy);
127 68 }
128 69
129 70 /**
130 - * @see is_post_type_hierarchical
71 + * @see \get_userdata()
72 + *
73 + * @param string $id
74 + *
75 + * @return false|\WP_User
131 76 */
132 - public function isPostTypeHierarchical(string $postType): bool
77 + public function getUserData($id)
133 78 {
134 - return is_post_type_hierarchical($postType);
79 + return \get_userdata($id);
135 80 }
136 81
137 82 /**
138 - * @see is_taxonomy_hierarchical
83 + * @see \get_post_types()
84 + *
85 + * @param string|array $arguments
86 + * @param string $output
87 + * @param string $operator
88 + *
89 + * @return array
139 90 */
140 - public function isTaxonomyHierarchical(string $taxonomy): bool
91 + public function getPostTypes($arguments = [], $output = 'names', $operator = 'and')
141 92 {
142 - return is_taxonomy_hierarchical($taxonomy);
93 + return \get_post_types($arguments, $output, $operator);
143 94 }
144 95
145 96 /**
146 - * @see get_userdata
97 + * @see \get_taxonomies()
98 + *
99 + * @param array $arguments
100 + * @param string $output
101 + * @param string $operator
102 + *
103 + * @return array
147 104 */
148 - public function getUserData(int|string|null $id): WP_User|bool
105 + public function getTaxonomies(array $arguments = [], $output = 'names', $operator = 'and')
149 106 {
150 - return get_userdata($id);
107 + return \get_taxonomies($arguments, $output, $operator);
151 108 }
152 109
153 110 /**
154 - * @see get_post_types
111 + * @see \get_taxonomy()
112 + *
113 + * @param string $taxonomy
114 + *
115 + * @return false|\WP_Taxonomy
155 116 */
156 - public function getPostTypes(
157 - array|string|int $arguments = [],
158 - string $output = 'names',
159 - string $operator = 'and'
160 - ): array {
161 - return get_post_types($arguments, $output, $operator);
117 + public function getTaxonomy($taxonomy)
118 + {
119 + return \get_taxonomy($taxonomy);
162 120 }
163 121
164 122 /**
165 - * @return string[]|WP_Taxonomy[]
166 - * @see get_taxonomies
123 + * @see \get_post()
124 + *
125 + * @param string $id The post id.
126 + * @param string $output
127 + * @param string $filter
128 + *
129 + * @return \WP_Post|array|null
167 130 */
168 - public function getTaxonomies(array $arguments = [], string $output = 'names', string $operator = 'and'): array
131 + public function getPost($id, $output = OBJECT, $filter = 'raw')
169 132 {
170 - return get_taxonomies($arguments, $output, $operator);
133 + return \get_post($id, $output, $filter);
171 134 }
172 135
173 136 /**
174 - * @see get_taxonomy
137 + * @see \get_post_type_object()
138 + *
139 + * @param string $postType
140 + *
141 + * @return null|\WP_Post_Type
175 142 */
176 - public function getTaxonomy(string $taxonomy): WP_Taxonomy|bool
143 + public function getPostTypeObject($postType)
177 144 {
178 - return get_taxonomy($taxonomy);
145 + return \get_post_type_object($postType);
179 146 }
180 147
181 148 /**
182 - * @see get_post
149 + * @see \get_term()
150 + *
151 + * @param string $id
152 + * @param string $taxonomy
153 + * @param string $output
154 + * @param string $filter
155 + *
156 + * @return array|null|\WP_Error|\WP_Term
183 157 */
184 - public function getPost(
185 - int|string|null $id,
186 - string $output = OBJECT,
187 - string $filter = 'raw'
188 - ): WP_Post|array|bool|null {
189 - return get_post($id, $output, $filter);
190 - }
191 -
192 - /**
193 - * @see get_post_type_object
194 - */
195 - public function getPostTypeObject(int|string $postType): ?WP_Post_Type
158 + public function getTerm($id, $taxonomy = '', $output = OBJECT, $filter = 'raw')
196 159 {
197 - return get_post_type_object($postType);
160 + return \get_term($id, $taxonomy, $output, $filter);
198 161 }
199 162
200 - /**
201 - * @see get_term
202 - */
203 - public function getTerm(
204 - int|string $id,
205 - string $taxonomy = '',
206 - string $output = OBJECT,
207 - string $filter = 'raw'
208 - ): WP_Term|WP_Error|array|bool|null {
209 - return get_term($id, $taxonomy, $output, $filter);
210 - }
211 163
212 -
213 164 /**
214 - * @see dbDelta
165 + * @see \dbDelta()
166 + *
167 + * @param array|string $queries
168 + * @param bool $execute
169 + *
170 + * @return array
215 171 */
216 - public function dbDelta(array|string $queries = '', bool $execute = true): array
172 + public function dbDelta($queries = '', $execute = true)
217 173 {
218 - if (function_exists('\dbDelta') === false) {
219 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
174 + if (\function_exists('\dbDelta') === false) {
175 + /**
176 + * @noinspection PhpIncludeInspection
177 + */
178 + require_once(ABSPATH.'wp-admin/includes/upgrade.php');
220 179 }
221 180
222 - return dbDelta($queries, $execute);
181 + return \dbDelta($queries, $execute);
223 182 }
224 183
225 184 /**
226 - * @see switch_to_blog
185 + * @see \switch_to_blog()
186 + *
187 + * @param integer $blogId
188 + *
189 + * @return int|true
227 190 */
228 - public function switchToBlog(int|string|null $blogId): bool
191 + public function switchToBlog($blogId)
229 192 {
230 193 if (function_exists('\switch_to_blog') === true) {
231 - return (bool) switch_to_blog($blogId);
194 + return \switch_to_blog($blogId);
232 195 }
233 196
234 197 return true;
235 198 }
@@ -235,10 +198,12 @@
235 198 }
236 199
237 200 /**
238 201 * @see \restore_current_blog()
202 + *
203 + * @return bool
239 204 */
240 - public function restoreCurrentBlog(): bool
205 + public function restoreCurrentBlog()
241 206 {
242 207 if (function_exists('\restore_current_blog') === true) {
243 208 return restore_current_blog();
244 209 }
@@ -246,479 +211,551 @@
246 211 return true;
247 212 }
248 213
249 214 /**
250 - * @see is_multisite
215 + * @see \is_multisite()
216 + *
217 + * @return bool
251 218 */
252 - public function isMultiSite(): bool
219 + public function isMultiSite()
253 220 {
254 - return is_multisite();
221 + return \is_multisite();
255 222 }
256 223
257 224 /**
258 - * @see do_action
225 + * @see \do_action()
226 + *
227 + * @param string $tag
228 + * @param mixed $arguments
259 229 */
260 - public function doAction(string $tag, mixed $arguments = ''): void
230 + public function doAction($tag, $arguments = '')
261 231 {
262 - do_action($tag, $arguments);
232 + \do_action($tag, $arguments);
263 233 }
264 234
265 235 /**
266 - * @see add_action
236 + * @see \add_action()
237 + *
238 + * @param string $tag
239 + * @param callable $functionToAdd
240 + * @param int $priority
241 + * @param int $acceptedArguments
242 + *
243 + * @return true
267 244 */
268 - public function addAction(
269 - string $tag,
270 - callable $functionToAdd,
271 - int $priority = 10,
272 - int $acceptedArguments = 1
273 - ): bool {
274 - return add_action($tag, $functionToAdd, $priority, $acceptedArguments);
275 - }
276 -
277 - /**
278 - * @see remove_action
279 - */
280 - public function removeAction(string $hookName, callable $callback, int $priority = 10): bool
245 + public function addAction($tag, $functionToAdd, $priority = 10, $acceptedArguments = 1)
281 246 {
282 - return remove_action($hookName, $callback, $priority);
247 + return \add_action($tag, $functionToAdd, $priority, $acceptedArguments);
283 248 }
284 249
285 250 /**
286 - * @see has_filter
251 + * @see \has_filter()
252 + *
253 + * @param string $tag
254 + * @param bool|callable $functionToCheck
255 + *
256 + * @return bool|false|int
287 257 */
288 - public function hasFilter(string $tag, callable|bool $functionToCheck = false): bool|int
258 + public function hasFilter($tag, $functionToCheck = false)
289 259 {
290 - return has_filter($tag, $functionToCheck);
260 + return \has_filter($tag, $functionToCheck);
291 261 }
292 262
293 263 /**
294 - * @see add_filter
264 + * @see \add_filter()
265 + *
266 + * @param string $tag
267 + * @param callable $functionToAdd
268 + * @param int $priority
269 + * @param int $acceptedArguments
270 + *
271 + * @return true
295 272 */
296 - public function addFilter(
297 - string $tag,
298 - callable $functionToAdd,
299 - int $priority = 10,
300 - int $acceptedArguments = 1
301 - ): bool {
302 - return add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
303 - }
304 -
305 - /**
306 - * @see WP_Error
307 - */
308 - public function getWpError(string|int $code = '', string $message = '', mixed $data = ''): WP_Error
273 + public function addFilter($tag, $functionToAdd, $priority = 10, $acceptedArguments = 1)
309 274 {
310 - return new WP_Error($code, $message, $data);
275 + return \add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
311 276 }
312 277
313 278 /**
314 - * @see remove_filter
279 + * @see \remove_filter()
280 + *
281 + * @param string $tag
282 + * @param callable $functionToRemove
283 + * @param int $priority
284 + *
285 + * @return bool
315 286 */
316 - public function removeFilter(string $tag, callable $functionToRemove, int $priority = 10): bool
287 + public function removeFilter($tag, $functionToRemove, $priority = 10)
317 288 {
318 - return remove_filter($tag, $functionToRemove, $priority);
289 + return \remove_filter($tag, $functionToRemove, $priority);
319 290 }
320 291
321 292 /**
322 - * @see add_option
293 + * @see \add_option()
294 + *
295 + * @param string $option
296 + * @param mixed $value
297 + * @param string $deprecated
298 + * @param string|bool $autoload
299 + *
300 + * @return bool
323 301 */
324 - public function addOption(
325 - string $option,
326 - mixed $value = '',
327 - string $deprecated = '',
328 - bool|string $autoload = 'yes'
329 - ): bool {
330 - return add_option($option, $value, $deprecated, $autoload);
331 - }
332 -
333 - /**
334 - * @see delete_option
335 - */
336 - public function deleteOption(string $option): bool
302 + public function addOption($option, $value = '', $deprecated = '', $autoload = 'yes')
337 303 {
338 - return delete_option($option);
304 + return \add_option($option, $value, $deprecated, $autoload);
339 305 }
340 306
341 307 /**
342 - * @see update_option
308 + * @see \delete_option()
309 + *
310 + * @param string $option
311 + *
312 + * @return bool
343 313 */
344 - public function updateOption(string $option, mixed $value = '', bool|string $autoload = 'yes'): bool
314 + public function deleteOption($option)
345 315 {
346 - return update_option($option, $value, $autoload);
316 + return \delete_option($option);
347 317 }
348 318
349 319 /**
350 - * @see get_option
320 + * @see \update_option()
321 + *
322 + * @param string $option
323 + * @param mixed $value
324 + * @param string|bool $autoload
325 + *
326 + * @return bool
351 327 */
352 - public function getOption(string $option, mixed $default = false)
328 + public function updateOption($option, $value = '', $autoload = 'yes')
353 329 {
354 - return get_option($option, $default);
330 + return \update_option($option, $value, $autoload);
355 331 }
356 332
357 333 /**
358 - * @see wp_cache_set
334 + * @see \get_option()
335 + *
336 + * @param string $option
337 + * @param mixed $default
338 + *
339 + * @return mixed
359 340 */
360 - public function wpCacheSet(string $key, mixed $data, string $group = '', int $expire = 0): bool
341 + public function getOption($option, $default = false)
361 342 {
362 - return wp_cache_set($key, $data, $group, $expire);
343 + return \get_option($option, $default);
363 344 }
364 345
365 346 /**
366 - * @see wp_cache_get
347 + * @see \is_super_admin()
348 + *
349 + * @param int|bool $userId
350 + *
351 + * @return bool
367 352 */
368 - public function wpCacheGet(string $key, string $group = ''): mixed
353 + public function isSuperAdmin($userId = false)
369 354 {
370 - return wp_cache_get($key, $group);
355 + return \is_super_admin($userId);
371 356 }
372 357
373 358 /**
374 - * @see wp_cache_delete
359 + * @see \wp_get_current_user()
360 + *
361 + * @return \WP_User
375 362 */
376 - public function wpCacheDelete(string $key, string $group = ''): bool
363 + public function getCurrentUser()
377 364 {
378 - return wp_cache_delete($key, $group);
379 - }
380 -
381 - /**
382 - * @see is_super_admin
383 - */
384 - public function isSuperAdmin(bool|int|string|null $userId = false): bool
385 - {
386 - return is_super_admin($userId);
387 - }
388 -
389 - /**
390 - * @see wp_get_current_user
391 - */
392 - public function getCurrentUser(): WP_User
393 - {
394 365 if (function_exists('\wp_get_current_user') === false) {
395 - require_once(ABSPATH . 'wp-includes/pluggable.php');
366 + require_once(ABSPATH.'wp-includes/pluggable.php');
396 367 }
397 368
398 - return wp_get_current_user();
369 + return \wp_get_current_user();
399 370 }
400 371
401 372 /**
402 - * @see get_allowed_mime_types
373 + * @see \get_allowed_mime_types()
374 + *
375 + * @param int|\WP_User $user
376 + *
377 + * @return array
403 378 */
404 - public function getAllowedMimeTypes(WP_User|int|string|null $user = null): array
379 + public function getAllowedMimeTypes($user = null)
405 380 {
406 - return get_allowed_mime_types($user);
381 + return \get_allowed_mime_types($user);
407 382 }
408 383
409 384 /**
410 - * @see wp_upload_dir
385 + * @see \wp_upload_dir()
386 + *
387 + * @param string $time
388 + * @param bool $createDir
389 + * @param bool $refreshCache
390 + *
391 + * @return array
411 392 */
412 - public function getUploadDir(?string $time = null, bool $createDir = true, bool $refreshCache = false): array
393 + public function getUploadDir($time = null, $createDir = true, $refreshCache = false)
413 394 {
414 - return wp_upload_dir($time, $createDir, $refreshCache);
395 + return \wp_upload_dir($time, $createDir, $refreshCache);
415 396 }
416 397
417 398 /**
418 - * @see home_url
399 + * @see \home_url()
400 + *
401 + * @param string $path
402 + * @param null|string $scheme
403 + *
404 + * @return string
419 405 */
420 - public function getHomeUrl(string $path = '', ?string $scheme = null): string
406 + public function getHomeUrl($path = '', $scheme = null)
421 407 {
422 - return home_url($path, $scheme);
408 + return \home_url($path, $scheme);
423 409 }
424 410
425 411 /**
426 - * @see site_url
412 + * @see \site_url();
413 + *
414 + * @param string $path
415 + * @param null|string $scheme
416 + *
417 + * @return string
427 418 */
428 - public function getSiteUrl(string $path = '', ?string $scheme = null): string
419 + public function getSiteUrl($path = '', $scheme = null)
429 420 {
430 - return site_url($path, $scheme);
421 + return \site_url($path, $scheme);
431 422 }
432 423
433 424 /**
434 - * @see add_query_arg
425 + * @see \get_home_path()
426 + *
427 + * @return string
435 428 */
436 - public function addQueryArg(array $arguments, string $url): string
429 + public function getHomePath()
437 430 {
438 - return add_query_arg($arguments, $url);
439 - }
440 -
441 - /**
442 - * @see get_home_path
443 - */
444 - public function getHomePath(): string
445 - {
446 431 if (function_exists('\get_home_path') === false) {
447 - require_once(ABSPATH . 'wp-admin/includes/file.php');
432 + require_once(ABSPATH.'wp-admin/includes/file.php');
448 433 }
449 434
450 - return get_home_path();
435 + return \get_home_path();
451 436 }
452 437
453 438 /**
454 - * @see wp_parse_id_list
439 + * @see \wp_parse_id_list()
440 + *
441 + * @param array|string $list
442 + *
443 + * @return array
455 444 */
456 - public function parseIdList(array|string|int $list): array
445 + public function parseIdList($list)
457 446 {
458 - return wp_parse_id_list($list);
447 + return \wp_parse_id_list($list);
459 448 }
460 449
461 450 /**
462 - * @see wp_die
451 + * @see \wp_die()
452 + *
453 + * @param string $message
454 + * @param string $title
455 + * @param array $arguments
463 456 */
464 - #[NoReturn]
465 - public function wpDie(string $message = '', string $title = '', array $arguments = []): void
457 + public function wpDie($message = '', $title = '', array $arguments = [])
466 458 {
467 - wp_die($message, $title, $arguments);
459 + \wp_die($message, $title, $arguments);
468 460 }
469 461
470 462 /**
471 - * @see is_feed
463 + * @see \is_feed()
464 + *
465 + * @param string|array $feeds
466 + *
467 + * @return bool
472 468 */
473 - public function isFeed(array|string|int $feeds = ''): bool
469 + public function isFeed($feeds = '')
474 470 {
475 - return is_feed($feeds);
471 + return \is_feed($feeds);
476 472 }
477 473
478 474 /**
479 - * @see is_user_logged_in
475 + * @see \is_user_logged_in()
476 + *
477 + * @return bool
480 478 */
481 - public function isUserLoggedIn(): bool
479 + public function isUserLoggedIn()
482 480 {
483 - return is_user_logged_in();
481 + return \is_user_logged_in();
484 482 }
485 483
486 484 /**
487 - * @see get_page_by_path
485 + * @see \get_page_by_path()
486 + *
487 + * @param string $pagePath
488 + * @param string $output
489 + * @param string $postType
490 + *
491 + * @return array|null|\WP_Post
488 492 */
489 - public function getPageByPath(
490 - string $pagePath,
491 - string $output = OBJECT,
492 - string $postType = 'page'
493 - ): array|WP_Post|null {
494 - return get_page_by_path($pagePath, $output, $postType);
493 + public function getPageByPath($pagePath, $output = OBJECT, $postType = 'page')
494 + {
495 + return \get_page_by_path($pagePath, $output, $postType);
495 496 }
496 497
497 498 /**
498 - * @see wp_redirect
499 + * @see \wp_redirect()
500 + *
501 + * @param string $location
502 + * @param int $status
503 + *
504 + * @return bool
499 505 */
500 - public function wpRedirect(string $location, int $status = 302): bool
506 + public function wpRedirect($location, $status = 302)
501 507 {
502 - return wp_redirect($location, $status);
508 + return \wp_redirect($location, $status);
503 509 }
504 510
505 511 /**
506 - * @see wp_get_referer
512 + * @param bool|int|\WP_Post $post
513 + * @param bool $leaveName
514 + * @param bool $sample
515 + *
516 + * @return string The page permalink.
507 517 */
508 - public function getReferer(): string|false
518 + public function getPageLink($post = false, $leaveName = false, $sample = false)
509 519 {
510 - return wp_get_referer();
520 + return \get_page_link($post, $leaveName, $sample);
511 521 }
512 522
513 - public function getPageLink(
514 - bool|int|string|WP_Post $post = false,
515 - bool $leaveName = false,
516 - bool $sample = false
517 - ): string {
518 - return get_page_link($post, $leaveName, $sample);
519 - }
520 -
521 - public function getWpQuery(): WP_Query
523 + /**
524 + * Returns the wp_query object.
525 + *
526 + * @return \WP_Query
527 + */
528 + public function getWpQuery()
522 529 {
523 530 global $wp_query;
524 531 return $wp_query;
525 532 }
526 533
527 - public function isRestRequest(): bool
534 + /**
535 + * @see \is_admin()
536 + *
537 + * @return bool
538 + */
539 + public function isAdmin()
528 540 {
529 - return defined('REST_REQUEST') === true && REST_REQUEST === true;
530 - }
531 -
532 - public function setRestRequestContext(bool $isEditingRequest): void
533 - {
534 - $this->restRequestDispatched = true;
535 - //Nested requests, like the ones for embedded objects, must not lower the context again.
536 - $this->editingRestRequestDetected = $this->editingRestRequestDetected || $isEditingRequest;
537 - }
538 -
539 - private function isReadingRestMethod(string $method): bool
540 - {
541 - return in_array(strtoupper($method), self::REST_READING_METHODS, true);
542 - }
543 -
544 - private function isEditingRestRequest(): bool
545 - {
546 - if ($this->isRestRequest() === false) {
547 - return false;
541 + //Ajax request are always identified as administrative interface page
542 + if (\wp_doing_ajax() === true) {
543 + //So let's check if we are calling the ajax data for the frontend or backend
544 + //If the referer is an admin url we are requesting the data for the backend
545 + $adminUrl = get_admin_url();
546 + return (substr($_SERVER['HTTP_REFERER'], 0, strlen($adminUrl)) === $adminUrl);
548 547 }
549 548
550 - if ($this->restRequestDispatched === true) {
551 - return $this->editingRestRequestDetected;
552 - }
553 -
554 - //Undispatched requests only expose the raw data, so an editing request is assumed.
555 - return $this->isReadingRestMethod((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET')) === false
556 - || ($_REQUEST['context'] ?? '') === 'edit';
549 + //No ajax request just use the normal function
550 + return \is_admin();
557 551 }
558 552
559 553 /**
560 - * @see is_admin
554 + * @see \wp_create_nonce()
555 + *
556 + * @param int|string $action
557 + *
558 + * @return string
561 559 */
562 - public function isAdmin(): bool
560 + public function createNonce($action)
563 561 {
564 - if ($this->isRestRequest() === true) {
565 - return $this->isEditingRestRequest();
566 - }
567 -
568 - if (wp_doing_ajax() === true) {
569 - return is_user_logged_in() === true
570 - && str_starts_with((string)($_SERVER['HTTP_REFERER'] ?? ''), get_admin_url());
571 - }
572 -
573 - return is_admin();
562 + return \wp_create_nonce($action);
574 563 }
575 564
576 565 /**
577 - * @see wp_create_nonce
566 + * @see \wp_nonce_field()
567 + *
568 + * @param int|string $action
569 + * @param string $name
570 + * @param bool $referrer
571 + * @param bool $echo
572 + *
573 + * @return string
578 574 */
579 - public function createNonce(int|string $action): string
575 + public function getNonceField($action = -1, $name = '_wpnonce', $referrer = true, $echo = true)
580 576 {
581 - return wp_create_nonce($action);
577 + return \wp_nonce_field($action, $name, $referrer, $echo);
582 578 }
583 579
584 580 /**
585 - * @see wp_nonce_field
581 + * @see \wp_verify_nonce()
582 + *
583 + * @param string $nonce
584 + * @param string|int $action
585 + *
586 + * @return false|int
586 587 */
587 - public function getNonceField(
588 - int|string $action = -1,
589 - string $name = '_wpnonce',
590 - bool $referrer = true,
591 - bool $echo = true
592 - ): string {
593 - return wp_nonce_field($action, $name, $referrer, $echo);
588 + public function verifyNonce($nonce, $action = -1)
589 + {
590 + return \wp_verify_nonce($nonce, $action);
594 591 }
595 592
596 593 /**
597 - * @see wp_verify_nonce
594 + * Returns the wordpress roles.
595 + *
596 + * @return \WP_Roles
598 597 */
599 - public function verifyNonce(?string $nonce, int|string $action = -1): bool|int
598 + public function getRoles()
600 599 {
601 - return wp_verify_nonce($nonce, $action);
602 - }
603 -
604 - public function getRoles(): WP_Roles
605 - {
606 600 global $wp_roles;
607 601 return $wp_roles;
608 602 }
609 603
610 604 /**
611 - * @see add_menu_page
605 + * @see \add_menu_page()
606 + *
607 + * @param string $pageTitle
608 + * @param string $menuTitle
609 + * @param string $capability
610 + * @param string $menuSlug
611 + * @param mixed $function
612 + * @param string $iconUrl
613 + * @param null $position
614 + *
615 + * @return string
612 616 */
613 617 public function addMenuPage(
614 - string $pageTitle,
615 - string $menuTitle,
616 - string $capability,
617 - string $menuSlug,
618 - mixed $function = '',
619 - string $iconUrl = '',
620 - int|float|null $position = null
621 - ): string {
622 - return add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $function, $iconUrl, $position);
618 + $pageTitle,
619 + $menuTitle,
620 + $capability,
621 + $menuSlug,
622 + $function = '',
623 + $iconUrl = '',
624 + $position = null
625 + ) {
626 + return \add_menu_page($pageTitle, $menuTitle, $capability, $menuSlug, $function, $iconUrl, $position);
623 627 }
624 628
625 629 /**
626 - * @see add_submenu_page
630 + * @see \add_submenu_page()
631 + *
632 + * @param string $parentSlug
633 + * @param string $pageTitle
634 + * @param string $menuTitle
635 + * @param string $capability
636 + * @param string $menuSlug
637 + * @param string|callable $function
638 + *
639 + * @return false|string
627 640 */
628 - public function addSubMenuPage(
629 - string $parentSlug,
630 - string $pageTitle,
631 - string $menuTitle,
632 - string $capability,
633 - string $menuSlug,
634 - callable|string $function = ''
635 - ): bool|string {
636 - return add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function);
641 + public function addSubMenuPage($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function = '')
642 + {
643 + return \add_submenu_page($parentSlug, $pageTitle, $menuTitle, $capability, $menuSlug, $function);
637 644 }
638 645
639 646 /**
640 - * @see add_meta_box
647 + * @see \add_meta_box()
648 + *
649 + * @param string $id
650 + * @param string $title
651 + * @param callable $callback
652 + * @param string|array|\WP_Screen $screen
653 + * @param string $context
654 + * @param string $priority
655 + * @param array $callbackArguments
641 656 */
642 657 public function addMetaBox(
643 - string $id,
644 - string $title,
645 - callable $callback,
658 + $id,
659 + $title,
660 + $callback,
646 661 $screen = null,
647 - string $context = 'advanced',
648 - string $priority = 'default',
662 + $context = 'advanced',
663 + $priority = 'default',
649 664 $callbackArguments = null
650 - ): void {
651 - add_meta_box($id, $title, $callback, $screen, $context, $priority, $callbackArguments);
665 + ) {
666 + \add_meta_box($id, $title, $callback, $screen, $context, $priority, $callbackArguments);
652 667 }
653 668
654 669 /**
655 - * @see get_pages
670 + * @see \get_pages()
671 + *
672 + * @param array|string $arguments
673 + *
674 + * @return array|false
656 675 */
657 - public function getPages(array|string|int $arguments): bool|array
676 + public function getPages($arguments)
658 677 {
659 - return get_pages($arguments);
678 + return \get_pages($arguments);
660 679 }
661 680
662 681 /**
663 - * @see wp_register_style
682 + * @see \wp_register_style()
683 + *
684 + * @param string $handle
685 + * @param string $source
686 + * @param array $depends
687 + * @param string|bool|null $version
688 + * @param string $media
689 + *
690 + * @return bool
664 691 */
665 - public function registerStyle(
666 - string $handle,
667 - string $source,
668 - array $depends = [],
669 - bool|string|null $version = false,
670 - string $media = 'all'
671 - ): bool {
672 - return wp_register_style($handle, $source, $depends, $version, $media);
692 + public function registerStyle($handle, $source, $depends = [], $version = false, $media = 'all')
693 + {
694 + return \wp_register_style($handle, $source, $depends, $version, $media);
673 695 }
674 696
675 697 /**
676 - * @see wp_register_script
698 + * @see \wp_register_script()
699 + *
700 + * @param string $handle
701 + * @param string $source
702 + * @param array $depends
703 + * @param string|bool|null $version
704 + * @param bool $inFooter
705 + *
706 + * @return bool
677 707 */
678 - public function registerScript(
679 - string $handle,
680 - string $source,
681 - array $depends = [],
682 - bool|string|null $version = false,
683 - bool $inFooter = false
684 - ): bool {
685 - return wp_register_script($handle, $source, $depends, $version, $inFooter);
708 + public function registerScript($handle, $source, $depends = [], $version = false, $inFooter = false)
709 + {
710 + return \wp_register_script($handle, $source, $depends, $version, $inFooter);
686 711 }
687 712
688 713 /**
689 - * @see wp_enqueue_style
714 + * @see \wp_enqueue_style()
715 + *
716 + * @param string $handle
717 + * @param string $source
718 + * @param array $depends
719 + * @param string|bool|null $version
720 + * @param string $media
690 721 */
691 - public function enqueueStyle(
692 - string $handle,
693 - string $source = '',
694 - array $depends = [],
695 - bool|string|null $version = false,
696 - string $media = 'all'
697 - ): void {
698 - wp_enqueue_style($handle, $source, $depends, $version, $media);
722 + public function enqueueStyle($handle, $source = '', $depends = [], $version = false, $media = 'all')
723 + {
724 + \wp_enqueue_style($handle, $source, $depends, $version, $media);
699 725 }
700 726
701 727 /**
702 - * @see wp_enqueue_script
728 + * @see \wp_enqueue_script()
729 + *
730 + * @param string $handle
731 + * @param string $source
732 + * @param array $depends
733 + * @param string|bool|null $version
734 + * @param bool $inFooter
703 735 */
704 - public function enqueueScript(
705 - string $handle,
706 - string $source = '',
707 - array $depends = [],
708 - bool|string|null $version = false,
709 - bool $inFooter = false
710 - ): void {
711 - wp_enqueue_script($handle, $source, $depends, $version, $inFooter);
736 + public function enqueueScript($handle, $source = '', $depends = [], $version = false, $inFooter = false)
737 + {
738 + \wp_enqueue_script($handle, $source, $depends, $version, $inFooter);
712 739 }
713 740
714 - public function getMetaBoxes(): array
741 + /**
742 + * Returns the wordpress meta boxes.
743 + *
744 + * @return array
745 + */
746 + public function getMetaBoxes()
715 747 {
716 748 global $wp_meta_boxes;
717 749 return $wp_meta_boxes;
718 750 }
719 751
720 - public function setMetaBoxes(array $wpMetaBoxes): void
752 + /**
753 + * Sets the wordpress meta boxes.
754 + *
755 + * @param array $wpMetaBoxes
756 + */
757 + public function setMetaBoxes(array $wpMetaBoxes)
721 758 {
722 759 global $wp_meta_boxes;
723 760 $wp_meta_boxes = $wpMetaBoxes;
724 761 }
@@ -723,14 +760,18 @@
723 760 $wp_meta_boxes = $wpMetaBoxes;
724 761 }
725 762
726 763 /**
727 - * @see get_sites
764 + * @see \get_sites()
765 + *
766 + * @param array $arguments
767 + *
768 + * @return array
728 769 */
729 - public function getSites(array $arguments = []): array
770 + public function getSites(array $arguments = [])
730 771 {
731 772 if (function_exists('\get_sites') === true && class_exists('\WP_Site_Query') === true) {
732 - return get_sites($arguments);
773 + return \get_sites($arguments);
733 774 }
734 775
735 776 return [];
736 777 }
@@ -735,236 +776,287 @@
735 776 return [];
736 777 }
737 778
738 779 /**
739 - * @see apply_filters()
780 + * @see \apply_filters()
781 + *
782 + * @param string $tag
783 + * @param mixed $value
784 + *
785 + * @return mixed
740 786 */
741 - public function applyFilters(string $tag, mixed $value): mixed
787 + public function applyFilters($tag, $value)
742 788 {
743 789 return call_user_func_array('\apply_filters', func_get_args());
744 790 }
745 791
746 792 /**
747 - * @see get_bloginfo
793 + * @see \get_bloginfo()
794 + *
795 + * @param string $show
796 + * @param string $filter
797 + *
798 + * @return string
748 799 */
749 - public function getBlogInfo(string $show = '', string $filter = 'raw'): string
800 + public function getBlogInfo($show = '', $filter = 'raw')
750 801 {
751 - return get_bloginfo($show, $filter);
802 + return \get_bloginfo($show, $filter);
752 803 }
753 804
754 805 /**
755 - * @see esc_html
806 + * @see \esc_html()
807 + *
808 + * @param string $text
809 + *
810 + * @return string
756 811 */
757 - public function escHtml(string $text): string
812 + public function escHtml($text)
758 813 {
759 - return esc_html($text);
814 + return \esc_html($text);
760 815 }
761 816
762 817 /**
763 - * @see is_single
818 + * @see \is_single()
819 + *
820 + * @param int|string|array $post
821 + *
822 + * @return bool
764 823 */
765 - public function isSingle(array|string|int $post = ''): bool
824 + public function isSingle($post = '')
766 825 {
767 - return is_single($post);
826 + return \is_single($post);
768 827 }
769 828
770 829 /**
771 - * @see is_page
830 + * @see \is_page()
831 + *
832 + * @param int|string|array $page
833 + *
834 + * @return bool
772 835 */
773 - public function isPage(array|string|int $page = ''): bool
836 + public function isPage($page = '')
774 837 {
775 - return is_page($page);
838 + return \is_page($page);
776 839 }
777 840
778 841 /**
779 842 * @see \WP_PLUGIN_DIR
843 + *
844 + * @return string
780 845 */
781 - public function getPluginDir(): string
846 + public function getPluginDir()
782 847 {
783 848 return WP_PLUGIN_DIR;
784 849 }
785 850
786 851 /**
787 - * @see plugins_url
852 + * @see \plugins_url()
853 + *
854 + * @param string $path
855 + * @param string $plugin
856 + *
857 + * @return string
788 858 */
789 - public function pluginsUrl(string $path = '', string $plugin = ''): string
859 + public function pluginsUrl($path = '', $plugin = '')
790 860 {
791 - return plugins_url($path, $plugin);
861 + return \plugins_url($path, $plugin);
792 862 }
793 863
794 864 /**
795 - * @see plugin_basename
865 + * @see \plugin_basename()
866 + *
867 + * @param $file
868 + *
869 + * @return string
796 870 */
797 - public function pluginBasename(string $file): string
871 + public function pluginBasename($file)
798 872 {
799 - return plugin_basename($file);
873 + return \plugin_basename($file);
800 874 }
801 875
802 876 /**
803 - * @see wp_attachment_is_image
877 + * @see \wp_attachment_is_image()
878 + *
879 + * @param int|\WP_Post $post
880 + *
881 + * @return bool
804 882 */
805 - public function attachmentIsImage(int|WP_Post $post): bool
883 + public function attachmentIsImage($post)
806 884 {
807 - return wp_attachment_is_image($post);
885 + return \wp_attachment_is_image($post);
808 886 }
809 887
810 888 /**
811 - * @see get_attached_file
889 + * @see \current_user_can()
890 + *
891 + * @param string $capability
892 + *
893 + * @return bool
812 894 */
813 - public function getAttachedFile(int $attachmentId, bool $unfiltered = false): string|false
895 + public function currentUserCan($capability)
814 896 {
815 - return get_attached_file($attachmentId, $unfiltered);
897 + return \current_user_can($capability);
816 898 }
817 899
818 900 /**
819 - * The return value passes the wp_get_attachment_metadata filter, so any type can reach us.
901 + * @see \get_users()
820 902 *
821 - * @see wp_get_attachment_metadata
903 + * @param array $arguments
904 + *
905 + * @return array
822 906 */
823 - public function getAttachmentMetadata(int $attachmentId): mixed
907 + public function getUsers(array $arguments = [])
824 908 {
825 - return wp_get_attachment_metadata($attachmentId);
909 + return \get_users($arguments);
826 910 }
827 911
828 912 /**
829 - * @see current_user_can
913 + * @return \WP_Hook[]
830 914 */
831 - public function currentUserCan(string $capability): bool
915 + public function getFilters()
832 916 {
833 - return current_user_can($capability);
917 + global $wp_filter;
918 + return $wp_filter;
834 919 }
835 920
836 921 /**
837 - * @see get_users
922 + * @param array $filters
838 923 */
839 - public function getUsers(array $arguments = []): array
924 + public function setFilters(array $filters)
840 925 {
841 - return get_users($arguments);
926 + global $wp_filter;
927 + $wp_filter = $filters;
842 928 }
843 929
844 930 /**
845 - * @return WP_Hook[]
931 + * @see \current_time()
932 + *
933 + * @param string $type
934 + * @param int $gmt
935 + *
936 + * @return int|string
846 937 */
847 - public function getFilters(): array
938 + public function currentTime($type, $gmt = 0)
848 939 {
849 - global $wp_filter;
850 - return $wp_filter;
940 + return \current_time($type, $gmt);
851 941 }
852 942
853 - public function setFilters(array $filters): void
854 - {
855 - global $wp_filter;
856 - $wp_filter = $filters;
857 - }
858 -
859 943 /**
860 - * @see current_time
944 + * Formats the date like wordpress does it.
945 + *
946 + * @param string $date
947 + *
948 + * @return string
861 949 */
862 - public function currentTime(string $type, int $gmt = 0): int|string
950 + public function formatDate($date)
863 951 {
864 - return current_time($type, $gmt);
865 - }
866 -
867 - public function formatDate(string $date): string
868 - {
869 952 $dateFormat = __('M j, Y @ H:i');
870 - return date_i18n($dateFormat, strtotime($date));
953 + return \date_i18n($dateFormat, strtotime($date));
871 954 }
872 955
873 956 /**
874 - * @see register_widget
957 + * @see \register_widget()
958 + *
959 + * @param mixed $widgetClass
875 960 */
876 - public function registerWidget(mixed $widgetClass): void
961 + public function registerWidget($widgetClass)
877 962 {
878 - register_widget($widgetClass);
963 + \register_widget($widgetClass);
879 964 }
880 965
881 966 /**
882 - * @see wp_login_url
967 + * @see \wp_login_url()
968 + *
969 + * @param string $redirect
970 + * @param bool $forceReauth
971 + *
972 + * @return string
883 973 */
884 - public function wpLoginUrl(string $redirect = '', bool $forceReauth = false): string
974 + public function wpLoginUrl($redirect = '', $forceReauth = false)
885 975 {
886 - return wp_login_url($redirect, $forceReauth);
976 + return \wp_login_url($redirect, $forceReauth);
887 977 }
888 978
889 979 /**
890 - * @see wp_logout_url
980 + * @see \wp_logout_url()
981 + *
982 + * @param string $redirect
983 + *
984 + * @return string
891 985 */
892 - public function wpLogoutUrl(string $redirect = ''): string
986 + public function wpLogoutUrl($redirect = '')
893 987 {
894 - return wp_logout_url($redirect);
988 + return \wp_logout_url($redirect);
895 989 }
896 990
897 991 /**
898 - * @see wp_registration_url
992 + * @see \wp_registration_url()
993 + *
994 + * @return string
899 995 */
900 - public function wpRegistrationUrl(): string
996 + public function wpRegistrationUrl()
901 997 {
902 - return wp_registration_url();
998 + return \wp_registration_url();
903 999 }
904 1000
905 1001 /**
906 - * @see wp_lostpassword_url
1002 + * @see \wp_lostpassword_url()
1003 + *
1004 + * @param string $redirect
1005 + *
1006 + * @return string
907 1007 */
908 - public function wpLostPasswordUrl(string $redirect = ''): string
1008 + public function wpLostPasswordUrl($redirect = '')
909 1009 {
910 - return wp_lostpassword_url($redirect);
1010 + return \wp_lostpassword_url($redirect);
911 1011 }
912 1012
913 1013 /**
914 - * @see add_shortcode
1014 + * @see \add_shortcode()
1015 + *
1016 + * @param string $tag
1017 + * @param callable $function
915 1018 */
916 - public function addShortCode(string $tag, callable $function): void
1019 + public function addShortCode($tag, $function)
917 1020 {
918 - add_shortcode($tag, $function);
1021 + \add_shortcode($tag, $function);
919 1022 }
920 1023
921 1024 /**
922 - * @see do_shortcode
1025 + * @see \do_shortcode()
1026 + *
1027 + * @param string $content
1028 + * @param bool $ignoreHtml
1029 + *
1030 + * @return string
923 1031 */
924 - public function doShortCode(string $content, bool $ignoreHtml = false): string
1032 + public function doShortCode($content, $ignoreHtml = false)
925 1033 {
926 - return do_shortcode($content, $ignoreHtml);
1034 + return \do_shortcode($content, $ignoreHtml);
927 1035 }
928 1036
929 1037 /**
930 - * @see attachment_url_to_postid
1038 + * @see \attachment_url_to_postid()
1039 + *
1040 + * @param string $url
1041 + *
1042 + * @return int
931 1043 */
932 - public function attachmentUrlToPostId(string $url): int
1044 + public function attachmentUrlToPostId($url)
933 1045 {
934 - return attachment_url_to_postid($url);
1046 + return \attachment_url_to_postid($url);
935 1047 }
936 1048
937 1049 /**
938 - * @see got_mod_rewrite
1050 + * @see \got_mod_rewrite()
1051 + *
1052 + * @return bool
939 1053 */
940 - public function gotModRewrite(): bool
1054 + public function gotModRewrite()
941 1055 {
942 1056 if (function_exists('\got_mod_rewirte') === false) {
943 - require_once(ABSPATH . 'wp-admin/includes/misc.php');
1057 + require_once(ABSPATH.'wp-admin/includes/misc.php');
944 1058 }
945 1059
946 - return got_mod_rewrite();
947 - }
948 -
949 - /**
950 - * @see is_user_member_of_blog()
951 - */
952 - public function isUserMemberOfBlog(): bool
953 - {
954 - return is_user_member_of_blog();
955 - }
956 -
957 - /**
958 - * @see get_queried_object_id
959 - */
960 - public function getQueriedObjectId(): int
961 - {
962 - return get_queried_object_id();
963 - }
964 -
965 - public function getCurrentPost(): array|WP_Post|null
966 - {
967 - global $post;
968 - return $post;
1060 + return \got_mod_rewrite();
969 1061 }
970 1062 }