diff options
author | Yury German <blueknight@gentoo.org> | 2022-01-23 18:37:36 -0500 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2022-01-23 18:37:36 -0500 |
commit | f18b23a3a9378fb0a98856d436aa9ebf94e47429 (patch) | |
tree | e418433e22854ebd2d77eaa869d5d0470a973317 /plugins/jetpack/3rd-party | |
parent | Add classic-editor 1.5 (diff) | |
download | blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.gz blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.bz2 blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.zip |
Updating Classic Editor, Google Authenticatior, Jetpack, Public Post Preview, Table of Contents, Wordpress Importer
Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/jetpack/3rd-party')
22 files changed, 1430 insertions, 110 deletions
diff --git a/plugins/jetpack/3rd-party/3rd-party.php b/plugins/jetpack/3rd-party/3rd-party.php index 1db4fafd..7bbe75ee 100644 --- a/plugins/jetpack/3rd-party/3rd-party.php +++ b/plugins/jetpack/3rd-party/3rd-party.php @@ -3,11 +3,13 @@ * Compatibility files for third-party plugins. * This is used to improve compatibility of specific Jetpack features with third-party plugins. * - * @package Jetpack + * @package automattic/jetpack */ namespace Automattic\Jetpack; +use Automattic\Jetpack\Status\Host; + /** * Loads the individual 3rd-party compat files. */ @@ -19,12 +21,17 @@ function load_3rd_party() { 'bitly.php', 'buddypress.php', 'class.jetpack-amp-support.php', - 'class.jetpack-modules-overrides.php', // Special case. Tools to be used to override module settings. + 'class-jetpack-crm-data.php', + 'class-jetpack-modules-overrides.php', // Special case. Tools to be used to override module settings. + 'creative-mail.php', + 'jetpack-backup.php', + 'jetpack-boost.php', 'debug-bar.php', - 'domain-mapping.php', - 'polldaddy.php', + 'class-domain-mapping.php', + 'crowdsignal.php', 'qtranslate-x.php', 'vaultpress.php', + 'web-stories.php', 'wpml.php', 'woocommerce.php', 'woocommerce-services.php', @@ -35,6 +42,31 @@ function load_3rd_party() { require_once JETPACK__PLUGIN_DIR . '/3rd-party/' . $file; } } + + add_filter( 'jetpack_development_version', __NAMESPACE__ . '\atomic_weekly_override' ); +} + +/** + * Handles suppressing development version notices on Atomic-hosted sites. + * + * @param bool $development_version Filterable value if this is a development version of Jetpack. + * + * @return bool + */ +function atomic_weekly_override( $development_version ) { + if ( ( new Host() )->is_atomic_platform() ) { + $haystack = Constants::get_constant( 'JETPACK__PLUGIN_DIR' ); + $needle = '/jetpack-dev/'; + if ( + ( function_exists( 'str_ends_with' ) && str_ends_with( $haystack, $needle ) ) || // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.str_ends_withFound + 0 === substr_compare( $haystack, $needle, -13 ) + ) { + return $development_version; // Returns the default response if the active Jetpack version is from the beta plugin. + } + + $development_version = false; // Returns false for regular installs on Atomic. + } + return $development_version; // Return default if not on Atomic. } load_3rd_party(); diff --git a/plugins/jetpack/3rd-party/bbpress.php b/plugins/jetpack/3rd-party/bbpress.php index 0af7e028..86d6f13f 100644 --- a/plugins/jetpack/3rd-party/bbpress.php +++ b/plugins/jetpack/3rd-party/bbpress.php @@ -1,4 +1,10 @@ <?php +/** + * Compatibility functions for bbpress. + * + * @package automattic/jetpack + */ + add_action( 'init', 'jetpack_bbpress_compat', 11 ); // Priority 11 needed to ensure sharing_display is loaded. /** @@ -8,8 +14,21 @@ add_action( 'init', 'jetpack_bbpress_compat', 11 ); // Priority 11 needed to ens * @since 3.7.1 */ function jetpack_bbpress_compat() { + if ( ! function_exists( 'bbpress' ) ) { + return; + } + + /** + * Add compatibility layer for REST API. + * + * @since 8.5.0 Moved from root-level file and check_rest_api_compat() + */ + require_once 'class-jetpack-bbpress-rest-api.php'; + Jetpack_BbPress_REST_API::instance(); + + // Adds sharing buttons to bbPress items. if ( function_exists( 'sharing_display' ) ) { - add_filter( 'bbp_get_topic_content', 'sharing_display', 19 ); + add_filter( 'bbp_get_topic_content', 'sharing_display', 19 ); add_action( 'bbp_template_after_single_forum', 'jetpack_sharing_bbpress' ); add_action( 'bbp_template_after_single_topic', 'jetpack_sharing_bbpress' ); } @@ -20,11 +39,11 @@ function jetpack_bbpress_compat() { * @author Brandon Kraft * @since 6.0.0 */ - if ( function_exists( 'bbp_get_topic_post_type' ) ) { - add_post_type_support( bbp_get_topic_post_type(), 'wpcom-markdown' ); - add_post_type_support( bbp_get_reply_post_type(), 'wpcom-markdown' ); - add_post_type_support( bbp_get_forum_post_type(), 'wpcom-markdown' ); - } + if ( function_exists( 'bbp_get_topic_post_type' ) ) { + add_post_type_support( bbp_get_topic_post_type(), 'wpcom-markdown' ); + add_post_type_support( bbp_get_reply_post_type(), 'wpcom-markdown' ); + add_post_type_support( bbp_get_forum_post_type(), 'wpcom-markdown' ); + } /** * Use Photon for all images in Topics and replies. diff --git a/plugins/jetpack/3rd-party/beaverbuilder.php b/plugins/jetpack/3rd-party/beaverbuilder.php index b3215ca2..4faf2d97 100644 --- a/plugins/jetpack/3rd-party/beaverbuilder.php +++ b/plugins/jetpack/3rd-party/beaverbuilder.php @@ -1,20 +1,19 @@ <?php /** * Beaverbuilder Compatibility. + * + * @package automattic/jetpack */ -class Jetpack_BeaverBuilderCompat { - function __construct() { - add_action( 'init', array( $this, 'beaverbuilder_refresh' ) ); - } +namespace Automattic\Jetpack\Third_Party; + +add_action( 'init', __NAMESPACE__ . '\beaverbuilder_refresh' ); - /** - * If masterbar module is active force BeaverBuilder to refresh when publishing a layout. - */ - function beaverbuilder_refresh() { - if ( Jetpack::is_module_active( 'masterbar' ) ) { - add_filter( 'fl_builder_should_refresh_on_publish', '__return_true' ); - } +/** + * If masterbar module is active force BeaverBuilder to refresh when publishing a layout. + */ +function beaverbuilder_refresh() { + if ( \Jetpack::is_module_active( 'masterbar' ) ) { + add_filter( 'fl_builder_should_refresh_on_publish', '__return_true' ); } } -new Jetpack_BeaverBuilderCompat(); diff --git a/plugins/jetpack/3rd-party/bitly.php b/plugins/jetpack/3rd-party/bitly.php index d9b744a5..4252099b 100644 --- a/plugins/jetpack/3rd-party/bitly.php +++ b/plugins/jetpack/3rd-party/bitly.php @@ -1,34 +1,33 @@ <?php - -/* +/** * Fixes issues with the Official Bitly for WordPress * https://wordpress.org/plugins/bitly/ + * + * @package automattic/jetpack */ -if( class_exists( 'Bitly' ) ) { - if( isset( $GLOBALS['bitly'] ) ) { +if ( class_exists( 'Bitly' ) ) { + + if ( isset( $GLOBALS['bitly'] ) ) { if ( method_exists( $GLOBALS['bitly'], 'og_tags' ) ) { remove_action( 'wp_head', array( $GLOBALS['bitly'], 'og_tags' ) ); } add_action( 'wp_head', 'jetpack_bitly_og_tag', 100 ); } - } /** - * jetpack_bitly_og_tag - * - * @return null + * Adds bitly OG tags. */ function jetpack_bitly_og_tag() { - if( has_filter( 'wp_head', 'jetpack_og_tags') === false ) { - // Add the bitly part again back if we don't have any jetpack_og_tags added + if ( has_filter( 'wp_head', 'jetpack_og_tags' ) === false ) { + // Add the bitly part again back if we don't have any jetpack_og_tags added. if ( method_exists( $GLOBALS['bitly'], 'og_tags' ) ) { $GLOBALS['bitly']->og_tags(); } } elseif ( isset( $GLOBALS['posts'] ) && $GLOBALS['posts'][0]->ID > 0 ) { - printf( "<meta property=\"bitly:url\" content=\"%s\" /> \n", esc_attr( $GLOBALS['bitly']->get_bitly_link_for_post_id( $GLOBALS['posts'][0]->ID ) ) ); + printf( "<meta property=\"bitly:url\" content=\"%s\" /> \n", esc_attr( $GLOBALS['bitly']->get_bitly_link_for_post_id( $GLOBALS['posts'][0]->ID ) ) ); } } diff --git a/plugins/jetpack/3rd-party/buddypress.php b/plugins/jetpack/3rd-party/buddypress.php index 9ae35f3c..3d02ca34 100644 --- a/plugins/jetpack/3rd-party/buddypress.php +++ b/plugins/jetpack/3rd-party/buddypress.php @@ -1,8 +1,22 @@ <?php +/** + * 3rd Party Integration for BuddyPress. + * + * @package automattic/jetpack. + */ -add_filter( 'bp_core_pre_avatar_handle_upload', 'blobphoto' ); -function blobphoto( $bool ) { +namespace Automattic\Jetpack\Third_Party; + +add_filter( 'bp_core_pre_avatar_handle_upload', __NAMESPACE__ . '\blobphoto' ); +/** + * Adds filters for skipping photon during pre_avatar_handle_upload. + * + * @param bool $bool Passthrough of filter's original content. No changes made. + * + * @return bool + */ +function blobphoto( $bool ) { add_filter( 'jetpack_photon_skip_image', '__return_true' ); return $bool; diff --git a/plugins/jetpack/3rd-party/class-domain-mapping.php b/plugins/jetpack/3rd-party/class-domain-mapping.php new file mode 100644 index 00000000..dd0cdaa5 --- /dev/null +++ b/plugins/jetpack/3rd-party/class-domain-mapping.php @@ -0,0 +1,160 @@ +<?php +/** + * Domain Mapping 3rd Party + * + * @package automattic/jetpack + */ + +namespace Automattic\Jetpack\Third_Party; + +use Automattic\Jetpack\Constants; + +/** + * Class Automattic\Jetpack\Third_Party\Domain_Mapping. + * + * This class contains methods that are used to provide compatibility between Jetpack sync and domain mapping plugins. + */ +class Domain_Mapping { + + /** + * Singleton holder. + * + * @var Domain_Mapping + **/ + private static $instance = null; + + /** + * An array of methods that are used to hook the Jetpack sync filters for home_url and site_url to a mapping plugin. + * + * @var array + */ + public static $test_methods = array( + 'hook_wordpress_mu_domain_mapping', + 'hook_wpmu_dev_domain_mapping', + ); + + /** + * Singleton constructor. + * + * @return Domain_Mapping|null + */ + public static function init() { + if ( is_null( self::$instance ) ) { + self::$instance = new Domain_Mapping(); + } + + return self::$instance; + } + + /** + * Class Automattic\Jetpack\Third_Party\Domain_Mapping constructor. + */ + private function __construct() { + add_action( 'plugins_loaded', array( $this, 'attempt_to_hook_domain_mapping_plugins' ) ); + } + + /** + * This function is called on the plugins_loaded action and will loop through the $test_methods + * to try and hook a domain mapping plugin to the Jetpack sync filters for the home_url and site_url callables. + */ + public function attempt_to_hook_domain_mapping_plugins() { + if ( ! Constants::is_defined( 'SUNRISE' ) ) { + return; + } + + $hooked = false; + $count = count( self::$test_methods ); + for ( $i = 0; $i < $count && ! $hooked; $i++ ) { + $hooked = call_user_func( array( $this, self::$test_methods[ $i ] ) ); + } + } + + /** + * This method will test for a constant and function that are known to be used with Donncha's WordPress MU + * Domain Mapping plugin. If conditions are met, we hook the domain_mapping_siteurl() function to Jetpack sync + * filters for home_url and site_url callables. + * + * @return bool + */ + public function hook_wordpress_mu_domain_mapping() { + if ( ! Constants::is_defined( 'SUNRISE_LOADED' ) || ! $this->function_exists( 'domain_mapping_siteurl' ) ) { + return false; + } + + add_filter( 'jetpack_sync_home_url', 'domain_mapping_siteurl' ); + add_filter( 'jetpack_sync_site_url', 'domain_mapping_siteurl' ); + + return true; + } + + /** + * This method will test for a class and method known to be used in WPMU Dev's domain mapping plugin. If the + * method exists, then we'll hook the swap_to_mapped_url() to our Jetpack sync filters for home_url and site_url. + * + * @return bool + */ + public function hook_wpmu_dev_domain_mapping() { + if ( ! $this->class_exists( 'domain_map' ) || ! $this->method_exists( 'domain_map', 'utils' ) ) { + return false; + } + + $utils = $this->get_domain_mapping_utils_instance(); + add_filter( 'jetpack_sync_home_url', array( $utils, 'swap_to_mapped_url' ) ); + add_filter( 'jetpack_sync_site_url', array( $utils, 'swap_to_mapped_url' ) ); + + return true; + } + + /* + * Utility Methods + * + * These methods are very minimal, and in most cases, simply pass on arguments. Why create them you ask? + * So that we can test. + */ + + /** + * Checks if a method exists. + * + * @param string $class Class name. + * @param string $method Method name. + * + * @return bool Returns function_exists() without modification. + */ + public function method_exists( $class, $method ) { + return method_exists( $class, $method ); + } + + /** + * Checks if a class exists. + * + * @param string $class Class name. + * + * @return bool Returns class_exists() without modification. + */ + public function class_exists( $class ) { + return class_exists( $class ); + } + + /** + * Checks if a function exists. + * + * @param string $function Function name. + * + * @return bool Returns function_exists() without modification. + */ + public function function_exists( $function ) { + return function_exists( $function ); + } + + /** + * Returns the Domain_Map::utils() instance. + * + * @see https://github.com/wpmudev/domain-mapping/blob/master/classes/Domainmap/Utils.php + * @return Domainmap_Utils + */ + public function get_domain_mapping_utils_instance() { + return \domain_map::utils(); + } +} + +Domain_Mapping::init(); diff --git a/plugins/jetpack/3rd-party/class-jetpack-bbpress-rest-api.php b/plugins/jetpack/3rd-party/class-jetpack-bbpress-rest-api.php new file mode 100644 index 00000000..4943bcd5 --- /dev/null +++ b/plugins/jetpack/3rd-party/class-jetpack-bbpress-rest-api.php @@ -0,0 +1,161 @@ +<?php +/** + * REST API Compatibility: bbPress & Jetpack + * Enables bbPress to work with the Jetpack REST API + * + * @package automattic/jetpack + */ + +/** + * REST API Compatibility: bbPress. + */ +class Jetpack_BbPress_REST_API { + + /** + * Singleton + * + * @var Jetpack_BbPress_REST_API. + */ + private static $instance; + + /** + * Returns or creates the singleton. + * + * @return Jetpack_BbPress_REST_API + */ + public static function instance() { + if ( isset( self::$instance ) ) { + return self::$instance; + } + + self::$instance = new self(); + } + + /** + * Jetpack_BbPress_REST_API constructor. + */ + private function __construct() { + add_filter( 'rest_api_allowed_post_types', array( $this, 'allow_bbpress_post_types' ) ); + add_filter( 'bbp_map_meta_caps', array( $this, 'adjust_meta_caps' ), 10, 4 ); + add_filter( 'rest_api_allowed_public_metadata', array( $this, 'allow_bbpress_public_metadata' ) ); + } + + /** + * Adds the bbPress post types to the rest_api_allowed_post_types filter. + * + * @param array $allowed_post_types Allowed post types. + * + * @return array + */ + public function allow_bbpress_post_types( $allowed_post_types ) { + $allowed_post_types[] = 'forum'; + $allowed_post_types[] = 'topic'; + $allowed_post_types[] = 'reply'; + return $allowed_post_types; + } + + /** + * Adds the bbpress meta keys to the rest_api_allowed_public_metadata filter. + * + * @param array $allowed_meta_keys Allowed meta keys. + * + * @return array + */ + public function allow_bbpress_public_metadata( $allowed_meta_keys ) { + $allowed_meta_keys[] = '_bbp_forum_id'; + $allowed_meta_keys[] = '_bbp_topic_id'; + $allowed_meta_keys[] = '_bbp_status'; + $allowed_meta_keys[] = '_bbp_forum_type'; + $allowed_meta_keys[] = '_bbp_forum_subforum_count'; + $allowed_meta_keys[] = '_bbp_reply_count'; + $allowed_meta_keys[] = '_bbp_total_reply_count'; + $allowed_meta_keys[] = '_bbp_topic_count'; + $allowed_meta_keys[] = '_bbp_total_topic_count'; + $allowed_meta_keys[] = '_bbp_topic_count_hidden'; + $allowed_meta_keys[] = '_bbp_last_topic_id'; + $allowed_meta_keys[] = '_bbp_last_reply_id'; + $allowed_meta_keys[] = '_bbp_last_active_time'; + $allowed_meta_keys[] = '_bbp_last_active_id'; + $allowed_meta_keys[] = '_bbp_sticky_topics'; + $allowed_meta_keys[] = '_bbp_voice_count'; + $allowed_meta_keys[] = '_bbp_reply_count_hidden'; + $allowed_meta_keys[] = '_bbp_anonymous_reply_count'; + + return $allowed_meta_keys; + } + + /** + * Adds the needed caps to the bbp_map_meta_caps filter. + * + * @param array $caps Capabilities for meta capability. + * @param string $cap Capability name. + * @param int $user_id User id. + * @param array $args Arguments. + * + * @return array + */ + public function adjust_meta_caps( $caps, $cap, $user_id, $args ) { + + // Return early if not a REST request or if not meta bbPress caps. + if ( $this->should_adjust_meta_caps_return_early( $caps, $cap, $user_id, $args ) ) { + return $caps; + } + + // $args[0] could be a post ID or a post_type string. + if ( is_int( $args[0] ) ) { + $_post = get_post( $args[0] ); + if ( ! empty( $_post ) ) { + $post_type = get_post_type_object( $_post->post_type ); + } + } elseif ( is_string( $args[0] ) ) { + $post_type = get_post_type_object( $args[0] ); + } + + // no post type found, bail. + if ( empty( $post_type ) ) { + return $caps; + } + + // reset the needed caps. + $caps = array(); + + // Add 'do_not_allow' cap if user is spam or deleted. + if ( bbp_is_user_inactive( $user_id ) ) { + $caps[] = 'do_not_allow'; + + // Moderators can always edit meta. + } elseif ( user_can( $user_id, 'moderate' ) ) { + $caps[] = 'moderate'; + + // Unknown so map to edit_posts. + } else { + $caps[] = $post_type->cap->edit_posts; + } + + return $caps; + } + + /** + * Should adjust_meta_caps return early? + * + * @param array $caps Capabilities for meta capability. + * @param string $cap Capability name. + * @param int $user_id User id. + * @param array $args Arguments. + * + * @return bool + */ + private function should_adjust_meta_caps_return_early( $caps, $cap, $user_id, $args ) { + // only run for REST API requests. + if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST ) { + return true; + } + + // only modify caps for meta caps and for bbPress meta keys. + if ( ! in_array( $cap, array( 'edit_post_meta', 'delete_post_meta', 'add_post_meta' ), true ) || empty( $args[1] ) || false === strpos( $args[1], '_bbp_' ) ) { + return true; + } + + return false; + } +} diff --git a/plugins/jetpack/3rd-party/class-jetpack-crm-data.php b/plugins/jetpack/3rd-party/class-jetpack-crm-data.php new file mode 100644 index 00000000..21c01ce5 --- /dev/null +++ b/plugins/jetpack/3rd-party/class-jetpack-crm-data.php @@ -0,0 +1,77 @@ +<?php +/** + * Compatibility functions for the Jetpack CRM plugin. + * + * @since 9.0.0 + * + * @package automattic/jetpack + */ + +namespace Automattic\Jetpack; + +/** + * Provides Jetpack CRM plugin data. + */ +class Jetpack_CRM_Data { + + const JETPACK_CRM_PLUGIN_SLUG = 'zero-bs-crm/ZeroBSCRM.php'; + + /** + * Provides Jetpack CRM plugin data for use in the Contact Form block sidebar menu. + * + * @return array An array containing the Jetpack CRM plugin data. + */ + public function get_crm_data() { + jetpack_require_lib( 'plugins' ); + $plugins = \Jetpack_Plugins::get_plugins(); + + // Set default values. + $response = array( + 'crm_installed' => false, + 'crm_active' => false, + 'crm_version' => null, + 'jp_form_ext_enabled' => null, + 'can_install_crm' => false, + 'can_activate_crm' => false, + 'can_activate_extension' => false, + ); + + if ( isset( $plugins[ self::JETPACK_CRM_PLUGIN_SLUG ] ) ) { + $response['crm_installed'] = true; + + $crm_data = $plugins[ self::JETPACK_CRM_PLUGIN_SLUG ]; + + $response['crm_active'] = $crm_data['active']; + $response['crm_version'] = $crm_data['Version']; + + if ( $response['crm_active'] ) { + if ( function_exists( 'zeroBSCRM_isExtensionInstalled' ) ) { + $response['jp_form_ext_enabled'] = zeroBSCRM_isExtensionInstalled( 'jetpackforms' ); + } + } + } + + $response['can_install_crm'] = $response['crm_installed'] ? false : current_user_can( 'install_plugins' ); + $response['can_activate_crm'] = $response['crm_active'] ? false : current_user_can( 'activate_plugins' ); + + if ( $response['crm_active'] && function_exists( 'zeroBSCRM_extension_install_jetpackforms' ) ) { + $response['can_activate_extension'] = current_user_can( 'admin_zerobs_manage_options' ); + } + + return $response; + } + + /** + * Activates Jetpack CRM's Jetpack Forms extension. This is used by a button in the Jetpack Contact Form + * sidebar menu. + * + * @return true|WP_Error Returns true if activation is success, else returns a WP_Error object. + */ + public function activate_crm_jetpackforms_extension() { + if ( function_exists( 'zeroBSCRM_extension_install_jetpackforms' ) ) { + return zeroBSCRM_extension_install_jetpackforms(); + } + + return new WP_Error( 'jp_forms_extension_activation_failed', esc_html__( 'The Jetpack Forms extension could not be activated.', 'jetpack' ) ); + } +} diff --git a/plugins/jetpack/3rd-party/class-jetpack-modules-overrides.php b/plugins/jetpack/3rd-party/class-jetpack-modules-overrides.php new file mode 100644 index 00000000..cd576ac1 --- /dev/null +++ b/plugins/jetpack/3rd-party/class-jetpack-modules-overrides.php @@ -0,0 +1,148 @@ +<?php +/** + * Special cases for overriding modules. + * + * @package automattic/jetpack + */ + +/** + * Provides methods for dealing with module overrides. + * + * @since 5.9.0 + */ +class Jetpack_Modules_Overrides { + /** + * Used to cache module overrides so that we minimize how many times we apply the + * option_jetpack_active_modules filter. + * + * @var null|array + */ + private $overrides = null; + + /** + * Clears the $overrides member used for caching. + * + * Since get_overrides() can be passed a falsey value to skip caching, this is probably + * most useful for clearing cache between tests. + * + * @return void + */ + public function clear_cache() { + $this->overrides = null; + } + + /** + * Returns true if there is a filter on the jetpack_active_modules option. + * + * @return bool Whether there is a filter on the jetpack_active_modules option. + */ + public function do_overrides_exist() { + return (bool) ( has_filter( 'option_jetpack_active_modules' ) || has_filter( 'jetpack_active_modules' ) ); + } + + /** + * Gets the override for a given module. + * + * @param string $module_slug The module's slug. + * @param boolean $use_cache Whether or not cached overrides should be used. + * + * @return bool|string False if no override for module. 'active' or 'inactive' if there is an override. + */ + public function get_module_override( $module_slug, $use_cache = true ) { + $overrides = $this->get_overrides( $use_cache ); + + if ( ! isset( $overrides[ $module_slug ] ) ) { + return false; + } + + return $overrides[ $module_slug ]; + } + + /** + * Returns an array of module overrides where the key is the module slug and the value + * is true if the module is forced on and false if the module is forced off. + * + * @param bool $use_cache Whether or not cached overrides should be used. + * + * @return array The array of module overrides. + */ + public function get_overrides( $use_cache = true ) { + if ( $use_cache && ! is_null( $this->overrides ) ) { + return $this->overrides; + } + + if ( ! $this->do_overrides_exist() ) { + return array(); + } + + $available_modules = Jetpack::get_available_modules(); + + /** + * First, let's get all modules that have been forced on. + */ + + /** This filter is documented in wp-includes/option.php */ + $filtered = apply_filters( 'option_jetpack_active_modules', array() ); + + /** This filter is documented in class.jetpack.php */ + $filtered = apply_filters( 'jetpack_active_modules', $filtered ); + + $forced_on = array_diff( $filtered, array() ); + + /** + * Second, let's get all modules forced off. + */ + + /** This filter is documented in wp-includes/option.php */ + $filtered = apply_filters( 'option_jetpack_active_modules', $available_modules ); + + /** This filter is documented in class.jetpack.php */ + $filtered = apply_filters( 'jetpack_active_modules', $filtered ); + + $forced_off = array_diff( $available_modules, $filtered ); + + /** + * Last, build the return value. + */ + $return_value = array(); + foreach ( $forced_on as $on ) { + $return_value[ $on ] = 'active'; + } + + foreach ( $forced_off as $off ) { + $return_value[ $off ] = 'inactive'; + } + + $this->overrides = $return_value; + + return $return_value; + } + + /** + * A reference to an instance of this class. + * + * @var Jetpack_Modules_Overrides + */ + private static $instance = null; + + /** + * Returns the singleton instance of Jetpack_Modules_Overrides + * + * @return Jetpack_Modules_Overrides + */ + public static function instance() { + if ( is_null( self::$instance ) ) { + self::$instance = new Jetpack_Modules_Overrides(); + } + + return self::$instance; + } + + /** + * Private construct to enforce singleton. + */ + private function __construct() { + } +} + +Jetpack_Modules_Overrides::instance(); diff --git a/plugins/jetpack/3rd-party/class.jetpack-amp-support.php b/plugins/jetpack/3rd-party/class.jetpack-amp-support.php index bf8d19f5..304f4ebd 100644 --- a/plugins/jetpack/3rd-party/class.jetpack-amp-support.php +++ b/plugins/jetpack/3rd-party/class.jetpack-amp-support.php @@ -1,5 +1,6 @@ <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName +use Automattic\Jetpack\Assets; use Automattic\Jetpack\Sync\Functions; /** @@ -31,6 +32,13 @@ class Jetpack_AMP_Support { // Sharing. add_filter( 'jetpack_sharing_display_markup', array( 'Jetpack_AMP_Support', 'render_sharing_html' ), 10, 2 ); add_filter( 'sharing_enqueue_scripts', array( 'Jetpack_AMP_Support', 'amp_disable_sharedaddy_css' ) ); + add_action( 'wp_enqueue_scripts', array( 'Jetpack_AMP_Support', 'amp_enqueue_sharing_css' ) ); + + // Sharing for Reader mode. + if ( function_exists( 'jetpack_social_menu_include_svg_icons' ) ) { + add_action( 'amp_post_template_footer', 'jetpack_social_menu_include_svg_icons' ); + } + add_action( 'amp_post_template_css', array( 'Jetpack_AMP_Support', 'amp_reader_sharing_css' ), 10, 0 ); // enforce freedom mode for videopress. add_filter( 'videopress_shortcode_options', array( 'Jetpack_AMP_Support', 'videopress_enable_freedom_mode' ) ); @@ -41,11 +49,32 @@ class Jetpack_AMP_Support { // Post rendering changes for legacy AMP. add_action( 'pre_amp_render_post', array( 'Jetpack_AMP_Support', 'amp_disable_the_content_filters' ) ); + // Disable Comment Likes. + add_filter( 'jetpack_comment_likes_enabled', array( 'Jetpack_AMP_Support', 'comment_likes_enabled' ) ); + + // Transitional mode AMP should not have comment likes. + add_filter( 'the_content', array( 'Jetpack_AMP_Support', 'disable_comment_likes_before_the_content' ) ); + + // Remove the Likes button from the admin bar. + add_filter( 'jetpack_admin_bar_likes_enabled', array( 'Jetpack_AMP_Support', 'disable_likes_admin_bar' ) ); + // Add post template metadata for legacy AMP. add_filter( 'amp_post_template_metadata', array( 'Jetpack_AMP_Support', 'amp_post_template_metadata' ), 10, 2 ); // Filter photon image args for AMP Stories. add_filter( 'jetpack_photon_post_image_args', array( 'Jetpack_AMP_Support', 'filter_photon_post_image_args_for_stories' ), 10, 2 ); + + // Sync the amp-options. + add_filter( 'jetpack_options_whitelist', array( 'Jetpack_AMP_Support', 'filter_jetpack_options_safelist' ) ); + } + + /** + * Disable the Comment Likes feature on AMP views. + * + * @param bool $enabled Should comment likes be enabled. + */ + public static function comment_likes_enabled( $enabled ) { + return $enabled && ! self::is_amp_request(); } /** @@ -67,6 +96,16 @@ class Jetpack_AMP_Support { } /** + * Is AMP available for this request + * This returns false for admin, CLI requests etc. + * + * @return bool is_amp_available + */ + public static function is_amp_available() { + return ( function_exists( 'amp_is_available' ) && amp_is_available() ); + } + + /** * Does the page return AMP content. * * @return bool $is_amp_request Are we on am AMP view. @@ -99,6 +138,30 @@ class Jetpack_AMP_Support { } /** + * Do not add comment likes on AMP requests. + * + * @param string $content Post content. + */ + public static function disable_comment_likes_before_the_content( $content ) { + if ( self::is_amp_request() ) { + remove_filter( 'comment_text', 'comment_like_button', 12, 2 ); + } + return $content; + } + + /** + * Do not display the Likes' Admin bar on AMP requests. + * + * @param bool $is_admin_bar_button_visible Should the Like button be visible in the Admin bar. Default to true. + */ + public static function disable_likes_admin_bar( $is_admin_bar_button_visible ) { + if ( self::is_amp_request() ) { + return false; + } + return $is_admin_bar_button_visible; + } + + /** * Add Jetpack stats pixel. * * @since 6.2.1 @@ -124,7 +187,7 @@ class Jetpack_AMP_Support { $metadata = self::add_site_icon_to_metadata( $metadata ); } - if ( ! isset( $metadata['image'] ) ) { + if ( ! isset( $metadata['image'] ) && ! empty( $post ) ) { $metadata = self::add_image_to_metadata( $metadata, $post ); } @@ -247,7 +310,7 @@ class Jetpack_AMP_Support { if ( function_exists( 'staticize_subdomain' ) ) { return staticize_subdomain( $domain ); } else { - return Jetpack::staticize_subdomain( $domain ); + return Assets::staticize_subdomain( $domain ); } } @@ -260,10 +323,10 @@ class Jetpack_AMP_Support { * @return array Dimensions. */ private static function extract_image_dimensions_from_getimagesize( $dimensions ) { - if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'require_lib' ) ) ) { + if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'jetpack_require_lib' ) ) ) { return $dimensions; } - require_lib( 'wpcom/imagesize' ); + jetpack_require_lib( 'wpcom/imagesize' ); foreach ( $dimensions as $url => $value ) { if ( is_array( $value ) ) { @@ -313,6 +376,12 @@ class Jetpack_AMP_Support { * @param array $sharing_enabled Array of Sharing Services currently enabled. */ public static function render_sharing_html( $markup, $sharing_enabled ) { + global $post; + + if ( empty( $post ) ) { + return ''; + } + if ( ! self::is_amp_request() ) { return $markup; } @@ -321,39 +390,17 @@ class Jetpack_AMP_Support { if ( empty( $sharing_enabled ) ) { return $markup; } - $supported_services = array( - 'facebook' => array( - /** This filter is documented in modules/sharedaddy/sharing-sources.php */ - 'data-param-app_id' => apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ), - ), - 'twitter' => array(), - 'pinterest' => array(), - 'whatsapp' => array(), - 'tumblr' => array(), - 'linkedin' => array(), - ); - $sharing_links = array(); - foreach ( $sharing_enabled['visible'] as $id => $service ) { - if ( ! isset( $supported_services[ $id ] ) ) { - $sharing_links[] = "<!-- not supported: $id -->"; - continue; - } - $args = array_merge( - array( - 'type' => $id, - ), - $supported_services[ $id ] - ); - $sharing_link = '<amp-social-share'; - foreach ( $args as $key => $value ) { - $sharing_link .= sprintf( ' %s="%s"', sanitize_key( $key ), esc_attr( $value ) ); + + $sharing_links = array(); + foreach ( $sharing_enabled['visible'] as $service ) { + $sharing_link = $service->get_amp_display( $post ); + if ( ! empty( $sharing_link ) ) { + $sharing_links[] = $sharing_link; } - $sharing_link .= '></amp-social-share>'; - $sharing_links[] = $sharing_link; } - // Wrap AMP sharing buttons in container. - $markup = preg_replace( '#(?<=<div class="sd-content">).+?(?=</div>)#s', implode( '', $sharing_links ), $markup ); + // Replace the existing unordered list with AMP sharing buttons. + $markup = preg_replace( '#<ul>(.+)</ul>#', implode( '', $sharing_links ), $markup ); // Remove any lingering share-end list items. $markup = str_replace( '<li class="share-end"></li>', '', $markup ); @@ -376,6 +423,43 @@ class Jetpack_AMP_Support { } /** + * Enqueues the AMP specific sharing styles for the sharing icons. + */ + public static function amp_enqueue_sharing_css() { + if ( self::is_amp_request() ) { + wp_enqueue_style( 'sharedaddy-amp', plugin_dir_url( __DIR__ ) . 'modules/sharedaddy/amp-sharing.css', array( 'social-logos' ), JETPACK__VERSION ); + } + } + + /** + * For the AMP Reader mode template, include styles that we need. + */ + public static function amp_reader_sharing_css() { + // If sharing is not enabled, we should not proceed to render the CSS. + if ( ! defined( 'JETPACK_SOCIAL_LOGOS_DIR' ) | ! defined( 'JETPACK_SOCIAL_LOGOS_URL' ) || ! defined( 'WP_SHARING_PLUGIN_DIR' ) ) { + return; + } + + /* + * We'll need to output the full contents of the 2 files + * in the head on AMP views. We can't rely on regular enqueues here. + * @todo As of AMP plugin v1.5, you can actually rely on regular enqueues thanks to https://github.com/ampproject/amp-wp/pull/4299. Once WPCOM upgrades AMP, then this method can be eliminated. + * + * phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + * phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped + */ + $css = file_get_contents( JETPACK_SOCIAL_LOGOS_DIR . 'social-logos.css' ); + $css = preg_replace( '#(?<=url\(")(?=social-logos\.)#', JETPACK_SOCIAL_LOGOS_URL, $css ); // Make sure font files get their absolute paths. + echo $css; + echo file_get_contents( WP_SHARING_PLUGIN_DIR . 'amp-sharing.css' ); + + /* + * phpcs:enable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + * phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped + */ + } + + /** * Ensure proper Photon image dimensions for AMP Stories. * * @param array $args Array of Photon Arguments. @@ -442,6 +526,20 @@ class Jetpack_AMP_Support { return $args; } + + /** + * Adds amp-options to the list of options to sync, if AMP is available + * + * @param array $options_safelist Safelist of options to sync. + * + * @return array Updated options safelist + */ + public static function filter_jetpack_options_safelist( $options_safelist ) { + if ( function_exists( 'is_amp_endpoint' ) ) { + $options_safelist[] = 'amp-options'; + } + return $options_safelist; + } } add_action( 'init', array( 'Jetpack_AMP_Support', 'init' ), 1 ); diff --git a/plugins/jetpack/3rd-party/creative-mail.php b/plugins/jetpack/3rd-party/creative-mail.php new file mode 100644 index 00000000..957a8a2d --- /dev/null +++ b/plugins/jetpack/3rd-party/creative-mail.php @@ -0,0 +1,128 @@ +<?php +/** + * Compatibility functions for the Creative Mail plugin. + * https://wordpress.org/plugins/creative-mail-by-constant-contact/ + * + * @since 8.9.0 + * + * @package automattic/jetpack + */ + +namespace Automattic\Jetpack\Creative_Mail; + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +const PLUGIN_SLUG = 'creative-mail-by-constant-contact'; +const PLUGIN_FILE = 'creative-mail-by-constant-contact/creative-mail-plugin.php'; + +add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' ); +add_action( 'admin_init', __NAMESPACE__ . '\try_install' ); +add_action( 'jetpack_activated_plugin', __NAMESPACE__ . '\configure_plugin', 10, 2 ); + +/** + * Verify the intent to install Creative Mail, and kick off installation. + * + * This works in tandem with a JITM set up in the JITM package. + */ +function try_install() { + if ( ! isset( $_GET['creative-mail-action'] ) ) { + return; + } + + check_admin_referer( 'creative-mail-install' ); + + $result = false; + $redirect = admin_url( 'edit.php?post_type=feedback' ); + + // Attempt to install and activate the plugin. + if ( current_user_can( 'activate_plugins' ) ) { + switch ( $_GET['creative-mail-action'] ) { + case 'install': + $result = install_and_activate(); + break; + case 'activate': + $result = activate(); + break; + } + } + + if ( $result ) { + /** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */ + do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' ); + $redirect = admin_url( 'admin.php?page=creativemail' ); + } else { + $redirect = add_query_arg( 'creative-mail-install-error', true, $redirect ); + } + + wp_safe_redirect( $redirect ); + + exit; +} + +/** + * Install and activate the Creative Mail plugin. + * + * @return bool result of installation + */ +function install_and_activate() { + jetpack_require_lib( 'plugins' ); + $result = \Jetpack_Plugins::install_and_activate_plugin( PLUGIN_SLUG ); + + if ( is_wp_error( $result ) ) { + return false; + } else { + return true; + } +} + +/** + * Activate the Creative Mail plugin. + * + * @return bool result of activation + */ +function activate() { + $result = activate_plugin( PLUGIN_FILE ); + + // Activate_plugin() returns null on success. + return is_null( $result ); +} + +/** + * Notify the user that the installation of Creative Mail failed. + */ +function error_notice() { + if ( empty( $_GET['creative-mail-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return; + } + + ?> + <div class="notice notice-error is-dismissible"> + <p><?php esc_html_e( 'There was an error installing Creative Mail.', 'jetpack' ); ?></p> + </div> + <?php +} + +/** + * Set some options when first activating the plugin via Jetpack. + * + * @since 8.9.0 + * + * @param string $plugin_file Plugin file. + * @param string $source Where did the plugin installation originate. + */ +function configure_plugin( $plugin_file, $source ) { + if ( PLUGIN_FILE !== $plugin_file ) { + return; + } + + $plugin_info = array( + 'plugin' => 'jetpack', + 'version' => JETPACK__VERSION, + 'time' => time(), + 'source' => esc_attr( $source ), + ); + + update_option( 'ce4wp_referred_by', $plugin_info ); +} diff --git a/plugins/jetpack/3rd-party/crowdsignal.php b/plugins/jetpack/3rd-party/crowdsignal.php new file mode 100644 index 00000000..dbeef8b3 --- /dev/null +++ b/plugins/jetpack/3rd-party/crowdsignal.php @@ -0,0 +1,23 @@ +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName +/** + * Fallback for the Crowdsignal Plugin. + * + * The PollDaddy/Crowdsignal prior to v. 2.033 called Jetpack_Sync as long as the Jetpack class was present. This stub is provided to prevent any fatals for older versions of the plugin. + * This was resolved in 2016, but need to do just a little research before ripping it out. + * + * @see https://github.com/Automattic/crowdsignal-plugin/commit/941fc5758152ebf860a14d1cd0058245e8aed86b + * + * @package automattic/jetpack + */ + +/** + * Stub of Jetpack_Sync for Crowdsignal. + */ +class Jetpack_Sync { + /** + * Stub of sync_options to prevent fatals for Crowdsignal. + */ + public static function sync_options() { + _deprecated_function( __METHOD__, 'jetpack-4.2', 'jetpack_options_whitelist filter' ); + } +} diff --git a/plugins/jetpack/3rd-party/debug-bar.php b/plugins/jetpack/3rd-party/debug-bar.php index a6449903..45f20dc9 100644 --- a/plugins/jetpack/3rd-party/debug-bar.php +++ b/plugins/jetpack/3rd-party/debug-bar.php @@ -1,4 +1,9 @@ <?php +/** + * 3rd Party integration for Debug Bar. + * + * @package automattic/jetpack + */ /** * Checks if the search module is active, and if so, will initialize the singleton instance @@ -12,7 +17,7 @@ function init_jetpack_search_debug_bar( $panels ) { return $panels; } - require_once dirname( __FILE__ ) . '/debug-bar/class.jetpack-search-debug-bar.php'; + require_once __DIR__ . '/debug-bar/class-jetpack-search-debug-bar.php'; $panels[] = Jetpack_Search_Debug_Bar::instance(); return $panels; } diff --git a/plugins/jetpack/3rd-party/debug-bar/class-jetpack-search-debug-bar.php b/plugins/jetpack/3rd-party/debug-bar/class-jetpack-search-debug-bar.php new file mode 100644 index 00000000..73e272c3 --- /dev/null +++ b/plugins/jetpack/3rd-party/debug-bar/class-jetpack-search-debug-bar.php @@ -0,0 +1,184 @@ +<?php +/** + * Adds a Jetpack Search debug panel to Debug Bar. + * + * @package automattic/jetpack + */ + +/** + * Singleton class instantiated by Jetpack_Searc_Debug_Bar::instance() that handles + * rendering the Jetpack Search debug bar menu item and panel. + */ +class Jetpack_Search_Debug_Bar extends Debug_Bar_Panel { + /** + * Holds singleton instance + * + * @var Jetpack_Search_Debug_Bar + */ + protected static $instance = null; + + /** + * The title to use in the debug bar navigation + * + * @var string + */ + public $title; + + /** + * Constructor + */ + public function __construct() { + $this->title( esc_html__( 'Jetpack Search', 'jetpack' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'login_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'enqueue_embed_scripts', array( $this, 'enqueue_scripts' ) ); + } + + /** + * Returns the singleton instance of Jetpack_Search_Debug_Bar + * + * @return Jetpack_Search_Debug_Bar + */ + public static function instance() { + if ( is_null( self::$instance ) ) { + self::$instance = new Jetpack_Search_Debug_Bar(); + } + return self::$instance; + } + + /** + * Enqueues styles for our panel in the debug bar + * + * @return void + */ + public function enqueue_scripts() { + // Do not enqueue scripts if we haven't already enqueued Debug Bar or Query Monitor styles. + if ( ! wp_style_is( 'debug-bar' ) && ! wp_style_is( 'query-monitor' ) ) { + return; + } + + wp_enqueue_style( + 'jetpack-search-debug-bar', + plugins_url( '3rd-party/debug-bar/debug-bar.css', JETPACK__PLUGIN_FILE ), + array(), + JETPACK__VERSION + ); + wp_enqueue_script( + 'jetpack-search-debug-bar', + plugins_url( '3rd-party/debug-bar/debug-bar.js', JETPACK__PLUGIN_FILE ), + array( 'jquery' ), + JETPACK__VERSION, + true + ); + } + + /** + * Should the Jetpack Search Debug Bar show? + * + * Since we've previously done a check for the search module being activated, let's just return true. + * Later on, we can update this to only show when `is_search()` is true. + * + * @return boolean + */ + public function is_visible() { + return true; + } + + /** + * Renders the panel content + * + * @return void + */ + public function render() { + if ( ! class_exists( 'Jetpack_Search' ) ) { + return; + } + + $jetpack_search = Jetpack_Search::instance(); + $last_query_info = $jetpack_search->get_last_query_info(); + + // If not empty, let's reshuffle the order of some things. + if ( ! empty( $last_query_info ) ) { + $args = $last_query_info['args']; + $response = $last_query_info['response']; + $response_code = $last_query_info['response_code']; + + unset( $last_query_info['args'] ); + unset( $last_query_info['response'] ); + unset( $last_query_info['response_code'] ); + + if ( is_null( $last_query_info['es_time'] ) ) { + $last_query_info['es_time'] = esc_html_x( + 'cache hit', + 'displayed in search results when results are cached', + 'jetpack' + ); + } + + $temp = array_merge( + array( 'response_code' => $response_code ), + array( 'args' => $args ), + $last_query_info, + array( 'response' => $response ) + ); + + $last_query_info = $temp; + } + ?> + <div class="jetpack-search-debug-bar"> + <h2><?php esc_html_e( 'Last query information:', 'jetpack' ); ?></h2> + <?php if ( empty( $last_query_info ) ) : ?> + <?php echo esc_html_x( 'None', 'Text displayed when there is no information', 'jetpack' ); ?> + <?php + else : + foreach ( $last_query_info as $key => $info ) : + ?> + <h3><?php echo esc_html( $key ); ?></h3> + <?php + if ( 'response' !== $key && 'args' !== $key ) : + ?> + <pre><?php print_r( esc_html( $info ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions ?></pre> + <?php + else : + $this->render_json_toggle( $info ); + endif; + ?> + <?php + endforeach; + endif; + ?> + </div><!-- Closes .jetpack-search-debug-bar --> + <?php + } + + /** + * Responsible for rendering the HTML necessary for the JSON toggle + * + * @param array $value The resonse from the API as an array. + * @return void + */ + public function render_json_toggle( $value ) { + ?> + <div class="json-toggle-wrap"> + <pre class="json"> + <?php + // esc_html() will not double-encode entities (& -> &amp;). + // If any entities are part of the JSON blob, we want to re-encoode them + // (double-encode them) so that they are displayed correctly in the debug + // bar. + // Use _wp_specialchars() "manually" to ensure entities are encoded correctly. + echo _wp_specialchars( // phpcs:ignore WordPress.Security.EscapeOutput + wp_json_encode( $value ), + ENT_NOQUOTES, // Don't need to encode quotes (output is for a text node). + 'UTF-8', // wp_json_encode() outputs UTF-8 (really just ASCII), not the blog's charset. + true // Do "double-encode" existing HTML entities. + ); + ?> + </pre> + <span class="pretty toggle"><?php echo esc_html_x( 'Pretty', 'label for formatting JSON', 'jetpack' ); ?></span> + <span class="ugly toggle"><?php echo esc_html_x( 'Minify', 'label for formatting JSON', 'jetpack' ); ?></span> + </div> + <?php + } +} diff --git a/plugins/jetpack/3rd-party/jetpack-backup.php b/plugins/jetpack/3rd-party/jetpack-backup.php new file mode 100644 index 00000000..ec1880b3 --- /dev/null +++ b/plugins/jetpack/3rd-party/jetpack-backup.php @@ -0,0 +1,105 @@ +<?php +/** + * Compatibility functions for the Jetpack Backup plugin. + * https://wordpress.org/plugins/jetpack-backup/ + * + * @since 10.4 + * + * @package automattic/jetpack + */ + +namespace Automattic\Jetpack\Jetpack_Backup; + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +const PLUGIN_SLUG = 'jetpack-backup'; +const PLUGIN_FILE = 'jetpack-backup/jetpack-backup.php'; + +add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' ); +add_action( 'admin_init', __NAMESPACE__ . '\try_install' ); + +/** + * Verify the intent to install Jetpack Backup, and kick off installation. + * + * This works in tandem with a JITM set up in the JITM package. + */ +function try_install() { + if ( ! isset( $_GET['jetpack-backup-action'] ) ) { + return; + } + + check_admin_referer( 'jetpack-backup-install' ); + + $result = false; + // If the plugin install fails, redirect to plugin install page pre-populated with jetpack-backup search term. + $redirect_on_error = admin_url( 'plugin-install.php?s=jetpack-backup&tab=search&type=term' ); + + // Attempt to install and activate the plugin. + if ( current_user_can( 'activate_plugins' ) ) { + switch ( $_GET['jetpack-backup-action'] ) { + case 'install': + $result = install_and_activate(); + break; + case 'activate': + $result = activate(); + break; + } + } + + if ( $result ) { + /** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */ + do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' ); + $redirect = admin_url( 'admin.php?page=jetpack-backup' ); + } else { + $redirect = add_query_arg( 'jetpack-backup-install-error', true, $redirect_on_error ); + } + + wp_safe_redirect( $redirect ); + + exit; +} + +/** + * Install and activate the Jetpack Backup plugin. + * + * @return bool result of installation + */ +function install_and_activate() { + jetpack_require_lib( 'plugins' ); + $result = \Jetpack_Plugins::install_and_activate_plugin( PLUGIN_SLUG ); + + if ( is_wp_error( $result ) ) { + return false; + } else { + return true; + } +} + +/** + * Activate the Jetpack Backup plugin. + * + * @return bool result of activation + */ +function activate() { + $result = activate_plugin( PLUGIN_FILE ); + + // Activate_plugin() returns null on success. + return is_null( $result ); +} + +/** + * Notify the user that the installation of Jetpack Backup failed. + */ +function error_notice() { + if ( empty( $_GET['jetpack-backup-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return; + } + + ?> + <div class="notice notice-error is-dismissible"> + <p><?php esc_html_e( 'There was an error installing Jetpack Backup. Please try again.', 'jetpack' ); ?></p> + </div> + <?php +} diff --git a/plugins/jetpack/3rd-party/jetpack-boost.php b/plugins/jetpack/3rd-party/jetpack-boost.php new file mode 100644 index 00000000..328078c1 --- /dev/null +++ b/plugins/jetpack/3rd-party/jetpack-boost.php @@ -0,0 +1,105 @@ +<?php +/** + * Compatibility functions for the Jetpack Boost plugin. + * https://wordpress.org/plugins/jetpack-boost/ + * + * @since 10.4 + * + * @package automattic/jetpack + */ + +namespace Automattic\Jetpack\Jetpack_Boost; + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +const PLUGIN_SLUG = 'jetpack-boost'; +const PLUGIN_FILE = 'jetpack-boost/jetpack-boost.php'; + +add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' ); +add_action( 'admin_init', __NAMESPACE__ . '\try_install' ); + +/** + * Verify the intent to install Jetpack Boost, and kick off installation. + * + * This works in tandem with a JITM set up in the JITM package. + */ +function try_install() { + if ( ! isset( $_GET['jetpack-boost-action'] ) ) { + return; + } + + check_admin_referer( 'jetpack-boost-install' ); + + $result = false; + // If the plugin install fails, redirect to plugin install page pre-populated with jetpack-boost search term. + $redirect_on_error = admin_url( 'plugin-install.php?s=jetpack-boost&tab=search&type=term' ); + + // Attempt to install and activate the plugin. + if ( current_user_can( 'activate_plugins' ) ) { + switch ( $_GET['jetpack-boost-action'] ) { + case 'install': + $result = install_and_activate(); + break; + case 'activate': + $result = activate(); + break; + } + } + + if ( $result ) { + /** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */ + do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' ); + $redirect = admin_url( 'admin.php?page=jetpack-boost' ); + } else { + $redirect = add_query_arg( 'jetpack-boost-install-error', true, $redirect_on_error ); + } + + wp_safe_redirect( $redirect ); + + exit; +} + +/** + * Install and activate the Jetpack Boost plugin. + * + * @return bool result of installation + */ +function install_and_activate() { + jetpack_require_lib( 'plugins' ); + $result = \Jetpack_Plugins::install_and_activate_plugin( PLUGIN_SLUG ); + + if ( is_wp_error( $result ) ) { + return false; + } else { + return true; + } +} + +/** + * Activate the Jetpack Boost plugin. + * + * @return bool result of activation + */ +function activate() { + $result = activate_plugin( PLUGIN_FILE ); + + // Activate_plugin() returns null on success. + return is_null( $result ); +} + +/** + * Notify the user that the installation of Jetpack Boost failed. + */ +function error_notice() { + if ( empty( $_GET['jetpack-boost-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return; + } + + ?> + <div class="notice notice-error is-dismissible"> + <p><?php esc_html_e( 'There was an error installing Jetpack Boost. Please try again.', 'jetpack' ); ?></p> + </div> + <?php +} diff --git a/plugins/jetpack/3rd-party/qtranslate-x.php b/plugins/jetpack/3rd-party/qtranslate-x.php index 07390b05..38b06582 100644 --- a/plugins/jetpack/3rd-party/qtranslate-x.php +++ b/plugins/jetpack/3rd-party/qtranslate-x.php @@ -1,12 +1,18 @@ <?php /** + * 3rd party integration for qTranslate. + * + * @package automattic/jetpack + */ + +/** * Prevent qTranslate X from redirecting REST calls. * * @since 5.3 * * @param string $url_lang Language URL to redirect to. * @param string $url_orig Original URL. - * @param array $url_info Pieces of original URL. + * @param array $url_info Pieces of original URL. * * @return bool */ diff --git a/plugins/jetpack/3rd-party/vaultpress.php b/plugins/jetpack/3rd-party/vaultpress.php index 0b71e6a4..0589f412 100644 --- a/plugins/jetpack/3rd-party/vaultpress.php +++ b/plugins/jetpack/3rd-party/vaultpress.php @@ -1,4 +1,11 @@ <?php +/** + * Handles VaultPress->Rewind transition by deactivating VaultPress when needed. + * + * @package automattic/jetpack + */ + +use Automattic\Jetpack\Redirect; /** * Notify user that VaultPress has been disabled. Hide VaultPress notice that requested attention. @@ -11,9 +18,7 @@ function jetpack_vaultpress_rewind_enabled_notice() { deactivate_plugins( 'vaultpress/vaultpress.php' ); // Remove WP core notice that says that the plugin was activated. - if ( isset( $_GET['activate'] ) ) { - unset( $_GET['activate'] ); - } + unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification ?> <div class="notice notice-success is-dismissible vp-deactivated"> <p style="margin-bottom: 0.25em;"><strong><?php esc_html_e( 'Jetpack is now handling your backups.', 'jetpack' ); ?></strong></p> @@ -22,8 +27,8 @@ function jetpack_vaultpress_rewind_enabled_notice() { <?php echo sprintf( wp_kses( - /* Translators: first variable is the URL of the web site without the protocol, e.g. mysite.com */ - __( 'You can access your backups on your site\'s <a href="https://wordpress.com/activity-log/%s" target="_blank" rel="noopener noreferrer">Activity</a> page.', 'jetpack' ), + /* Translators: first variable is the full URL to the new dashboard */ + __( 'You can access your backups at <a href="%s" target="_blank" rel="noopener noreferrer">this dashboard</a>.', 'jetpack' ), array( 'a' => array( 'href' => array(), @@ -32,7 +37,7 @@ function jetpack_vaultpress_rewind_enabled_notice() { ), ) ), - esc_attr( Jetpack::build_raw_urls( get_home_url() ) ) + esc_url( Redirect::get_url( 'calypso-backups' ) ) ); ?> </p> @@ -47,10 +52,11 @@ function jetpack_vaultpress_rewind_enabled_notice() { * @since 5.8 */ function jetpack_vaultpress_rewind_check() { - if ( Jetpack::is_active() && - Jetpack::is_plugin_active( 'vaultpress/vaultpress.php' ) && - Jetpack::is_rewind_enabled() - ) { + if ( + Jetpack::is_connection_ready() && + Jetpack::is_plugin_active( 'vaultpress/vaultpress.php' ) && + Jetpack::is_rewind_enabled() + ) { remove_submenu_page( 'jetpack', 'vaultpress' ); add_action( 'admin_notices', 'jetpack_vaultpress_rewind_enabled_notice' ); diff --git a/plugins/jetpack/3rd-party/web-stories.php b/plugins/jetpack/3rd-party/web-stories.php new file mode 100644 index 00000000..73619623 --- /dev/null +++ b/plugins/jetpack/3rd-party/web-stories.php @@ -0,0 +1,36 @@ +<?php +/** + * Compatibility functions for the Web Stories plugin. + * https://wordpress.org/plugins/web-stories/ + * + * @since 9.2.0 + * + * @package automattic/jetpack + */ + +namespace Automattic\Jetpack\Web_Stories; + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +/** + * Filter to enable web stories built in open graph data from being output. + * If Jetpack is already handling Open Graph Meta Tags, the Web Stories plugin will not output any. + * + * @param bool $enabled If web stories open graph data is enabled. + * + * @return bool + */ +function maybe_disable_open_graph( $enabled ) { + /** This filter is documented in class.jetpack.php */ + $jetpack_enabled = apply_filters( 'jetpack_enable_open_graph', false ); + + if ( $jetpack_enabled ) { + $enabled = false; + } + + return $enabled; +} +add_filter( 'web_stories_enable_open_graph_metadata', __NAMESPACE__ . '\maybe_disable_open_graph' ); +add_filter( 'web_stories_enable_twitter_metadata', __NAMESPACE__ . '\maybe_disable_open_graph' ); diff --git a/plugins/jetpack/3rd-party/woocommerce-services.php b/plugins/jetpack/3rd-party/woocommerce-services.php index bdf1014e..87212cdc 100644 --- a/plugins/jetpack/3rd-party/woocommerce-services.php +++ b/plugins/jetpack/3rd-party/woocommerce-services.php @@ -126,22 +126,14 @@ class WC_Services_Installer { * @return bool result of installation */ private function install() { - include_once ABSPATH . '/wp-admin/includes/admin.php'; - include_once ABSPATH . '/wp-admin/includes/plugin-install.php'; - include_once ABSPATH . '/wp-admin/includes/plugin.php'; - include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; - include_once ABSPATH . '/wp-admin/includes/class-plugin-upgrader.php'; + jetpack_require_lib( 'plugins' ); + $result = Jetpack_Plugins::install_plugin( 'woocommerce-services' ); - $api = plugins_api( 'plugin_information', array( 'slug' => 'woocommerce-services' ) ); - - if ( is_wp_error( $api ) ) { + if ( is_wp_error( $result ) ) { return false; + } else { + return true; } - - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); - $result = $upgrader->install( $api->download_link ); - - return true === $result; } /** diff --git a/plugins/jetpack/3rd-party/woocommerce.php b/plugins/jetpack/3rd-party/woocommerce.php index 78a307b6..321051ff 100644 --- a/plugins/jetpack/3rd-party/woocommerce.php +++ b/plugins/jetpack/3rd-party/woocommerce.php @@ -1,9 +1,17 @@ <?php /** * This file contains compatibility functions for WooCommerce to improve Jetpack feature support. + * + * @package automattic/jetpack */ + add_action( 'woocommerce_init', 'jetpack_woocommerce_integration' ); +/** + * Loads JP+WC integration. + * + * Fires on `woocommerce_init` hook + */ function jetpack_woocommerce_integration() { /** * Double check WooCommerce exists - unlikely to fail due to the hook being used but better safe than sorry. @@ -23,14 +31,14 @@ function jetpack_woocommerce_integration() { } } -/* +/** * Make sure the social sharing icons show up under the product's short description */ function jetpack_woocommerce_social_share_icons() { if ( function_exists( 'sharing_display' ) ) { remove_filter( 'the_content', 'sharing_display', 19 ); remove_filter( 'the_excerpt', 'sharing_display', 19 ); - echo sharing_display(); + sharing_display( '', true ); } } @@ -57,7 +65,7 @@ add_action( 'loop_start', 'jetpack_woocommerce_remove_share' ); /** * Add a callback for WooCommerce product rendering in infinite scroll. * - * @param array $callbacks + * @param array $callbacks Array of render callpacks for IS. * @return array */ function jetpack_woocommerce_infinite_scroll_render_callback( $callbacks ) { @@ -87,19 +95,35 @@ function jetpack_woocommerce_infinite_scroll_render() { * Basic styling when infinite scroll is active only. */ function jetpack_woocommerce_infinite_scroll_style() { - $custom_css = " + $custom_css = ' .infinite-scroll .woocommerce-pagination { display: none; - }"; + }'; wp_add_inline_style( 'woocommerce-layout', $custom_css ); } +/** + * Adds compat for WooCommerce and Lazy Loading. + */ function jetpack_woocommerce_lazy_images_compat() { - wp_add_inline_script( 'wc-cart-fragments', " + wp_add_inline_script( + 'wc-cart-fragments', + " jQuery( 'body' ).bind( 'wc_fragments_refreshed', function() { - jQuery( 'body' ).trigger( 'jetpack-lazy-images-load' ); + var jetpackLazyImagesLoadEvent; + try { + jetpackLazyImagesLoadEvent = new Event( 'jetpack-lazy-images-load', { + bubbles: true, + cancelable: true + } ); + } catch ( e ) { + jetpackLazyImagesLoadEvent = document.createEvent( 'Event' ) + jetpackLazyImagesLoadEvent.initEvent( 'jetpack-lazy-images-load', true, true ); + } + jQuery( 'body' ).get( 0 ).dispatchEvent( jetpackLazyImagesLoadEvent ); } ); - " ); + " + ); } add_action( 'wp_enqueue_scripts', 'jetpack_woocommerce_lazy_images_compat', 11 ); diff --git a/plugins/jetpack/3rd-party/wpml.php b/plugins/jetpack/3rd-party/wpml.php index 219cb37d..b6352f14 100644 --- a/plugins/jetpack/3rd-party/wpml.php +++ b/plugins/jetpack/3rd-party/wpml.php @@ -1,6 +1,8 @@ <?php /** * Only load these if WPML plugin is installed and active. + * + * @package automattic/jetpack */ /** @@ -17,13 +19,11 @@ add_action( 'wpml_loaded', 'wpml_jetpack_init' ); /** * Filter the Top Posts and Pages by language. * - * @param array $posts Array of the most popular posts. - * @param array $post_ids Array of Post IDs. - * @param string $count Number of Top Posts we want to display. + * @param array $posts Array of the most popular posts. * * @return array */ -function wpml_jetpack_widget_get_top_posts( $posts, $post_ids, $count ) { +function wpml_jetpack_widget_get_top_posts( $posts ) { global $sitepress; foreach ( $posts as $k => $post ) { @@ -42,13 +42,12 @@ function wpml_jetpack_widget_get_top_posts( $posts, $post_ids, $count ) { /** * Filter the HTML of the Contact Form and output the one requested by language. * - * @param string $r Contact Form HTML output. - * @param string $field_label Field label. - * @param int|null $id Post ID. + * @param string $r Contact Form HTML output. + * @param string $field_label Field label. * * @return string */ -function grunion_contact_form_field_html_filter( $r, $field_label, $id ){ +function grunion_contact_form_field_html_filter( $r, $field_label ) { global $sitepress; if ( function_exists( 'icl_translate' ) ) { |