PluginProbe
User Access Manager / 2.3.2
User Access Manager v2.3.2
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 +22 -128 2.3.152.3.2 View file →
@@ -19,9 +19,8 @@
19 19 use function add_filter;
20 20 use function add_menu_page;
21 21 use function add_meta_box;
22 22 use function add_option;
23 -use function add_query_arg;
24 23 use function add_shortcode;
25 24 use function add_submenu_page;
26 25 use function attachment_url_to_postid;
27 26 use function current_time;
@@ -90,13 +89,8 @@
90 89 use function wp_verify_nonce;
91 90
92 91 class Wordpress
93 92 {
94 - public const REST_READING_METHODS = ['GET', 'HEAD'];
95 -
96 - private bool $restRequestDispatched = false;
97 - private bool $editingRestRequestDetected = false;
98 -
99 93 public function getDatabase(): wpdb
100 94 {
101 95 global $wpdb;
102 96 return $wpdb;
@@ -108,24 +102,8 @@
108 102 return $is_nginx;
109 103 }
110 104
111 105 /**
112 - * @see wp_using_ext_object_cache
113 - */
114 - public function isUsingExtObjectCache(): bool
115 - {
116 - return function_exists('wp_using_ext_object_cache') && wp_using_ext_object_cache() === true;
117 - }
118 -
119 - /**
120 - * @see apache_get_modules
121 - */
122 - public function isApacheModuleLoaded(string $module): bool
123 - {
124 - return function_exists('apache_get_modules') && in_array($module, apache_get_modules(), true);
125 - }
126 -
127 - /**
128 106 * @see is_post_type_hierarchical
129 107 */
130 108 public function isPostTypeHierarchical(string $postType): bool
131 109 {
@@ -142,9 +120,9 @@
142 120
143 121 /**
144 122 * @see get_userdata
145 123 */
146 - public function getUserData(int|string|null $id): WP_User|bool
124 + public function getUserData(int|string $id): WP_User|bool
147 125 {
148 126 return get_userdata($id);
149 127 }
150 128
@@ -151,9 +129,9 @@
151 129 /**
152 130 * @see get_post_types
153 131 */
154 132 public function getPostTypes(
155 - array|string|int $arguments = [],
133 + array|string $arguments = [],
156 134 string $output = 'names',
157 135 string $operator = 'and'
158 136 ): array {
159 137 return get_post_types($arguments, $output, $operator);
@@ -178,13 +156,10 @@
178 156
179 157 /**
180 158 * @see get_post
181 159 */
182 - public function getPost(
183 - int|string|null $id,
184 - string $output = OBJECT,
185 - string $filter = 'raw'
186 - ): WP_Post|array|bool|null {
160 + public function getPost(int|string $id, string $output = OBJECT, string $filter = 'raw'): array|WP_Post|null
161 + {
187 162 return get_post($id, $output, $filter);
188 163 }
189 164
190 165 /**
@@ -202,9 +177,9 @@
202 177 int|string $id,
203 178 string $taxonomy = '',
204 179 string $output = OBJECT,
205 180 string $filter = 'raw'
206 - ): WP_Term|WP_Error|array|bool|null {
181 + ): WP_Term|WP_Error|array|null {
207 182 return get_term($id, $taxonomy, $output, $filter);
208 183 }
209 184
210 185
@@ -222,9 +197,9 @@
222 197
223 198 /**
224 199 * @see switch_to_blog
225 200 */
226 - public function switchToBlog(int|string|null $blogId): bool
201 + public function switchToBlog(int $blogId): bool
227 202 {
228 203 if (function_exists('\switch_to_blog') === true) {
229 204 return switch_to_blog($blogId);
230 205 }
@@ -300,16 +275,8 @@
300 275 return add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
301 276 }
302 277
303 278 /**
304 - * @see WP_Error
305 - */
306 - public function getWpError(string|int $code = '', string $message = '', mixed $data = ''): WP_Error
307 - {
308 - return new WP_Error($code, $message, $data);
309 - }
310 -
311 - /**
312 279 * @see remove_filter
313 280 */
314 281 public function removeFilter(string $tag, callable $functionToRemove, int $priority = 10): bool
315 282 {
@@ -352,35 +319,11 @@
352 319 return get_option($option, $default);
353 320 }
354 321
355 322 /**
356 - * @see wp_cache_set
357 - */
358 - public function wpCacheSet(string $key, mixed $data, string $group = '', int $expire = 0): bool
359 - {
360 - return wp_cache_set($key, $data, $group, $expire);
361 - }
362 -
363 - /**
364 - * @see wp_cache_get
365 - */
366 - public function wpCacheGet(string $key, string $group = ''): mixed
367 - {
368 - return wp_cache_get($key, $group);
369 - }
370 -
371 - /**
372 - * @see wp_cache_delete
373 - */
374 - public function wpCacheDelete(string $key, string $group = ''): bool
375 - {
376 - return wp_cache_delete($key, $group);
377 - }
378 -
379 - /**
380 323 * @see is_super_admin
381 324 */
382 - public function isSuperAdmin(bool|int|string|null $userId = false): bool
325 + public function isSuperAdmin(bool|int|string $userId = false): bool
383 326 {
384 327 return is_super_admin($userId);
385 328 }
386 329
@@ -398,9 +341,9 @@
398 341
399 342 /**
400 343 * @see get_allowed_mime_types
401 344 */
402 - public function getAllowedMimeTypes(WP_User|int|string|null $user = null): array
345 + public function getAllowedMimeTypes(WP_User|int|string $user = null): array
403 346 {
404 347 return get_allowed_mime_types($user);
405 348 }
406 349
@@ -406,9 +349,9 @@
406 349
407 350 /**
408 351 * @see wp_upload_dir
409 352 */
410 - public function getUploadDir(?string $time = null, bool $createDir = true, bool $refreshCache = false): array
353 + public function getUploadDir(string $time = null, bool $createDir = true, bool $refreshCache = false): array
411 354 {
412 355 return wp_upload_dir($time, $createDir, $refreshCache);
413 356 }
414 357
@@ -414,9 +357,9 @@
414 357
415 358 /**
416 359 * @see home_url
417 360 */
418 - public function getHomeUrl(string $path = '', ?string $scheme = null): string
361 + public function getHomeUrl(string $path = '', string $scheme = null): string
419 362 {
420 363 return home_url($path, $scheme);
421 364 }
422 365
@@ -422,22 +365,14 @@
422 365
423 366 /**
424 367 * @see site_url
425 368 */
426 - public function getSiteUrl(string $path = '', ?string $scheme = null): string
369 + public function getSiteUrl(string $path = '', string $scheme = null): string
427 370 {
428 371 return site_url($path, $scheme);
429 372 }
430 373
431 374 /**
432 - * @see add_query_arg
433 - */
434 - public function addQueryArg(array $arguments, string $url): string
435 - {
436 - return add_query_arg($arguments, $url);
437 - }
438 -
439 - /**
440 375 * @see get_home_path
441 376 */
442 377 public function getHomePath(): string
443 378 {
@@ -450,9 +385,9 @@
450 385
451 386 /**
452 387 * @see wp_parse_id_list
453 388 */
454 - public function parseIdList(array|string|int $list): array
389 + public function parseIdList(array|string $list): array
455 390 {
456 391 return wp_parse_id_list($list);
457 392 }
458 393
@@ -467,9 +402,9 @@
467 402
468 403 /**
469 404 * @see is_feed
470 405 */
471 - public function isFeed(array|string|int $feeds = ''): bool
406 + public function isFeed(array|string $feeds = ''): bool
472 407 {
473 408 return is_feed($feeds);
474 409 }
475 410
@@ -499,16 +434,8 @@
499 434 {
500 435 return wp_redirect($location, $status);
501 436 }
502 437
503 - /**
504 - * @see wp_get_referer
505 - */
506 - public function getReferer(): string|false
507 - {
508 - return wp_get_referer();
509 - }
510 -
511 438 public function getPageLink(
512 439 bool|int|string|WP_Post $post = false,
513 440 bool $leaveName = false,
514 441 bool $sample = false
@@ -521,40 +448,8 @@
521 448 global $wp_query;
522 449 return $wp_query;
523 450 }
524 451
525 - public function isRestRequest(): bool
526 - {
527 - return defined('REST_REQUEST') === true && REST_REQUEST === true;
528 - }
529 -
530 - public function setRestRequestContext(bool $isEditingRequest): void
531 - {
532 - $this->restRequestDispatched = true;
533 - //Nested requests, like the ones for embedded objects, must not lower the context again.
534 - $this->editingRestRequestDetected = $this->editingRestRequestDetected || $isEditingRequest;
535 - }
536 -
537 - private function isReadingRestMethod(string $method): bool
538 - {
539 - return in_array(strtoupper($method), self::REST_READING_METHODS, true);
540 - }
541 -
542 - private function isEditingRestRequest(): bool
543 - {
544 - if ($this->isRestRequest() === false) {
545 - return false;
546 - }
547 -
548 - if ($this->restRequestDispatched === true) {
549 - return $this->editingRestRequestDetected;
550 - }
551 -
552 - //Undispatched requests only expose the raw data, so an editing request is assumed.
553 - return $this->isReadingRestMethod((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET')) === false
554 - || ($_REQUEST['context'] ?? '') === 'edit';
555 - }
556 -
557 452 /**
558 453 * @see is_admin
559 454 */
560 455 public function isAdmin(): bool
@@ -559,14 +454,13 @@
559 454 */
560 455 public function isAdmin(): bool
561 456 {
562 457 //Ajax request are always identified as an administrative interface page
563 - if (wp_doing_ajax() === true || $this->isRestRequest() === true) {
458 + if (wp_doing_ajax() === true || defined('REST_REQUEST') && REST_REQUEST) {
564 459 //So let's check if we are calling the ajax data for the frontend or backend
565 460 //If the referer is an admin url we are requesting the data for the backend
566 461 $adminUrl = get_admin_url();
567 - return str_starts_with((string)($_SERVER['HTTP_REFERER'] ?? ''), $adminUrl)
568 - || $this->isEditingRestRequest() === true;
462 + return str_starts_with((string)($_SERVER['HTTP_REFERER'] ?? ''), $adminUrl);
569 463 }
570 464
571 465 //No ajax request just uses the normal function
572 466 return is_admin();
@@ -652,9 +546,9 @@
652 546
653 547 /**
654 548 * @see get_pages
655 549 */
656 - public function getPages(array|string|int $arguments): bool|array
550 + public function getPages(array|string $arguments): bool|array
657 551 {
658 552 return get_pages($arguments);
659 553 }
660 554
@@ -674,13 +568,13 @@
674 568 /**
675 569 * @see wp_register_script
676 570 */
677 571 public function registerScript(
678 - string $handle,
679 - string $source,
680 - array $depends = [],
572 + string $handle,
573 + string $source,
574 + array $depends = [],
681 575 bool|string|null $version = false,
682 - bool $inFooter = false
576 + bool $inFooter = false
683 577 ): bool {
684 578 return wp_register_script($handle, $source, $depends, $version, $inFooter);
685 579 }
686 580
@@ -760,9 +654,9 @@
760 654
761 655 /**
762 656 * @see is_single
763 657 */
764 - public function isSingle(array|string|int $post = ''): bool
658 + public function isSingle(int|array|string $post = ''): bool
765 659 {
766 660 return is_single($post);
767 661 }
768 662
@@ -768,9 +662,9 @@
768 662
769 663 /**
770 664 * @see is_page
771 665 */
772 - public function isPage(array|string|int $page = ''): bool
666 + public function isPage(int|array|string $page = ''): bool
773 667 {
774 668 return is_page($page);
775 669 }
776 670