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 +28 -153 2.3.202.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;
@@ -33,9 +32,8 @@
33 32 use function do_shortcode;
34 33 use function esc_html;
35 34 use function function_exists;
36 35 use function get_allowed_mime_types;
37 -use function get_attached_file;
38 36 use function get_bloginfo;
39 37 use function get_home_path;
40 38 use function get_option;
41 39 use function get_page_by_path;
@@ -76,9 +74,8 @@
76 74 use function wp_die;
77 75 use function wp_doing_ajax;
78 76 use function wp_enqueue_script;
79 77 use function wp_enqueue_style;
80 -use function wp_get_attachment_metadata;
81 78 use function wp_get_current_user;
82 79 use function wp_login_url;
83 80 use function wp_logout_url;
84 81 use function wp_lostpassword_url;
@@ -92,13 +89,8 @@
92 89 use function wp_verify_nonce;
93 90
94 91 class Wordpress
95 92 {
96 - public const REST_READING_METHODS = ['GET', 'HEAD'];
97 -
98 - private bool $restRequestDispatched = false;
99 - private bool $editingRestRequestDetected = false;
100 -
101 93 public function getDatabase(): wpdb
102 94 {
103 95 global $wpdb;
104 96 return $wpdb;
@@ -110,24 +102,8 @@
110 102 return $is_nginx;
111 103 }
112 104
113 105 /**
114 - * @see wp_using_ext_object_cache
115 - */
116 - public function isUsingExtObjectCache(): bool
117 - {
118 - return function_exists('wp_using_ext_object_cache') && wp_using_ext_object_cache() === true;
119 - }
120 -
121 - /**
122 - * @see apache_get_modules
123 - */
124 - public function isApacheModuleLoaded(string $module): bool
125 - {
126 - return function_exists('apache_get_modules') && in_array($module, apache_get_modules(), true);
127 - }
128 -
129 - /**
130 106 * @see is_post_type_hierarchical
131 107 */
132 108 public function isPostTypeHierarchical(string $postType): bool
133 109 {
@@ -144,9 +120,9 @@
144 120
145 121 /**
146 122 * @see get_userdata
147 123 */
148 - public function getUserData(int|string|null $id): WP_User|bool
124 + public function getUserData(int|string $id): WP_User|bool
149 125 {
150 126 return get_userdata($id);
151 127 }
152 128
@@ -153,9 +129,9 @@
153 129 /**
154 130 * @see get_post_types
155 131 */
156 132 public function getPostTypes(
157 - array|string|int $arguments = [],
133 + array|string $arguments = [],
158 134 string $output = 'names',
159 135 string $operator = 'and'
160 136 ): array {
161 137 return get_post_types($arguments, $output, $operator);
@@ -180,13 +156,10 @@
180 156
181 157 /**
182 158 * @see get_post
183 159 */
184 - public function getPost(
185 - int|string|null $id,
186 - string $output = OBJECT,
187 - string $filter = 'raw'
188 - ): WP_Post|array|bool|null {
160 + public function getPost(int|string $id, string $output = OBJECT, string $filter = 'raw'): array|WP_Post|null
161 + {
189 162 return get_post($id, $output, $filter);
190 163 }
191 164
192 165 /**
@@ -204,9 +177,9 @@
204 177 int|string $id,
205 178 string $taxonomy = '',
206 179 string $output = OBJECT,
207 180 string $filter = 'raw'
208 - ): WP_Term|WP_Error|array|bool|null {
181 + ): WP_Term|WP_Error|array|null {
209 182 return get_term($id, $taxonomy, $output, $filter);
210 183 }
211 184
212 185
@@ -224,12 +197,12 @@
224 197
225 198 /**
226 199 * @see switch_to_blog
227 200 */
228 - public function switchToBlog(int|string|null $blogId): bool
201 + public function switchToBlog(int $blogId): bool
229 202 {
230 203 if (function_exists('\switch_to_blog') === true) {
231 - return (bool) switch_to_blog($blogId);
204 + return switch_to_blog($blogId);
232 205 }
233 206
234 207 return true;
235 208 }
@@ -302,16 +275,8 @@
302 275 return add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
303 276 }
304 277
305 278 /**
306 - * @see WP_Error
307 - */
308 - public function getWpError(string|int $code = '', string $message = '', mixed $data = ''): WP_Error
309 - {
310 - return new WP_Error($code, $message, $data);
311 - }
312 -
313 - /**
314 279 * @see remove_filter
315 280 */
316 281 public function removeFilter(string $tag, callable $functionToRemove, int $priority = 10): bool
317 282 {
@@ -354,35 +319,11 @@
354 319 return get_option($option, $default);
355 320 }
356 321
357 322 /**
358 - * @see wp_cache_set
359 - */
360 - public function wpCacheSet(string $key, mixed $data, string $group = '', int $expire = 0): bool
361 - {
362 - return wp_cache_set($key, $data, $group, $expire);
363 - }
364 -
365 - /**
366 - * @see wp_cache_get
367 - */
368 - public function wpCacheGet(string $key, string $group = ''): mixed
369 - {
370 - return wp_cache_get($key, $group);
371 - }
372 -
373 - /**
374 - * @see wp_cache_delete
375 - */
376 - public function wpCacheDelete(string $key, string $group = ''): bool
377 - {
378 - return wp_cache_delete($key, $group);
379 - }
380 -
381 - /**
382 323 * @see is_super_admin
383 324 */
384 - public function isSuperAdmin(bool|int|string|null $userId = false): bool
325 + public function isSuperAdmin(bool|int|string $userId = false): bool
385 326 {
386 327 return is_super_admin($userId);
387 328 }
388 329
@@ -400,9 +341,9 @@
400 341
401 342 /**
402 343 * @see get_allowed_mime_types
403 344 */
404 - public function getAllowedMimeTypes(WP_User|int|string|null $user = null): array
345 + public function getAllowedMimeTypes(WP_User|int|string $user = null): array
405 346 {
406 347 return get_allowed_mime_types($user);
407 348 }
408 349
@@ -408,9 +349,9 @@
408 349
409 350 /**
410 351 * @see wp_upload_dir
411 352 */
412 - 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
413 354 {
414 355 return wp_upload_dir($time, $createDir, $refreshCache);
415 356 }
416 357
@@ -416,9 +357,9 @@
416 357
417 358 /**
418 359 * @see home_url
419 360 */
420 - public function getHomeUrl(string $path = '', ?string $scheme = null): string
361 + public function getHomeUrl(string $path = '', string $scheme = null): string
421 362 {
422 363 return home_url($path, $scheme);
423 364 }
424 365
@@ -424,22 +365,14 @@
424 365
425 366 /**
426 367 * @see site_url
427 368 */
428 - public function getSiteUrl(string $path = '', ?string $scheme = null): string
369 + public function getSiteUrl(string $path = '', string $scheme = null): string
429 370 {
430 371 return site_url($path, $scheme);
431 372 }
432 373
433 374 /**
434 - * @see add_query_arg
435 - */
436 - public function addQueryArg(array $arguments, string $url): string
437 - {
438 - return add_query_arg($arguments, $url);
439 - }
440 -
441 - /**
442 375 * @see get_home_path
443 376 */
444 377 public function getHomePath(): string
445 378 {
@@ -452,9 +385,9 @@
452 385
453 386 /**
454 387 * @see wp_parse_id_list
455 388 */
456 - public function parseIdList(array|string|int $list): array
389 + public function parseIdList(array|string $list): array
457 390 {
458 391 return wp_parse_id_list($list);
459 392 }
460 393
@@ -469,9 +402,9 @@
469 402
470 403 /**
471 404 * @see is_feed
472 405 */
473 - public function isFeed(array|string|int $feeds = ''): bool
406 + public function isFeed(array|string $feeds = ''): bool
474 407 {
475 408 return is_feed($feeds);
476 409 }
477 410
@@ -501,16 +434,8 @@
501 434 {
502 435 return wp_redirect($location, $status);
503 436 }
504 437
505 - /**
506 - * @see wp_get_referer
507 - */
508 - public function getReferer(): string|false
509 - {
510 - return wp_get_referer();
511 - }
512 -
513 438 public function getPageLink(
514 439 bool|int|string|WP_Post $post = false,
515 440 bool $leaveName = false,
516 441 bool $sample = false
@@ -523,54 +448,22 @@
523 448 global $wp_query;
524 449 return $wp_query;
525 450 }
526 451
527 - public function isRestRequest(): bool
528 - {
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;
548 - }
549 -
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';
557 - }
558 -
559 452 /**
560 453 * @see is_admin
561 454 */
562 455 public function isAdmin(): bool
563 456 {
564 - if ($this->isRestRequest() === true) {
565 - return $this->isEditingRestRequest();
457 + //Ajax request are always identified as an administrative interface page
458 + if (wp_doing_ajax() === true || defined('REST_REQUEST') && REST_REQUEST) {
459 + //So let's check if we are calling the ajax data for the frontend or backend
460 + //If the referer is an admin url we are requesting the data for the backend
461 + $adminUrl = get_admin_url();
462 + return str_starts_with((string)($_SERVER['HTTP_REFERER'] ?? ''), $adminUrl);
566 463 }
567 464
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 -
465 + //No ajax request just uses the normal function
573 466 return is_admin();
574 467 }
575 468
576 469 /**
@@ -653,9 +546,9 @@
653 546
654 547 /**
655 548 * @see get_pages
656 549 */
657 - public function getPages(array|string|int $arguments): bool|array
550 + public function getPages(array|string $arguments): bool|array
658 551 {
659 552 return get_pages($arguments);
660 553 }
661 554
@@ -675,13 +568,13 @@
675 568 /**
676 569 * @see wp_register_script
677 570 */
678 571 public function registerScript(
679 - string $handle,
680 - string $source,
681 - array $depends = [],
572 + string $handle,
573 + string $source,
574 + array $depends = [],
682 575 bool|string|null $version = false,
683 - bool $inFooter = false
576 + bool $inFooter = false
684 577 ): bool {
685 578 return wp_register_script($handle, $source, $depends, $version, $inFooter);
686 579 }
687 580
@@ -761,9 +654,9 @@
761 654
762 655 /**
763 656 * @see is_single
764 657 */
765 - public function isSingle(array|string|int $post = ''): bool
658 + public function isSingle(int|array|string $post = ''): bool
766 659 {
767 660 return is_single($post);
768 661 }
769 662
@@ -769,9 +662,9 @@
769 662
770 663 /**
771 664 * @see is_page
772 665 */
773 - public function isPage(array|string|int $page = ''): bool
666 + public function isPage(int|array|string $page = ''): bool
774 667 {
775 668 return is_page($page);
776 669 }
777 670
@@ -804,26 +697,8 @@
804 697 */
805 698 public function attachmentIsImage(int|WP_Post $post): bool
806 699 {
807 700 return wp_attachment_is_image($post);
808 - }
809 -
810 - /**
811 - * @see get_attached_file
812 - */
813 - public function getAttachedFile(int $attachmentId, bool $unfiltered = false): string|false
814 - {
815 - return get_attached_file($attachmentId, $unfiltered);
816 - }
817 -
818 - /**
819 - * The return value passes the wp_get_attachment_metadata filter, so any type can reach us.
820 - *
821 - * @see wp_get_attachment_metadata
822 - */
823 - public function getAttachmentMetadata(int $attachmentId): mixed
824 - {
825 - return wp_get_attachment_metadata($attachmentId);
826 701 }
827 702
828 703 /**
829 704 * @see current_user_can