From 5ff452d2ee680eabf2ed0d4a928d344212f1785b Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 9 Oct 2024 14:05:17 -0500 Subject: [PATCH 1/9] Blocks: various optimizations --- .../changelog/add-performance-improvements | 4 ++ .../jetpack/class.jetpack-gutenberg.php | 39 ++++++++++++++----- projects/plugins/jetpack/class.jetpack.php | 17 ++------ projects/plugins/jetpack/modules/blocks.php | 15 +++++++ 4 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/add-performance-improvements diff --git a/projects/plugins/jetpack/changelog/add-performance-improvements b/projects/plugins/jetpack/changelog/add-performance-improvements new file mode 100644 index 0000000000000..8b9be7db08d8d --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-performance-improvements @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +Blocks: improved performance. diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index 6fa4dd4ed04cf..5552f1b59b0ed 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -65,6 +65,15 @@ class Jetpack_Gutenberg { 'jetpack/revue', ); + /** + * Storing the contents of the preset file. + * + * Already been json_decode. + * + * @var null|object JSON decoded object after first usage. + */ + private static $preset_cache = null; + /** * Check to see if a minimum version of Gutenberg is available. Because a Gutenberg version is not available in * php if the Gutenberg plugin is not installed, if we know which minimum WP release has the required version we can @@ -245,26 +254,40 @@ public static function get_blocks_directory() { /** * Checks for a given .json file in the blocks folder. * + * @deprecated $$next-version$$ + * * @param string $preset The name of the .json file to look for. * * @return bool True if the file is found. */ public static function preset_exists( $preset ) { + _deprecated_function( __METHOD__, '$$next-version$$' ); return file_exists( JETPACK__PLUGIN_DIR . self::get_blocks_directory() . $preset . '.json' ); } /** - * Decodes JSON loaded from a preset file in the blocks folder + * Decodes JSON loaded from the preset file in the blocks folder * - * @param string $preset The name of the .json file to load. + * @since $$next-version$$ Deprecated argument. Only one value is ever used. + * + * @param null $deprecated No longer used. * * @return mixed Returns an object if the file is present, or false if a valid .json file is not present. */ - public static function get_preset( $preset ) { - return json_decode( - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - file_get_contents( JETPACK__PLUGIN_DIR . self::get_blocks_directory() . $preset . '.json' ) + public static function get_preset( $deprecated = null ) { + if ( $deprecated ) { + _deprecated_argument( __METHOD__, '$$next-version', 'The $preset argument is no longer needed or used.' ); + } + + if ( self::$preset_cache ) { + return self::$preset_cache; + } + + self::$preset_cache = json_decode( + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + file_get_contents( JETPACK__PLUGIN_DIR . self::get_blocks_directory() . 'index.json' ) ); + return self::$preset_cache; } /** @@ -273,9 +296,7 @@ public static function get_preset( $preset ) { * @return array A list of blocks: eg [ 'publicize', 'markdown' ] */ public static function get_jetpack_gutenberg_extensions_allowed_list() { - $preset_extensions_manifest = self::preset_exists( 'index' ) - ? self::get_preset( 'index' ) - : (object) array(); + $preset_extensions_manifest = self::get_preset(); $blocks_variation = self::blocks_variation(); return self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation ); diff --git a/projects/plugins/jetpack/class.jetpack.php b/projects/plugins/jetpack/class.jetpack.php index 8cf17c78fa1a0..f141b150019e0 100644 --- a/projects/plugins/jetpack/class.jetpack.php +++ b/projects/plugins/jetpack/class.jetpack.php @@ -624,22 +624,11 @@ private function __construct() { /** * Prepare Gutenberg Editor functionality - */ - require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php'; - add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_independent_blocks' ) ); - add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_block_editor_extensions' ), 9 ); - /** - * We've switched from enqueue_block_editor_assets to enqueue_block_assets in WP-Admin because the assets with the former are loaded on the main site-editor.php. * - * With the latter, the assets are now loaded in the SE iframe; the implementation is now faster because Gutenberg doesn't need to inject the assets in the iframe on client-side. + * The hooks previously here have been moved to modules/blocks.php but leaving this here pending + * a longer investigation to see if code is expecting the Gutenberg class to always be available. */ - if ( is_admin() ) { - add_action( 'enqueue_block_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); - } else { - add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); - } - add_filter( 'render_block', array( 'Jetpack_Gutenberg', 'display_deprecated_block_message' ), 10, 2 ); - + require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php'; add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); add_action( 'jetpack_event_log', array( 'Jetpack', 'log' ), 10, 2 ); diff --git a/projects/plugins/jetpack/modules/blocks.php b/projects/plugins/jetpack/modules/blocks.php index 00338d87f0d06..4d50fb6edf510 100644 --- a/projects/plugins/jetpack/modules/blocks.php +++ b/projects/plugins/jetpack/modules/blocks.php @@ -28,3 +28,18 @@ function jetpack_blocks_activate_module() { delete_option( 'jetpack_blocks_disabled' ); // The function will check and return early if not present. } + +Jetpack_Gutenberg::load_independent_blocks(); +Jetpack_Gutenberg::load_block_editor_extensions(); + +/** + * We've switched from enqueue_block_editor_assets to enqueue_block_assets in WP-Admin because the assets with the former are loaded on the main site-editor.php. + * + * With the latter, the assets are now loaded in the SE iframe; the implementation is now faster because Gutenberg doesn't need to inject the assets in the iframe on client-side. + */ +if ( is_admin() ) { + add_action( 'enqueue_block_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); +} else { + add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); +} +add_filter( 'render_block', array( 'Jetpack_Gutenberg', 'display_deprecated_block_message' ), 10, 2 ); From c07017c855c577469ae9de7ce1244004a13296a9 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 9 Oct 2024 14:05:17 -0500 Subject: [PATCH 2/9] Blocks: various optimizations --- .../changelog/add-performance-improvements | 4 ++ .../jetpack/class.jetpack-gutenberg.php | 39 ++++++++++++++----- projects/plugins/jetpack/class.jetpack.php | 17 ++------ projects/plugins/jetpack/modules/blocks.php | 15 +++++++ 4 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/add-performance-improvements diff --git a/projects/plugins/jetpack/changelog/add-performance-improvements b/projects/plugins/jetpack/changelog/add-performance-improvements new file mode 100644 index 0000000000000..8b9be7db08d8d --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-performance-improvements @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +Blocks: improved performance. diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index 6fa4dd4ed04cf..5552f1b59b0ed 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -65,6 +65,15 @@ class Jetpack_Gutenberg { 'jetpack/revue', ); + /** + * Storing the contents of the preset file. + * + * Already been json_decode. + * + * @var null|object JSON decoded object after first usage. + */ + private static $preset_cache = null; + /** * Check to see if a minimum version of Gutenberg is available. Because a Gutenberg version is not available in * php if the Gutenberg plugin is not installed, if we know which minimum WP release has the required version we can @@ -245,26 +254,40 @@ public static function get_blocks_directory() { /** * Checks for a given .json file in the blocks folder. * + * @deprecated $$next-version$$ + * * @param string $preset The name of the .json file to look for. * * @return bool True if the file is found. */ public static function preset_exists( $preset ) { + _deprecated_function( __METHOD__, '$$next-version$$' ); return file_exists( JETPACK__PLUGIN_DIR . self::get_blocks_directory() . $preset . '.json' ); } /** - * Decodes JSON loaded from a preset file in the blocks folder + * Decodes JSON loaded from the preset file in the blocks folder * - * @param string $preset The name of the .json file to load. + * @since $$next-version$$ Deprecated argument. Only one value is ever used. + * + * @param null $deprecated No longer used. * * @return mixed Returns an object if the file is present, or false if a valid .json file is not present. */ - public static function get_preset( $preset ) { - return json_decode( - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - file_get_contents( JETPACK__PLUGIN_DIR . self::get_blocks_directory() . $preset . '.json' ) + public static function get_preset( $deprecated = null ) { + if ( $deprecated ) { + _deprecated_argument( __METHOD__, '$$next-version', 'The $preset argument is no longer needed or used.' ); + } + + if ( self::$preset_cache ) { + return self::$preset_cache; + } + + self::$preset_cache = json_decode( + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + file_get_contents( JETPACK__PLUGIN_DIR . self::get_blocks_directory() . 'index.json' ) ); + return self::$preset_cache; } /** @@ -273,9 +296,7 @@ public static function get_preset( $preset ) { * @return array A list of blocks: eg [ 'publicize', 'markdown' ] */ public static function get_jetpack_gutenberg_extensions_allowed_list() { - $preset_extensions_manifest = self::preset_exists( 'index' ) - ? self::get_preset( 'index' ) - : (object) array(); + $preset_extensions_manifest = self::get_preset(); $blocks_variation = self::blocks_variation(); return self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation ); diff --git a/projects/plugins/jetpack/class.jetpack.php b/projects/plugins/jetpack/class.jetpack.php index 8cf17c78fa1a0..f141b150019e0 100644 --- a/projects/plugins/jetpack/class.jetpack.php +++ b/projects/plugins/jetpack/class.jetpack.php @@ -624,22 +624,11 @@ private function __construct() { /** * Prepare Gutenberg Editor functionality - */ - require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php'; - add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_independent_blocks' ) ); - add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_block_editor_extensions' ), 9 ); - /** - * We've switched from enqueue_block_editor_assets to enqueue_block_assets in WP-Admin because the assets with the former are loaded on the main site-editor.php. * - * With the latter, the assets are now loaded in the SE iframe; the implementation is now faster because Gutenberg doesn't need to inject the assets in the iframe on client-side. + * The hooks previously here have been moved to modules/blocks.php but leaving this here pending + * a longer investigation to see if code is expecting the Gutenberg class to always be available. */ - if ( is_admin() ) { - add_action( 'enqueue_block_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); - } else { - add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); - } - add_filter( 'render_block', array( 'Jetpack_Gutenberg', 'display_deprecated_block_message' ), 10, 2 ); - + require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php'; add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); add_action( 'jetpack_event_log', array( 'Jetpack', 'log' ), 10, 2 ); diff --git a/projects/plugins/jetpack/modules/blocks.php b/projects/plugins/jetpack/modules/blocks.php index 00338d87f0d06..4d50fb6edf510 100644 --- a/projects/plugins/jetpack/modules/blocks.php +++ b/projects/plugins/jetpack/modules/blocks.php @@ -28,3 +28,18 @@ function jetpack_blocks_activate_module() { delete_option( 'jetpack_blocks_disabled' ); // The function will check and return early if not present. } + +Jetpack_Gutenberg::load_independent_blocks(); +Jetpack_Gutenberg::load_block_editor_extensions(); + +/** + * We've switched from enqueue_block_editor_assets to enqueue_block_assets in WP-Admin because the assets with the former are loaded on the main site-editor.php. + * + * With the latter, the assets are now loaded in the SE iframe; the implementation is now faster because Gutenberg doesn't need to inject the assets in the iframe on client-side. + */ +if ( is_admin() ) { + add_action( 'enqueue_block_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); +} else { + add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) ); +} +add_filter( 'render_block', array( 'Jetpack_Gutenberg', 'display_deprecated_block_message' ), 10, 2 ); From dd7892a50121a3dc54840c951aa061a1876f3f68 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 9 Oct 2024 16:59:38 -0500 Subject: [PATCH 3/9] Avoid str_starts_with calls when there's a set value already --- projects/packages/blocks/src/class-blocks.php | 1 + .../class-newspack-blocks.php | 2 +- .../jetpack/class.jetpack-gutenberg.php | 8 +- .../blocks/ai-assistant/ai-assistant.php | 149 ++---------------- .../payment-buttons/payment-buttons.php | 2 +- .../extensions/blocks/wordads/wordads.php | 2 +- .../plugins/publicize/publicize.php | 4 +- .../memberships/class-jetpack-memberships.php | 2 +- .../plugins/jetpack/modules/shortlinks.php | 2 +- .../videopress/class.videopress-gutenberg.php | 4 +- .../general/test-class.jetpack-gutenberg.php | 4 +- 11 files changed, 33 insertions(+), 147 deletions(-) diff --git a/projects/packages/blocks/src/class-blocks.php b/projects/packages/blocks/src/class-blocks.php index eb6582355e78b..54eba175ecfd4 100644 --- a/projects/packages/blocks/src/class-blocks.php +++ b/projects/packages/blocks/src/class-blocks.php @@ -318,6 +318,7 @@ public static function is_gutenberg_version_available( $version_requirements, $s ! $version_available && ! self::is_standalone_block() // This is only useful in Jetpack. ) { + $slug = Jetpack_Gutenberg::remove_extension_prefix( $slug ); Jetpack_Gutenberg::set_extension_unavailable( $slug, 'incorrect_gutenberg_version', diff --git a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/class-newspack-blocks.php b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/class-newspack-blocks.php index 2685df500ef0f..f86481adec254 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/class-newspack-blocks.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/class-newspack-blocks.php @@ -1400,7 +1400,7 @@ public static function disable_jetpack_donate() { // Tell Jetpack to mark the donations feature as unavailable. Jetpack_Gutenberg::set_extension_unavailable( - 'jetpack/donations', + 'donations', esc_html__( 'Jetpack donations is disabled in favour of Newspack donations.', 'jetpack-mu-wpcom' ) ); } diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index 5552f1b59b0ed..ae9235560eb27 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -110,6 +110,7 @@ public static function is_gutenberg_version_available( $version_requirements, $s } if ( ! $version_available ) { + $slug = self::remove_extension_prefix( $slug ); self::set_extension_unavailable( $slug, 'incorrect_gutenberg_version', @@ -170,7 +171,7 @@ protected static function share_items( $a, $b ) { * @param string $slug Slug of the extension. */ public static function set_extension_available( $slug ) { - self::$availability[ self::remove_extension_prefix( $slug ) ] = true; + self::$availability[ $slug ] = true; } /** @@ -206,7 +207,7 @@ public static function set_extension_unavailable( $slug, $reason, $details = arr $reason .= '__nudge_disabled'; } - self::$availability[ self::remove_extension_prefix( $slug ) ] = array( + self::$availability[ $slug ] = array( 'reason' => $reason, 'details' => $details, ); @@ -824,6 +825,8 @@ public static function enqueue_block_editor_assets() { * @see wp_common_block_scripts_and_styles() */ public static function load_independent_blocks() { + // Add temporary timing code. Remove before setting for review. + do_action( 'qm/start', 'jp_ind_blocks' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores if ( self::should_load() ) { /** * Look for files that match our list of available Jetpack Gutenberg extensions (blocks and plugins). @@ -841,6 +844,7 @@ public static function load_independent_blocks() { } } } + do_action( 'qm/stop', 'jp_ind_blocks' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } } diff --git a/projects/plugins/jetpack/extensions/blocks/ai-assistant/ai-assistant.php b/projects/plugins/jetpack/extensions/blocks/ai-assistant/ai-assistant.php index 9cae364a75c57..f58e3069c7e89 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-assistant/ai-assistant.php +++ b/projects/plugins/jetpack/extensions/blocks/ai-assistant/ai-assistant.php @@ -55,145 +55,26 @@ function load_assets( $attr, $content ) { } /** - * Register the `ai-assistant-support` extension. + * Register extensions. */ add_action( 'jetpack_register_gutenberg_extensions', function () { if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-assistant-support' ); - } - } -); - -/** - * Register the `ai-assistant-form-support` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-assistant-form-support' ); - } - } -); - -/** - * Register the `ai-content-lens` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-content-lens' ); - } - } -); - -/** - * Register the `ai-assistant-backend-prompts` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-assistant-backend-prompts' ); - } - } -); - -/** - * Register the `ai-assistant-usage-panel` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-assistant-usage-panel' ); - } - } -); - -/** - * Register the `ai-featured-image-generator` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-featured-image-generator' ); - } - } -); - -/** - * Register the `ai-title-optimization` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-title-optimization' ); - } - } -); - -/** - * Register the `ai-assistant-experimental-image-generation-support` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-assistant-experimental-image-generation-support' ); - } - } -); - -/** - * Register the `ai-general-purpose-image-generator` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-general-purpose-image-generator' ); - } - } -); - -/** - * Register the `ai-proofread-breve` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) && apply_filters( 'breve_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-proofread-breve' ); - } - } -); - -/** - * Register the `ai-assistant-site-logo-support` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-assistant-site-logo-support' ); - } - } -); - -/** - * Register the `ai-title-optimization-keywords-support` extension. - */ -add_action( - 'jetpack_register_gutenberg_extensions', - function () { - if ( apply_filters( 'jetpack_ai_enabled', true ) ) { - \Jetpack_Gutenberg::set_extension_available( 'ai-title-optimization-keywords-support' ); + Jetpack_Gutenberg::set_extension_available( 'ai-assistant-support' ); + Jetpack_Gutenberg::set_extension_available( 'ai-assistant-form-support' ); + Jetpack_Gutenberg::set_extension_available( 'ai-content-lens' ); + Jetpack_Gutenberg::set_extension_available( 'ai-assistant-backend-prompts' ); + Jetpack_Gutenberg::set_extension_available( 'ai-assistant-usage-panel' ); + Jetpack_Gutenberg::set_extension_available( 'ai-featured-image-generator' ); + Jetpack_Gutenberg::set_extension_available( 'ai-title-optimization' ); + Jetpack_Gutenberg::set_extension_available( 'ai-assistant-experimental-image-generation-support' ); + Jetpack_Gutenberg::set_extension_available( 'ai-general-purpose-image-generator' ); + Jetpack_Gutenberg::set_extension_available( 'ai-assistant-site-logo-support' ); + Jetpack_Gutenberg::set_extension_available( 'ai-title-optimization-keywords-support' ); + if ( apply_filters( 'breve_enabled', true ) ) { + Jetpack_Gutenberg::set_extension_available( 'ai-proofread-breve' ); + } } } ); diff --git a/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php b/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php index c21c1681c5e69..000022157e372 100644 --- a/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php +++ b/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php @@ -37,7 +37,7 @@ function register_block() { } else { $required_plan = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? 'personal-bundle' : 'jetpack_personal'; \Jetpack_Gutenberg::set_extension_unavailable( - Blocks::get_block_name( __DIR__ ), + 'payment-buttons', 'missing_plan', array( 'required_feature' => 'memberships', diff --git a/projects/plugins/jetpack/extensions/blocks/wordads/wordads.php b/projects/plugins/jetpack/extensions/blocks/wordads/wordads.php index 511b6a2c27015..3e3398c204753 100644 --- a/projects/plugins/jetpack/extensions/blocks/wordads/wordads.php +++ b/projects/plugins/jetpack/extensions/blocks/wordads/wordads.php @@ -69,7 +69,7 @@ public static function register() { * Set if the WordAds block is available. */ public static function set_availability() { - $block_name = Blocks::get_block_name( __DIR__ ); + $block_name = 'wordads'; if ( ! self::is_available() ) { Jetpack_Gutenberg::set_extension_unavailable( $block_name, 'WordAds unavailable' ); diff --git a/projects/plugins/jetpack/extensions/plugins/publicize/publicize.php b/projects/plugins/jetpack/extensions/plugins/publicize/publicize.php index dafa1a935e9a3..145382edf8c44 100644 --- a/projects/plugins/jetpack/extensions/plugins/publicize/publicize.php +++ b/projects/plugins/jetpack/extensions/plugins/publicize/publicize.php @@ -25,7 +25,7 @@ function register_plugins() { if ( ! current_user_can( $capability ) ) { - Jetpack_Gutenberg::set_extension_unavailable( 'jetpack/publicize', 'unauthorized' ); + Jetpack_Gutenberg::set_extension_unavailable( 'publicize', 'unauthorized' ); return; } @@ -35,7 +35,7 @@ function register_plugins() { || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() ) ) { // Register Publicize. - Jetpack_Gutenberg::set_extension_available( 'jetpack/publicize' ); + Jetpack_Gutenberg::set_extension_available( 'publicize' ); // Set the republicize availability, depending on the site plan. Jetpack_Gutenberg::set_availability_for_plan( 'republicize' ); diff --git a/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php b/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php index 3c07b2642153b..c3f04383b1ef8 100644 --- a/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php +++ b/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php @@ -887,7 +887,7 @@ public function register_gutenberg_block() { ); } else { Jetpack_Gutenberg::set_extension_unavailable( - 'jetpack/recurring-payments', + 'recurring-payments', 'missing_plan', array( 'required_feature' => 'memberships', diff --git a/projects/plugins/jetpack/modules/shortlinks.php b/projects/plugins/jetpack/modules/shortlinks.php index deb07127f8767..877d951953bbc 100644 --- a/projects/plugins/jetpack/modules/shortlinks.php +++ b/projects/plugins/jetpack/modules/shortlinks.php @@ -182,7 +182,7 @@ function wpme_rest_get_shortlink( $object ) { * Set the Shortlink Gutenberg extension as available. */ function wpme_set_extension_available() { - Jetpack_Gutenberg::set_extension_available( 'jetpack/shortlinks' ); + Jetpack_Gutenberg::set_extension_available( 'shortlinks' ); } add_action( 'init', 'wpme_set_extension_available' ); diff --git a/projects/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php b/projects/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php index 9e644fc2dc0e5..1451401c35447 100644 --- a/projects/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php +++ b/projects/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php @@ -103,9 +103,9 @@ public function check_videopress_availability() { public function set_extension_availability() { $availability = $this->check_videopress_availability(); if ( $availability['available'] ) { - Jetpack_Gutenberg::set_extension_available( 'jetpack/videopress' ); + Jetpack_Gutenberg::set_extension_available( 'videopress' ); } else { - Jetpack_Gutenberg::set_extension_unavailable( 'jetpack/videopress', $availability['unavailable_reason'] ); + Jetpack_Gutenberg::set_extension_unavailable( 'videopress', $availability['unavailable_reason'] ); } } diff --git a/projects/plugins/jetpack/tests/php/general/test-class.jetpack-gutenberg.php b/projects/plugins/jetpack/tests/php/general/test-class.jetpack-gutenberg.php index 9724ec510db6e..4a1b8b54ef5e4 100644 --- a/projects/plugins/jetpack/tests/php/general/test-class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/tests/php/general/test-class.jetpack-gutenberg.php @@ -104,7 +104,7 @@ public function test_registered_block_is_available() { } public function test_registered_block_is_not_available() { - Jetpack_Gutenberg::set_extension_unavailable( 'jetpack/banana', 'bar' ); + Jetpack_Gutenberg::set_extension_unavailable( 'banana', 'bar' ); $availability = Jetpack_Gutenberg::get_availability(); $this->assertFalse( $availability['banana']['available'], 'banana is available!' ); $this->assertEquals( 'bar', $availability['banana']['unavailable_reason'], 'unavailable_reason is not "bar"' ); @@ -132,7 +132,7 @@ public function test_registered_plugin_is_available() { } public function test_registered_plugin_is_not_available() { - Jetpack_Gutenberg::set_extension_unavailable( 'jetpack/potato', 'bar' ); + Jetpack_Gutenberg::set_extension_unavailable( 'potato', 'bar' ); $availability = Jetpack_Gutenberg::get_availability(); $this->assertFalse( $availability['potato']['available'], 'potato is available!' ); $this->assertEquals( 'bar', $availability['potato']['unavailable_reason'], 'unavailable_reason is not "bar"' ); From d8a851f30fdcb8c264bcd371add13f3627507792 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 9 Oct 2024 17:03:35 -0500 Subject: [PATCH 4/9] changelog --- .../packages/blocks/changelog/add-performance-improvements | 5 +++++ .../jetpack-mu-wpcom/changelog/add-performance-improvements | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 projects/packages/blocks/changelog/add-performance-improvements create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/add-performance-improvements diff --git a/projects/packages/blocks/changelog/add-performance-improvements b/projects/packages/blocks/changelog/add-performance-improvements new file mode 100644 index 0000000000000..ecba0160a0b15 --- /dev/null +++ b/projects/packages/blocks/changelog/add-performance-improvements @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: No functional changes. + + diff --git a/projects/packages/jetpack-mu-wpcom/changelog/add-performance-improvements b/projects/packages/jetpack-mu-wpcom/changelog/add-performance-improvements new file mode 100644 index 0000000000000..ecba0160a0b15 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/add-performance-improvements @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: No functional changes. + + From 2c48075323e99bf3711ab1dfd1dfe09e31e540d6 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 10 Oct 2024 13:55:42 -0500 Subject: [PATCH 5/9] Blocks: There are no php files in any of the stores --- projects/plugins/jetpack/class.jetpack-gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index 35517671aa0c7..afdc457e1056c 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -831,7 +831,7 @@ public static function load_independent_blocks() { * Look for files that match our list of available Jetpack Gutenberg extensions (blocks and plugins). * If available, load them. */ - $directories = array( 'blocks', 'plugins', 'extended-blocks', 'shared', 'store' ); + $directories = array( 'blocks', 'plugins', 'extended-blocks', 'shared' ); foreach ( static::get_extensions() as $extension ) { foreach ( $directories as $dirname ) { From c1bf0cece61d6d16c1a53891964c073307938f30 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 10 Oct 2024 13:56:45 -0500 Subject: [PATCH 6/9] Blocks: There are no php files in any of shared directories --- projects/plugins/jetpack/class.jetpack-gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index afdc457e1056c..f1d24ddbb2cb0 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -831,7 +831,7 @@ public static function load_independent_blocks() { * Look for files that match our list of available Jetpack Gutenberg extensions (blocks and plugins). * If available, load them. */ - $directories = array( 'blocks', 'plugins', 'extended-blocks', 'shared' ); + $directories = array( 'blocks', 'plugins', 'extended-blocks' ); foreach ( static::get_extensions() as $extension ) { foreach ( $directories as $dirname ) { From b5219ac8d47418d4e28a1803c67e192a4f2c2b21 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Tue, 15 Oct 2024 11:32:06 -0500 Subject: [PATCH 7/9] Remove debugging code --- projects/plugins/jetpack/class.jetpack-gutenberg.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index f1d24ddbb2cb0..9b15eccc030fb 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -824,8 +824,6 @@ public static function enqueue_block_editor_assets() { * @see wp_common_block_scripts_and_styles() */ public static function load_independent_blocks() { - // Add temporary timing code. Remove before setting for review. - do_action( 'qm/start', 'jp_ind_blocks' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores if ( self::should_load() ) { /** * Look for files that match our list of available Jetpack Gutenberg extensions (blocks and plugins). @@ -843,7 +841,6 @@ public static function load_independent_blocks() { } } } - do_action( 'qm/stop', 'jp_ind_blocks' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } } From 3c41cdd0d0045777f13b518718b12bfdf50b984e Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Tue, 15 Oct 2024 11:57:47 -0500 Subject: [PATCH 8/9] Dirty hack for tests --- projects/plugins/jetpack/class.jetpack-gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index 9b15eccc030fb..6e33561567298 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -297,7 +297,7 @@ public static function get_preset( $deprecated = null ) { * @return array A list of blocks: eg [ 'publicize', 'markdown' ] */ public static function get_jetpack_gutenberg_extensions_allowed_list() { - $preset_extensions_manifest = self::get_preset(); + $preset_extensions_manifest = ( defined( 'TESTING_IN_JETPACK' ) && TESTING_IN_JETPACK ) ? array() : self::get_preset(); $blocks_variation = self::blocks_variation(); return self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation ); From e721e808db7de50d26ec5b42926be253ddc9144e Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Mon, 18 Nov 2024 12:58:47 -0600 Subject: [PATCH 9/9] Ensure older prefixed form is still accepted --- projects/plugins/jetpack/class.jetpack-gutenberg.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index 56e7f73402858..cb5ce872b744d 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -171,6 +171,7 @@ protected static function share_items( $a, $b ) { * @param string $slug Slug of the extension. */ public static function set_extension_available( $slug ) { + $slug = self::remove_extension_prefix( $slug ); self::$availability[ $slug ] = true; } @@ -206,7 +207,7 @@ public static function set_extension_unavailable( $slug, $reason, $details = arr // Add a descriptive suffix to disable behavior but provide informative reason. $reason .= '__nudge_disabled'; } - + $slug = self::remove_extension_prefix( $slug ); self::$availability[ $slug ] = array( 'reason' => $reason, 'details' => $details,