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