debar( $request['id'] ); if ( $sidebar && $this->check_read_permission( $sidebar ) ) { return true; } return $this->do_permissions_check(); } /** * Checks if a sidebar can be read publicly. * * @since 5.9.0 * * @param array $sidebar The registered sidebar configuration. * @return bool Whether the side can be read. */ protected function check_read_permission( $sidebar ) { return ! empty( $sidebar['show_in_rest'] ); } /** * Retrieves one sidebar from the collection. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function get_item( $request ) { $this->retrieve_widgets(); $sidebar = $this->get_sidebar( $request['id'] ); if ( ! $sidebar ) { return new WP_Error( 'rest_sidebar_not_found', __( 'No sidebar exists with that id.' ), array( 'status' => 404 ) ); } return $this->prepare_item_for_response( $sidebar, $request ); } /** * Checks if a given request has access to update sidebars. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ public function update_item_permissions_check( $request ) { return $this->do_permissions_check(); } /** * Updates a sidebar. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response Response object on success, or WP_Error object on failure. */ public function update_item( $request ) { if ( isset( $request['widgets'] ) ) { $sidebars = wp_get_sidebars_widgets(); foreach ( $sidebars as $sidebar_id => $widgets ) { foreach ( $widgets as $i => $widget_id ) { // This automatically removes the passed widget IDs from any other sidebars in use. if ( $sidebar_id !== $request['id'] && in_array( $widget_id, $request['widgets'], true ) ) { unset( $sidebars[ $sidebar_id ][ $i ] ); } // This automatically removes omitted widget IDs to the inactive sidebar. if ( $sidebar_id === $request['id'] && ! in_array( $widget_id, $request['widgets'], true ) ) { $sidebars['wp_inactive_widgets'][] = $widget_id; } } } $sidebars[ $request['id'] ] = $request['widgets']; wp_set_sidebars_widgets( $sidebars ); } $request['context'] = 'edit'; $sidebar = $this->get_sidebar( $request['id'] ); /** * Fires after a sidebar is updated via the REST API. * * @since 5.8.0 * * @param array $sidebar The updated sidebar. * @param WP_REST_Request $request Request object. */ do_action( 'rest_save_sidebar', $sidebar, $request ); return $this->prepare_item_for_response( $sidebar, $request ); } /** * Checks if the user has permissions to make the request. * * @since 5.8.0 * * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ protected function do_permissions_check() { /* * Verify if the current user has edit_theme_options capability. * This capability is required to access the widgets screen. */ if ( ! current_user_can( 'edit_theme_options' ) ) { return new WP_Error( 'rest_cannot_manage_widgets', __( 'Sorry, you are not allowed to manage widgets on this site.' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } /** * Retrieves the registered sidebar with the given id. * * @since 5.8.0 * * @param string|int $id ID of the sidebar. * @return array|null The discovered sidebar, or null if it is not registered. */ protected function get_sidebar( $id ) { return wp_get_sidebar( $id ); } /** * Looks for "lost" widgets once per request. * * @since 5.9.0 * * @see retrieve_widgets() */ protected function retrieve_widgets() { if ( ! $this->widgets_retrieved ) { retrieve_widgets(); $this->widgets_retrieved = true; } } /** * Prepares a single sidebar output for response. * * @since 5.8.0 * @since 5.9.0 Renamed `$raw_sidebar` to `$item` to match parent class for PHP 8 named parameter support. * * @global array $wp_registered_sidebars The registered sidebars. * @global array $wp_registered_widgets The registered widgets. * * @param array $item Sidebar instance. * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response Prepared response object. */ public function prepare_item_for_response( $item, $request ) { global $wp_registered_sidebars, $wp_registered_widgets; // Restores the more descriptive, specific name for use within this method. $raw_sidebar = $item; $id = $raw_sidebar['id']; $sidebar = array( 'id' => $id ); if ( isset( $wp_registered_sidebars[ $id ] ) ) { $registered_sidebar = $wp_registered_sidebars[ $id ]; $sidebar['status'] = 'active'; $sidebar['name'] = isset( $registered_sidebar['name'] ) ? $registered_sidebar['name'] : ''; $sidebar['description'] = isset( $registered_sidebar['description'] ) ? wp_sidebar_description( $id ) : ''; $sidebar['class'] = isset( $registered_sidebar['class'] ) ? $registered_sidebar['class'] : ''; $sidebar['before_widget'] = isset( $registered_sidebar['before_widget'] ) ? $registered_sidebar['before_widget'] : ''; $sidebar['after_widget'] = isset( $registered_sidebar['after_widget'] ) ? $registered_sidebar['after_widget'] : ''; $sidebar['before_title'] = isset( $registered_sidebar['before_title'] ) ? $registered_sidebar['before_title'] : ''; $sidebar['after_title'] = isset( $registered_sidebar['after_title'] ) ? $registered_sidebar['after_title'] : ''; } else { $sidebar['status'] = 'inactive'; $sidebar['name'] = $raw_sidebar['name']; $sidebar['description'] = ''; $sidebar['class'] = ''; } if ( wp_is_block_theme() ) { $sidebar['status'] = 'inactive'; } $fields = $this->get_fields_for_response( $request ); if ( rest_is_field_included( 'widgets', $fields ) ) { $sidebars = wp_get_sidebars_widgets(); $widgets = array_filter( isset( $sidebars[ $sidebar['id'] ] ) ? $sidebars[ $sidebar['id'] ] : array(), static function ( $widget_id ) use ( $wp_registered_widgets ) { return isset( $wp_registered_widgets[ $widget_id ] ); } ); $sidebar['widgets'] = array_values( $widgets ); } $schema = $this->get_item_schema(); $data = array(); foreach ( $schema['properties'] as $property_id => $property ) { if ( isset( $sidebar[ $property_id ] ) && true === rest_validate_value_from_schema( $sidebar[ $property_id ], $property ) ) { $data[ $property_id ] = $sidebar[ $property_id ]; } elseif ( isset( $property['default'] ) ) { $data[ $property_id ] = $property['default']; } } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $response->add_links( $this->prepare_links( $sidebar ) ); } /** * Filters the REST API response for a sidebar. * * @since 5.8.0 * * @param WP_REST_Response $response The response object. * @param array $raw_sidebar The raw sidebar data. * @param WP_REST_Request $request The request object. */ return apply_filters( 'rest_prepare_sidebar', $response, $raw_sidebar, $request ); } /** * Prepares links for the sidebar. * * @since 5.8.0 * * @param array $sidebar Sidebar. * @return array Links for the given widget. */ protected function prepare_links( $sidebar ) { return array( 'collection' => array( 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ), 'self' => array( 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $sidebar['id'] ) ), ), 'https://api.w.org/widget' => array( 'href' => add_query_arg( 'sidebar', $sidebar['id'], rest_url( '/wp/v2/widgets' ) ), 'embeddable' => true, ), ); } /** * Retrieves the block type' schema, conforming to JSON Schema. * * @since 5.8.0 * * @return array Item schema data. */ public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'sidebar', 'type' => 'object', 'properties' => array( 'id' => array( 'description' => __( 'ID of sidebar.' ), 'type' => 'string', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'name' => array( 'description' => __( 'Unique name identifying the sidebar.' ), 'type' => 'string', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'description' => array( 'description' => __( 'Description of sidebar.' ), 'type' => 'string', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'class' => array( 'description' => __( 'Extra CSS class to assign to the sidebar in the Widgets interface.' ), 'type' => 'string', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'before_widget' => array( 'description' => __( 'HTML content to prepend to each widget\'s HTML output when assigned to this sidebar. Default is an opening list item element.' ), 'type' => 'string', 'default' => '', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'after_widget' => array( 'description' => __( 'HTML content to append to each widget\'s HTML output when assigned to this sidebar. Default is a closing list item element.' ), 'type' => 'string', 'default' => '', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'before_title' => array( 'description' => __( 'HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element.' ), 'type' => 'string', 'default' => '', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'after_title' => array( 'description' => __( 'HTML content to append to the sidebar title when displayed. Default is a closing h2 element.' ), 'type' => 'string', 'default' => '', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'status' => array( 'description' => __( 'Status of sidebar.' ), 'type' => 'string', 'enum' => array( 'active', 'inactive' ), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'widgets' => array( 'description' => __( 'Nested widgets.' ), 'type' => 'array', 'items' => array( 'type' => array( 'object', 'string' ), ), 'default' => array(), 'context' => array( 'embed', 'view', 'edit' ), ), ), ); $this->schema = $schema; return $this->add_additional_fields_schema( $this->schema ); } } ont end and editor style handles. * * @since 6.1.0 * @var string[] */ public $style_handles = array(); /** * Block type front end only style handles. * * @since 6.5.0 * @var string[] */ public $view_style_handles = array(); /** * Deprecated block type properties for script and style handles. * * @since 6.1.0 * @var string[] */ private $deprecated_properties = array( 'editor_script', 'script', 'view_script', 'editor_style', 'style', ); /** * Attributes supported by every block. * * @since 6.0.0 Added `lock`. * @since 6.5.0 Added `metadata`. * @var array */ const GLOBAL_ATTRIBUTES = array( 'lock' => array( 'type' => 'object' ), 'metadata' => array( 'type' => 'object' ), ); /** * Constructor. * * Will populate object properties from the provided arguments. * * @since 5.0.0 * @since 5.5.0 Added the `title`, `category`, `parent`, `icon`, `description`, * `keywords`, `textdomain`, `styles`, `supports`, `example`, * `uses_context`, and `provides_context` properties. * @since 5.6.0 Added the `api_version` property. * @since 5.8.0 Added the `variations` property. * @since 5.9.0 Added the `view_script` property. * @since 6.0.0 Added the `ancestor` property. * @since 6.1.0 Added the `editor_script_handles`, `script_handles`, `view_script_handles`, * `editor_style_handles`, and `style_handles` properties. * Deprecated the `editor_script`, `script`, `view_script`, `editor_style`, and `style` properties. * @since 6.3.0 Added the `selectors` property. * @since 6.4.0 Added the `block_hooks` property. * @since 6.5.0 Added the `allowed_blocks`, `variation_callback`, and `view_style_handles` properties. * * @see register_block_type() * * @param string $block_type Block type name including namespace. * @param array|string $args { * Optional. Array or string of arguments for registering a block type. Any arguments may be defined, * however the ones described below are supported by default. Default empty array. * * @type string $api_version Block API version. * @type string $title Human-readable block type label. * @type string|null $category Block type category classification, used in * search interfaces to arrange block types by category. * @type string[]|null $parent Setting parent lets a block require that it is only * available when nested within the specified blocks. * @type string[]|null $ancestor Setting ancestor makes a block available only inside the specified * block types at any position of the ancestor's block subtree. * @type string[]|null $allowed_blocks Limits which block types can be inserted as children of this block type. * @type string|null $icon Block type icon. * @type string $description A detailed block type description. * @type string[] $keywords Additional keywords to produce block type as * result in search interfaces. * @type string|null $textdomain The translation textdomain. * @type array[] $styles Alternative block styles. * @type array[] $variations Block variations. * @type array $selectors Custom CSS selectors for theme.json style generation. * @type array|null $supports Supported features. * @type array|null $example Structured data for the block preview. * @type callable|null $render_callback Block type render callback. * @type callable|null $variation_callback Block type variations callback. * @type array|null $attributes Block type attributes property schemas. * @type string[] $uses_context Context values inherited by blocks of this type. * @type string[]|null $provides_context Context provided by blocks of this type. * @type string[] $block_hooks Block hooks. * @type string[] $editor_script_handles Block type editor only script handles. * @type string[] $script_handles Block type front end and editor script handles. * @type string[] $view_script_handles Block type front end only script handles. * @type string[] $editor_style_handles Block type editor only style handles. * @type string[] $style_handles Block type front end and editor style handles. * @type string[] $view_style_handles Block type front end only style handles. * } */ public function __construct( $block_type, $args = array() ) { $this->name = $block_type; $this->set_props( $args ); } /** * Proxies getting values for deprecated properties for script and style handles for backward compatibility. * Gets the value for the corresponding new property if the first item in the array provided. * * @since 6.1.0 * * @param string $name Deprecated property name. * * @return string|string[]|null|void The value read from the new property if the first item in the array provided, * null when value not found, or void when unknown property name provided. */ public function __get( $name ) { if ( 'variations' === $name ) { return $this->get_variations(); } if ( 'uses_context' === $name ) { return $this->get_uses_context(); } if ( ! in_array( $name, $this->deprecated_properties, true ) ) { return; } $new_name = $name . '_handles'; if ( ! property_exists( $this, $new_name ) || ! is_array( $this->{$new_name} ) ) { return null; } if ( count( $this->{$new_name} ) > 1 ) { return $this->{$new_name}; } return isset( $this->{$new_name}[0] ) ? $this->{$new_name}[0] : null; } /** * Proxies checking for deprecated properties for script and style handles for backward compatibility. * Checks whether the corresponding new property has the first item in the array provided. * * @since 6.1.0 * * @param string $name Deprecated property name. * * @return bool Returns true when for the new property the first item in the array exists, * or false otherwise. */ public function __isset( $name ) { if ( in_array( $name, array( 'variations', 'uses_context' ), true ) ) { return true; } if ( ! in_array( $name, $this->deprecated_properties, true ) ) { return false; } $new_name = $name . '_handles'; return isset( $this->{$new_name}[0] ); } /** * Proxies setting values for deprecated properties for script and style handles for backward compatibility. * Sets the value for the corresponding new property as the first item in the array. * It also allows setting custom properties for backward compatibility. * * @since 6.1.0 * * @param string $name Property name. * @param mixed $value Property value. */ public function __set( $name, $value ) { if ( ! in_array( $name, $this->deprecated_properties, true ) ) { $this->{$name} = $value; return; } $new_name = $name . '_handles'; if ( is_array( $value ) ) { $filtered = array_filter( $value, 'is_string' ); if ( count( $filtered ) !== count( $value ) ) { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: The '$value' argument. */ __( 'The %s argument must be a string or a string array.' ), '$value' ), '6.1.0' ); } $this->{$new_name} = array_values( $filtered ); return; } if ( ! is_string( $value ) ) { return; } $this->{$new_name} = array( $value ); } /** * Renders the block type output for given attributes. * * @since 5.0.0 * * @param array $attributes Optional. Block attributes. Default empty array. * @param string $content Optional. Block content. Default empty string. * @return string Rendered block type output. */ public function render( $attributes = array(), $content = '' ) { if ( ! $this->is_dynamic() ) { return ''; } $attributes = $this->prepare_attributes_for_render( $attributes ); return (string) call_user_func( $this->render_callback, $attributes, $content ); } /** * Returns true if the block type is dynamic, or false otherwise. A dynamic * block is one which defers its rendering to occur on-demand at runtime. * * @since 5.0.0 * * @return bool Whether block type is dynamic. */ public function is_dynamic() { return is_callable( $this->render_callback ); } /** * Validates attributes against the current block schema, populating * defaulted and missing values. * * @since 5.0.0 * * @param array $attributes Original block attributes. * @return array Prepared block attributes. */ public function prepare_attributes_for_render( $attributes ) { // If there are no attribute definitions for the block type, skip // processing and return verbatim. if ( ! isset( $this->attributes ) ) { return $attributes; } foreach ( $attributes as $attribute_name => $value ) { // If the attribute is not defined by the block type, it cannot be // validated. if ( ! isset( $this->attributes[ $attribute_name ] ) ) { continue; } $schema = $this->attributes[ $attribute_name ]; // Validate value by JSON schema. An invalid value should revert to // its default, if one exists. This occurs by virtue of the missing // attributes loop immediately following. If there is not a default // assigned, the attribute value should remain unset. $is_valid = rest_validate_value_from_schema( $value, $schema, $attribute_name ); if ( is_wp_error( $is_valid ) ) { unset( $attributes[ $attribute_name ] ); } } // Populate values of any missing attributes for which the block type // defines a default. $missing_schema_attributes = array_diff_key( $this->attributes, $attributes ); foreach ( $missing_schema_attributes as $attribute_name => $schema ) { if ( isset( $schema['default'] ) ) { $attributes[ $attribute_name ] = $schema['default']; } } return $attributes; } /** * Sets block type properties. * * @since 5.0.0 * * @param array|string $args Array or string of arguments for registering a block type. * See WP_Block_Type::__construct() for information on accepted arguments. */ public function set_props( $args ) { $args = wp_parse_args( $args, array( 'render_callback' => null, ) ); $args['name'] = $this->name; // Setup attributes if needed. if ( ! isset( $args['attributes'] ) || ! is_array( $args['attributes'] ) ) { $args['attributes'] = array(); } // Register core attributes. foreach ( static::GLOBAL_ATTRIBUTES as $attr_key => $attr_schema ) { if ( ! array_key_exists( $attr_key, $args['attributes'] ) ) { $args['attributes'][ $attr_key ] = $attr_schema; } } /** * Filters the arguments for registering a block type. * * @since 5.5.0 * * @param array $args Array of arguments for registering a block type. * @param string $block_type Block type name including namespace. */ $args = apply_filters( 'register_block_type_args', $args, $this->name ); foreach ( $args as $property_name => $property_value ) { $this->$property_name = $property_value; } } /** * Get all available block attributes including possible layout attribute from Columns block. * * @since 5.0.0 * * @return array Array of attributes. */ public function get_attributes() { return is_array( $this->attributes ) ? $this->attributes : array(); } /** * Get block variations. * * @since 6.5.0 * * @return array[] */ public function get_variations() { if ( ! isset( $this->variations ) ) { $this->variations = array(); if ( is_callable( $this->variation_callback ) ) { $this->variations = call_user_func( $this->variation_callback ); } } /** * Filters the registered variations for a block type. * * @since 6.5.0 * * @param array $variations Array of registered variations for a block type. * @param WP_Block_Type $block_type The full block type object. */ return apply_filters( 'get_block_type_variations', $this->variations, $this ); } /** * Get block uses context. * * @since 6.5.0 * * @return string[] */ public function get_uses_context() { /** * Filters the registered uses context for a block type. * * @since 6.5.0 * * @param string[] $uses_context Array of registered uses context for a block type. * @param WP_Block_Type $block_type The full block type object. */ return apply_filters( 'get_block_type_uses_context', $this->uses_context, $this ); } } rch'] ) { $this->ensure_class( 'Automattic\Jetpack\Search\Initializer' ) && $this->ensure_feature( 'search' ); } if ( $this->config['publicize'] ) { $this->ensure_class( 'Automattic\Jetpack\Publicize\Publicize_UI' ) && $this->ensure_class( 'Automattic\Jetpack\Publicize\Publicize' ) && $this->ensure_feature( 'publicize' ); } if ( $this->config['wordads'] ) { $this->ensure_class( 'Automattic\Jetpack\WordAds\Initializer' ) && $this->ensure_feature( 'wordads' ); } if ( $this->config['waf'] ) { $this->ensure_class( 'Automattic\Jetpack\Waf\Waf_Initializer' ) && $this->ensure_feature( 'waf' ); } if ( $this->config['videopress'] ) { $this->ensure_class( 'Automattic\Jetpack\VideoPress\Initializer' ) && $this->ensure_feature( 'videopress' ); } if ( $this->config['stats'] ) { $this->ensure_class( 'Automattic\Jetpack\Stats\Main' ) && $this->ensure_feature( 'stats' ); } if ( $this->config['stats_admin'] ) { $this->ensure_class( 'Automattic\Jetpack\Stats_Admin\Main' ) && $this->ensure_feature( 'stats_admin' ); } if ( $this->config['blaze'] ) { $this->ensure_class( 'Automattic\Jetpack\Blaze' ) && $this->ensure_feature( 'blaze' ); } if ( $this->config['yoast_promo'] ) { $this->ensure_class( 'Automattic\Jetpack\Yoast_Promo' ) && $this->ensure_feature( 'yoast_promo' ); } if ( $this->config['import'] ) { $this->ensure_class( 'Automattic\Jetpack\Import\Main' ) && $this->ensure_feature( 'import' ); } } /** * Returns true if the required class is available and alerts the user if it's not available * in case the site is in debug mode. * * @param String $classname a fully qualified class name. * @param Boolean $log_notice whether the E_USER_NOTICE should be generated if the class is not found. * * @return Boolean whether the class is available. */ protected function ensure_class( $classname, $log_notice = true ) { $available = class_exists( $classname ); if ( $log_notice && ! $available && defined( 'WP_DEBUG' ) && WP_DEBUG ) { trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error sprintf( /* translators: %1$s is a PHP class name. */ esc_html__( 'Unable to load class %1$s. Please add the package that contains it using composer and make sure you are requiring the Jetpack autoloader', 'jetpack-config' ), esc_html( $classname ) ), E_USER_NOTICE ); } return $available; } /** * Ensures a feature is enabled, sets it up if it hasn't already been set up. * * @param String $feature slug of the feature. * @return Integer either FEATURE_ENSURED, FEATURE_ALREADY_ENSURED or FEATURE_NOT_AVAILABLE constants. */ protected function ensure_feature( $feature ) { $method = 'enable_' . $feature; if ( ! method_exists( $this, $method ) ) { return self::FEATURE_NOT_AVAILABLE; } if ( did_action( 'jetpack_feature_' . $feature . '_enabled' ) ) { return self::FEATURE_ALREADY_ENSURED; } $this->{ $method }(); /** * Fires when a specific Jetpack package feature is initalized using the Config package. * * @since 1.1.0 */ do_action( 'jetpack_feature_' . $feature . '_enabled' ); return self::FEATURE_ENSURED; } /** * Enables the JITM feature. */ protected function enable_jitm() { if ( class_exists( 'Automattic\Jetpack\JITMS\JITM' ) ) { JITMS_JITM::configure(); } else { // Provides compatibility with jetpack-jitm get_feature_options( 'publicize' ); if ( ! empty( $options['force_refresh'] ) ) { Publicize_Setup::$refresh_plan_info = true; } } /** * Enables WordAds. */ protected function enable_wordads() { Jetpack_WordAds_Main::init(); } /** * Enables Waf. */ protected function enable_waf() { Jetpack_Waf_Main::init(); return true; } /** * Enables VideoPress. */ protected function enable_videopress() { VideoPress_Pkg_Initializer::init(); return true; } /** * Enables Stats. */ protected function enable_stats() { Stats_Main::init(); return true; } /** * Enables Stats Admin. */ protected function enable_stats_admin() { Stats_Admin_Main::init(); return true; } /** * Handles VideoPress options */ protected function ensure_options_videopress() { $options = $this->get_feature_options( 'videopress' ); if ( ! empty( $options ) ) { VideoPress_Pkg_Initializer::update_init_options( $options ); } return true; } /** * Enables Blaze. */ protected function enable_blaze() { Blaze::init(); return true; } /** * Enables Yoast Promo. */ protected function enable_yoast_promo() { Yoast_Promo::init(); return true; } /** * Enables the Import feature. */ protected function enable_import() { Import_Main::configure(); return true; } /** * Setup the Connection options. */ protected function ensure_options_connection() { $options = $this->get_feature_options( 'connection' ); if ( ! empty( $options['slug'] ) ) { // The `slug` and `name` are removed from the options because they need to be passed as arguments. $slug = $options['slug']; unset( $options['slug'] ); $name = $slug; if ( ! empty( $options['name'] ) ) { $name = $options['name']; unset( $options['name'] ); } ( new Plugin( $slug ) )->add( $name, $options ); } return true; } /** * Setup the Identity Crisis options. * * @return bool */ protected function ensure_options_identity_crisis() { $options = $this->get_feature_options( 'identity_crisis' ); if ( is_array( $options ) && count( $options ) ) { add_filter( 'jetpack_idc_consumers', function ( $consumers ) use ( $options ) { $consumers[] = $options; return $consumers; } ); } return true; } /** * Setup the Sync options. */ protected function ensure_options_sync() { $options = $this->get_feature_options( 'sync' ); if ( method_exists( 'Automattic\Jetpack\Sync\Main', 'set_sync_data_options' ) ) { Sync_Main::set_sync_data_options( $options ); } return true; } /** * Temporary save initialization options for a feature. * * @param string $feature The feature slug. * @param array $options The options. * * @return bool */ protected function set_feature_options( $feature, array $options ) { if ( $options ) { $this->feature_options[ $feature ] = $options; } return true; } /** * Get initialization options for a feature from the temporary storage. * * @param string $feature The feature slug. * * @return array */ protected function get_feature_options( $feature ) { return empty( $this->feature_options[ $feature ] ) ? array() : $this->feature_options[ $feature ]; } }