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 -142 2.3.172.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;
@@ -91,13 +89,8 @@
91 89 use function wp_verify_nonce;
92 90
93 91 class Wordpress
94 92 {
95 - public const REST_READING_METHODS = ['GET', 'HEAD'];
96 -
97 - private bool $restRequestDispatched = false;
98 - private bool $editingRestRequestDetected = false;
99 -
100 93 public function getDatabase(): wpdb
101 94 {
102 95 global $wpdb;
103 96 return $wpdb;
@@ -109,24 +102,8 @@
109 102 return $is_nginx;
110 103 }
111 104
112 105 /**
113 - * @see wp_using_ext_object_cache
114 - */
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 106 * @see is_post_type_hierarchical
130 107 */
131 108 public function isPostTypeHierarchical(string $postType): bool
132 109 {
@@ -143,9 +120,9 @@
143 120
144 121 /**
145 122 * @see get_userdata
146 123 */
147 - public function getUserData(int|string|null $id): WP_User|bool
124 + public function getUserData(int|string $id): WP_User|bool
148 125 {
149 126 return get_userdata($id);
150 127 }
151 128
@@ -152,9 +129,9 @@
152 129 /**
153 130 * @see get_post_types
154 131 */
155 132 public function getPostTypes(
156 - array|string|int $arguments = [],
133 + array|string $arguments = [],
157 134 string $output = 'names',
158 135 string $operator = 'and'
159 136 ): array {
160 137 return get_post_types($arguments, $output, $operator);
@@ -179,13 +156,10 @@
179 156
180 157 /**
181 158 * @see get_post
182 159 */
183 - public function getPost(
184 - int|string|null $id,
185 - string $output = OBJECT,
186 - string $filter = 'raw'
187 - ): WP_Post|array|bool|null {
160 + public function getPost(int|string $id, string $output = OBJECT, string $filter = 'raw'): array|WP_Post|null
161 + {
188 162 return get_post($id, $output, $filter);
189 163 }
190 164
191 165 /**
@@ -203,9 +177,9 @@
203 177 int|string $id,
204 178 string $taxonomy = '',
205 179 string $output = OBJECT,
206 180 string $filter = 'raw'
207 - ): WP_Term|WP_Error|array|bool|null {
181 + ): WP_Term|WP_Error|array|null {
208 182 return get_term($id, $taxonomy, $output, $filter);
209 183 }
210 184
211 185
@@ -223,12 +197,12 @@
223 197
224 198 /**
225 199 * @see switch_to_blog
226 200 */
227 - public function switchToBlog(int|string|null $blogId): bool
201 + public function switchToBlog(int $blogId): bool
228 202 {
229 203 if (function_exists('\switch_to_blog') === true) {
230 - return (bool) switch_to_blog($blogId);
204 + return switch_to_blog($blogId);
231 205 }
232 206
233 207 return true;
234 208 }
@@ -301,16 +275,8 @@
301 275 return add_filter($tag, $functionToAdd, $priority, $acceptedArguments);
302 276 }
303 277
304 278 /**
305 - * @see WP_Error
306 - */
307 - public function getWpError(string|int $code = '', string $message = '', mixed $data = ''): WP_Error
308 - {
309 - return new WP_Error($code, $message, $data);
310 - }
311 -
312 - /**
313 279 * @see remove_filter
314 280 */
315 281 public function removeFilter(string $tag, callable $functionToRemove, int $priority = 10): bool
316 282 {
@@ -353,35 +319,11 @@
353 319 return get_option($option, $default);
354 320 }
355 321
356 322 /**
357 - * @see wp_cache_set
358 - */
359 - public function wpCacheSet(string $key, mixed $data, string $group = '', int $expire = 0): bool
360 - {
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 323 * @see is_super_admin
382 324 */
383 - public function isSuperAdmin(bool|int|string|null $userId = false): bool
325 + public function isSuperAdmin(bool|int|string $userId = false): bool
384 326 {
385 327 return is_super_admin($userId);
386 328 }
387 329
@@ -399,9 +341,9 @@
399 341
400 342 /**
401 343 * @see get_allowed_mime_types
402 344 */
403 - public function getAllowedMimeTypes(WP_User|int|string|null $user = null): array
345 + public function getAllowedMimeTypes(WP_User|int|string $user = null): array
404 346 {
405 347 return get_allowed_mime_types($user);
406 348 }
407 349
@@ -407,9 +349,9 @@
407 349
408 350 /**
409 351 * @see wp_upload_dir
410 352 */
411 - 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
412 354 {
413 355 return wp_upload_dir($time, $createDir, $refreshCache);
414 356 }
415 357
@@ -415,9 +357,9 @@
415 357
416 358 /**
417 359 * @see home_url
418 360 */
419 - public function getHomeUrl(string $path = '', ?string $scheme = null): string
361 + public function getHomeUrl(string $path = '', string $scheme = null): string
420 362 {
421 363 return home_url($path, $scheme);
422 364 }
423 365
@@ -423,22 +365,14 @@
423 365
424 366 /**
425 367 * @see site_url
426 368 */
427 - public function getSiteUrl(string $path = '', ?string $scheme = null): string
369 + public function getSiteUrl(string $path = '', string $scheme = null): string
428 370 {
429 371 return site_url($path, $scheme);
430 372 }
431 373
432 374 /**
433 - * @see add_query_arg
434 - */
435 - public function addQueryArg(array $arguments, string $url): string
436 - {
437 - return add_query_arg($arguments, $url);
438 - }
439 -
440 - /**
441 375 * @see get_home_path
442 376 */
443 377 public function getHomePath(): string
444 378 {
@@ -451,9 +385,9 @@
451 385
452 386 /**
453 387 * @see wp_parse_id_list
454 388 */
455 - public function parseIdList(array|string|int $list): array
389 + public function parseIdList(array|string $list): array
456 390 {
457 391 return wp_parse_id_list($list);
458 392 }
459 393
@@ -468,9 +402,9 @@
468 402
469 403 /**
470 404 * @see is_feed
471 405 */
472 - public function isFeed(array|string|int $feeds = ''): bool
406 + public function isFeed(array|string $feeds = ''): bool
473 407 {
474 408 return is_feed($feeds);
475 409 }
476 410
@@ -500,16 +434,8 @@
500 434 {
501 435 return wp_redirect($location, $status);
502 436 }
503 437
504 - /**
505 - * @see wp_get_referer
506 - */
507 - public function getReferer(): string|false
508 - {
509 - return wp_get_referer();
510 - }
511 -
512 438 public function getPageLink(
513 439 bool|int|string|WP_Post $post = false,
514 440 bool $leaveName = false,
515 441 bool $sample = false
@@ -522,54 +448,22 @@
522 448 global $wp_query;
523 449 return $wp_query;
524 450 }
525 451
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 452 /**
559 453 * @see is_admin
560 454 */
561 455 public function isAdmin(): bool
562 456 {
563 - if ($this->isRestRequest() === true) {
564 - 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);
565 463 }
566 464
567 - if (wp_doing_ajax() === true) {
568 - return is_user_logged_in() === true
569 - && str_starts_with((string)($_SERVER['HTTP_REFERER'] ?? ''), get_admin_url());
570 - }
571 -
465 + //No ajax request just uses the normal function
572 466 return is_admin();
573 467 }
574 468
575 469 /**
@@ -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
@@ -803,16 +697,8 @@
803 697 */
804 698 public function attachmentIsImage(int|WP_Post $post): bool
805 699 {
806 700 return wp_attachment_is_image($post);
807 - }
808 -
809 - /**
810 - * @see get_attached_file
811 - */
812 - public function getAttachedFile(int $attachmentId): string|false
813 - {
814 - return get_attached_file($attachmentId);
815 701 }
816 702
817 703 /**
818 704 * @see current_user_can