| @@ -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; |
| @@ -227,9 +219,9 @@ | ||
| 227 | 219 | */ |
| 228 | 220 | public function switchToBlog(int|string|null $blogId): bool |
| 229 | 221 | { |
| 230 | 222 | if (function_exists('\switch_to_blog') === true) { |
| 231 | - return (bool) switch_to_blog($blogId); | |
| 223 | + return switch_to_blog($blogId); | |
| 232 | 224 | } |
| 233 | 225 | |
| 234 | 226 | return true; |
| 235 | 227 | } |
| @@ -354,32 +346,8 @@ | ||
| 354 | 346 | return get_option($option, $default); |
| 355 | 347 | } |
| 356 | 348 | |
| 357 | 349 | /** |
| 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 | 350 | * @see is_super_admin |
| 383 | 351 | */ |
| 384 | 352 | public function isSuperAdmin(bool|int|string|null $userId = false): bool |
| 385 | 353 | { |
| @@ -430,16 +398,8 @@ | ||
| 430 | 398 | return site_url($path, $scheme); |
| 431 | 399 | } |
| 432 | 400 | |
| 433 | 401 | /** |
| 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 | 402 | * @see get_home_path |
| 443 | 403 | */ |
| 444 | 404 | public function getHomePath(): string |
| 445 | 405 | { |
| @@ -523,54 +483,22 @@ | ||
| 523 | 483 | global $wp_query; |
| 524 | 484 | return $wp_query; |
| 525 | 485 | } |
| 526 | 486 | |
| 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 | 487 | /** |
| 560 | 488 | * @see is_admin |
| 561 | 489 | */ |
| 562 | 490 | public function isAdmin(): bool |
| 563 | 491 | { |
| 564 | - if ($this->isRestRequest() === true) { | |
| 565 | - return $this->isEditingRestRequest(); | |
| 492 | + //Ajax request are always identified as an administrative interface page | |
| 493 | + if (wp_doing_ajax() === true || defined('REST_REQUEST') && REST_REQUEST) { | |
| 494 | + //So let's check if we are calling the ajax data for the frontend or backend | |
| 495 | + //If the referer is an admin url we are requesting the data for the backend | |
| 496 | + $adminUrl = get_admin_url(); | |
| 497 | + return str_starts_with((string)($_SERVER['HTTP_REFERER'] ?? ''), $adminUrl); | |
| 566 | 498 | } |
| 567 | 499 | |
| 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 | - | |
| 500 | + //No ajax request just uses the normal function | |
| 573 | 501 | return is_admin(); |
| 574 | 502 | } |
| 575 | 503 | |
| 576 | 504 | /** |
| @@ -804,26 +732,8 @@ | ||
| 804 | 732 | */ |
| 805 | 733 | public function attachmentIsImage(int|WP_Post $post): bool |
| 806 | 734 | { |
| 807 | 735 | 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 | 736 | } |
| 827 | 737 | |
| 828 | 738 | /** |
| 829 | 739 | * @see current_user_can |