From 168d3d1820c0f14a631c490436808edde017d72a Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 18 Sep 2024 16:38:50 -0500 Subject: [PATCH 1/4] Blocks: convert to a module --- .../jetpack/_inc/client/writing/composing.jsx | 44 +++++++++---------- .../jetpack/changelog/add-blocks-module | 4 ++ .../jetpack/class.jetpack-gutenberg.php | 9 ++-- projects/plugins/jetpack/class.jetpack.php | 13 ++++++ projects/plugins/jetpack/modules/blocks.php | 13 ++++++ 5 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/add-blocks-module create mode 100644 projects/plugins/jetpack/modules/blocks.php diff --git a/projects/plugins/jetpack/_inc/client/writing/composing.jsx b/projects/plugins/jetpack/_inc/client/writing/composing.jsx index dbdf2ae38ba37..98d1437d91923 100644 --- a/projects/plugins/jetpack/_inc/client/writing/composing.jsx +++ b/projects/plugins/jetpack/_inc/client/writing/composing.jsx @@ -1,4 +1,4 @@ -import { Chip, ToggleControl, getRedirectUrl } from '@automattic/jetpack-components'; +import { Chip, getRedirectUrl } from '@automattic/jetpack-components'; import { __, _x } from '@wordpress/i18n'; import CompactCard from 'components/card/compact'; import { FormFieldset } from 'components/forms'; @@ -173,29 +173,27 @@ export class Composing extends React.Component { } } > - - - { __( - 'Jetpack Blocks give you the power to deliver quality content that hooks website visitors without needing to hire a developer or learn a single line of code.', - 'jetpack' - ) } - - { ! this.props.getOptionValue( 'jetpack_blocks_disabled' ) && ( - - { __( - 'Caution: if there are Jetpack blocks used in existing posts or pages, disabling this setting will cause those blocks to stop working.', - 'jetpack' - ) } - + + + { __( + 'CJetpack Blocks give you the power to deliver quality content that hooks website visitors without needing to hire a developer or learn a single line of code.', + 'jetpack' + ) } + + { this.props.getOptionValue( 'blocks' ) && ( + + { __( + 'Caution: if there are Jetpack blocks used in existing posts or pages, disabling this setting will cause those blocks to stop working.', + 'jetpack' ) } - - } - /> + + ) } + is_active( 'blocks' ) ) { + $return = false; } /** @@ -443,7 +446,7 @@ public static function should_load() { * * @param bool true Whether to load Gutenberg blocks */ - return (bool) apply_filters( 'jetpack_gutenberg', true ); + return (bool) apply_filters( 'jetpack_gutenberg', $return ); } /** diff --git a/projects/plugins/jetpack/class.jetpack.php b/projects/plugins/jetpack/class.jetpack.php index f75b4baf918fb..40b89ddfbeb7b 100644 --- a/projects/plugins/jetpack/class.jetpack.php +++ b/projects/plugins/jetpack/class.jetpack.php @@ -2488,6 +2488,19 @@ public static function activate_default_modules( */ do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules, $requires_connection, $requires_user_connection ); + // Special case to convert block setting to a block module. + $block_key = array_search( 'blocks', $module, true ); + if ( $block_key ) { // Only care if 'blocks' made it through the previous filters. + $block_option = get_option( 'jetpack_blocks_disabled', null ); + if ( $block_option ) { + unset( $modules[ $block_key ] ); + } + + if ( $block_option !== null ) { + delete_option( 'jetpack_blocks_disabled' ); + } + } + // Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating. if ( $send_state_messages ) { self::restate(); diff --git a/projects/plugins/jetpack/modules/blocks.php b/projects/plugins/jetpack/modules/blocks.php new file mode 100644 index 0000000000000..0da373799b880 --- /dev/null +++ b/projects/plugins/jetpack/modules/blocks.php @@ -0,0 +1,13 @@ + Date: Wed, 18 Sep 2024 16:56:39 -0500 Subject: [PATCH 2/4] Correct a couple of typos --- projects/plugins/jetpack/_inc/client/writing/composing.jsx | 2 +- projects/plugins/jetpack/class.jetpack-gutenberg.php | 2 +- projects/plugins/jetpack/class.jetpack.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/_inc/client/writing/composing.jsx b/projects/plugins/jetpack/_inc/client/writing/composing.jsx index 98d1437d91923..90b5b46d5e535 100644 --- a/projects/plugins/jetpack/_inc/client/writing/composing.jsx +++ b/projects/plugins/jetpack/_inc/client/writing/composing.jsx @@ -181,7 +181,7 @@ export class Composing extends React.Component { > { __( - 'CJetpack Blocks give you the power to deliver quality content that hooks website visitors without needing to hire a developer or learn a single line of code.', + 'Jetpack Blocks give you the power to deliver quality content that hooks website visitors without needing to hire a developer or learn a single line of code.', 'jetpack' ) } diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index 5410048ffe265..a94fa779aa13a 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -435,7 +435,7 @@ public static function should_load() { $return = true; - if ( ( new Modules() )->is_active( 'blocks' ) ) { + if ( ! ( new Modules() )->is_active( 'blocks' ) ) { $return = false; } diff --git a/projects/plugins/jetpack/class.jetpack.php b/projects/plugins/jetpack/class.jetpack.php index 40b89ddfbeb7b..3cb091a5a7acb 100644 --- a/projects/plugins/jetpack/class.jetpack.php +++ b/projects/plugins/jetpack/class.jetpack.php @@ -2489,7 +2489,7 @@ public static function activate_default_modules( do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules, $requires_connection, $requires_user_connection ); // Special case to convert block setting to a block module. - $block_key = array_search( 'blocks', $module, true ); + $block_key = array_search( 'blocks', $modules, true ); if ( $block_key ) { // Only care if 'blocks' made it through the previous filters. $block_option = get_option( 'jetpack_blocks_disabled', null ); if ( $block_option ) { From 1d8b91f653a7fa68bfe4bd14dbbbfdd98ebeab15 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 18 Sep 2024 21:25:11 -0500 Subject: [PATCH 3/4] Update test to activate default modules --- .../jetpack/tests/php/general/test-class.jetpack-gutenberg.php | 1 + 1 file changed, 1 insertion(+) 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 2f395e2805c8d..9724ec510db6e 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 @@ -26,6 +26,7 @@ public function set_up() { Jetpack_Options::update_option( 'master_user', $this->master_user_id ); Jetpack_Options::update_option( 'id', 1234 ); Jetpack_Options::update_option( 'blog_token', 'asd.asd.1' ); + Jetpack::activate_default_modules(); add_filter( 'jetpack_set_available_extensions', array( __CLASS__, 'get_extensions_whitelist' ) ); delete_option( 'jetpack_excluded_extensions' ); From 7b88491851da4104095631d680ad2933cb717576 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 19 Sep 2024 10:21:23 -0500 Subject: [PATCH 4/4] Remove connection requirement --- projects/plugins/jetpack/modules/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/modules/blocks.php b/projects/plugins/jetpack/modules/blocks.php index 0da373799b880..857b7e52c2f0c 100644 --- a/projects/plugins/jetpack/modules/blocks.php +++ b/projects/plugins/jetpack/modules/blocks.php @@ -4,7 +4,7 @@ * Module Description: Add additional blocks to your site and post editors. * Sort Order: 5 * First Introduced: 13.9 - * Requires Connection: Yes + * Requires Connection: No * Auto Activate: Yes * Module Tags: blocks * Feature: Writing