← All changes
|
jetpack_vendor/automattic/jetpack-sync/src/class-functions.php
+67
-9
13.7.2
→
16.3-a.7
View file →
| @@ -10,8 +10,9 @@ | ||
| 10 | 10 | use Automattic\Jetpack\Connection\Manager; |
| 11 | 11 | use Automattic\Jetpack\Connection\Urls; |
| 12 | 12 | use Automattic\Jetpack\Constants; |
| 13 | 13 | use Automattic\Jetpack\Modules as Jetpack_Modules; |
| 14 | +use Automattic\Jetpack\Status; | |
| 14 | 15 | |
| 15 | 16 | /** |
| 16 | 17 | * Utility functions to generate data synced to wpcom |
| 17 | 18 | */ |
| @@ -70,9 +71,9 @@ | ||
| 70 | 71 | */ |
| 71 | 72 | public static function sanitize_taxonomy( $taxonomy ) { |
| 72 | 73 | |
| 73 | 74 | // Lets clone the taxonomy object instead of modifing the global one. |
| 74 | - $cloned_taxonomy = json_decode( wp_json_encode( $taxonomy ) ); | |
| 75 | + $cloned_taxonomy = json_decode( wp_json_encode( $taxonomy, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); | |
| 75 | 76 | |
| 76 | 77 | // recursive taxonomies are no fun. |
| 77 | 78 | if ( $cloned_taxonomy === null ) { |
| 78 | 79 | return null; |
| @@ -145,9 +146,9 @@ | ||
| 145 | 146 | $post_type_object->add_supports(); |
| 146 | 147 | $post_type_object->add_rewrite_rules(); |
| 147 | 148 | $post_type_object->add_hooks(); |
| 148 | 149 | $post_type_object->register_taxonomies(); |
| 149 | - return (object) $post_type_object; | |
| 150 | + return $post_type_object; | |
| 150 | 151 | } |
| 151 | 152 | |
| 152 | 153 | /** |
| 153 | 154 | * Returns site's post_type_features. |
| @@ -391,9 +392,9 @@ | ||
| 391 | 392 | /** |
| 392 | 393 | * Return the main network site WPCOM ID for multi-site installs |
| 393 | 394 | */ |
| 394 | 395 | $current_network = get_network(); |
| 395 | - switch_to_blog( $current_network->blog_id ); | |
| 396 | + switch_to_blog( (int) $current_network->blog_id ); | |
| 396 | 397 | $wpcom_blog_id = \Jetpack_Options::get_option( 'id' ); |
| 397 | 398 | restore_current_blog(); |
| 398 | 399 | return $wpcom_blog_id; |
| 399 | 400 | } |
| @@ -470,9 +471,9 @@ | ||
| 470 | 471 | if ( ! empty( $plugins_action_links ) ) { |
| 471 | 472 | if ( $plugin_file_singular === null ) { |
| 472 | 473 | return $plugins_action_links; |
| 473 | 474 | } |
| 474 | - return ( isset( $plugins_action_links[ $plugin_file_singular ] ) ? $plugins_action_links[ $plugin_file_singular ] : null ); | |
| 475 | + return ( $plugins_action_links[ $plugin_file_singular ] ?? null ); | |
| 475 | 476 | } |
| 476 | 477 | return array(); |
| 477 | 478 | } |
| 478 | 479 | |
| @@ -533,9 +534,9 @@ | ||
| 533 | 534 | |
| 534 | 535 | $formatted_gmt_offset = str_replace( |
| 535 | 536 | array( '.25', '.5', '.75' ), |
| 536 | 537 | array( ':15', ':30', ':45' ), |
| 537 | - (string) $formatted_gmt_offset | |
| 538 | + $formatted_gmt_offset | |
| 538 | 539 | ); |
| 539 | 540 | |
| 540 | 541 | /* translators: %s is UTC offset, e.g. "+1" */ |
| 541 | 542 | return sprintf( __( 'UTC%s', 'jetpack-sync' ), $formatted_gmt_offset ); |
| @@ -592,8 +593,26 @@ | ||
| 592 | 593 | return wp_is_block_theme(); |
| 593 | 594 | } |
| 594 | 595 | |
| 595 | 596 | /** |
| 597 | + * Returns the site's visibility as a `blog_public` value, or -1 when Jetpack considers the site private. | |
| 598 | + * | |
| 599 | + * Lets `jetpack_is_private_site` report the site as private to WordPress.com without changing | |
| 600 | + * the `blog_public` option itself, since core and other plugins do not expect a -1 there. | |
| 601 | + * | |
| 602 | + * @since 5.2.0 | |
| 603 | + * | |
| 604 | + * @return int -1 when private, otherwise the stored `blog_public` value. | |
| 605 | + */ | |
| 606 | + public static function get_site_visibility() { | |
| 607 | + if ( ( new Status() )->is_private_site() ) { | |
| 608 | + return -1; | |
| 609 | + } | |
| 610 | + | |
| 611 | + return (int) get_option( 'blog_public', 1 ); | |
| 612 | + } | |
| 613 | + | |
| 614 | + /** | |
| 596 | 615 | * Wraps data in a way so that we can distinguish between objects and array and also prevent object recursion. |
| 597 | 616 | * |
| 598 | 617 | * @since 1.21.0 |
| 599 | 618 | * |
| @@ -603,9 +622,21 @@ | ||
| 603 | 622 | * @return array |
| 604 | 623 | */ |
| 605 | 624 | public static function json_wrap( &$any, $seen_nodes = array() ) { |
| 606 | 625 | if ( is_object( $any ) ) { |
| 607 | - $input = get_object_vars( $any ); | |
| 626 | + $input = get_object_vars( $any ); | |
| 627 | + | |
| 628 | + // WordPress 6.9 introduced lazy-loading of WP_User `roles`, `caps`, and `allcaps` properties. | |
| 629 | + // It also made said properties protected, so we need to access them and set them as keys manually. | |
| 630 | + if ( $any instanceof \WP_User ) { | |
| 631 | + $roles = $any->roles; | |
| 632 | + $caps = $any->caps; | |
| 633 | + $allcaps = $any->allcaps; | |
| 634 | + $input['roles'] = $roles; | |
| 635 | + $input['caps'] = $caps; | |
| 636 | + $input['allcaps'] = $allcaps; | |
| 637 | + } | |
| 638 | + | |
| 608 | 639 | $input['__o'] = 1; |
| 609 | 640 | } else { |
| 610 | 641 | $input = &$any; |
| 611 | 642 | } |
| @@ -666,9 +697,9 @@ | ||
| 666 | 697 | |
| 667 | 698 | /** |
| 668 | 699 | * Return the list of active Jetpack modules. |
| 669 | 700 | * |
| 670 | - * @since $$next_version$$ | |
| 701 | + * @since 1.34.0 | |
| 671 | 702 | * |
| 672 | 703 | * @return array |
| 673 | 704 | */ |
| 674 | 705 | public static function get_active_modules() { |
| @@ -677,9 +708,9 @@ | ||
| 677 | 708 | |
| 678 | 709 | /** |
| 679 | 710 | * Return a list of PHP modules that we want to track. |
| 680 | 711 | * |
| 681 | - * @since $$next_version$$ | |
| 712 | + * @since 1.50.0 | |
| 682 | 713 | * |
| 683 | 714 | * @return array |
| 684 | 715 | */ |
| 685 | 716 | public static function get_loaded_extensions() { |
| @@ -713,12 +744,39 @@ | ||
| 713 | 744 | |
| 714 | 745 | /** |
| 715 | 746 | * Return the list of active connected Jetpack plugins. |
| 716 | 747 | * |
| 717 | - * @since $$next_version$$ | |
| 748 | + * @since 3.2.0 | |
| 718 | 749 | * |
| 719 | 750 | * @return array |
| 720 | 751 | */ |
| 721 | 752 | public static function get_jetpack_connection_active_plugins() { |
| 722 | 753 | return ( new Manager() )->get_connected_plugins(); |
| 754 | + } | |
| 755 | + | |
| 756 | + /** | |
| 757 | + * Return the list of active sync modules. | |
| 758 | + * | |
| 759 | + * @since 3.6.0 | |
| 760 | + * | |
| 761 | + * @return array | |
| 762 | + */ | |
| 763 | + public static function get_jetpack_sync_active_modules() { | |
| 764 | + | |
| 765 | + /** This filter is documented in projects/packages/sync/src/class-modules.php */ | |
| 766 | + $modules = apply_filters( 'jetpack_sync_modules', Modules::DEFAULT_SYNC_MODULES ); | |
| 767 | + $modules = array_unique( $modules ); | |
| 768 | + $modules = array_map( 'wp_normalize_path', $modules ); | |
| 769 | + return $modules; | |
| 770 | + } | |
| 771 | + | |
| 772 | + /** | |
| 773 | + * Return the list of Jetpack package versions. | |
| 774 | + * | |
| 775 | + * @since 4.11.1 | |
| 776 | + * | |
| 777 | + * @return array | |
| 778 | + */ | |
| 779 | + public static function get_jetpack_package_versions() { | |
| 780 | + return apply_filters( 'jetpack_package_versions', array() ); | |
| 723 | 781 | } |
| 724 | 782 | } |