Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks: convert to module #39449

Merged
merged 13 commits into from
Sep 27, 2024
Merged
44 changes: 21 additions & 23 deletions projects/plugins/jetpack/_inc/client/writing/composing.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -173,29 +173,27 @@ export class Composing extends React.Component {
} }
>
<FormFieldset>
<ToggleControl
checked={ ! this.props.getOptionValue( 'jetpack_blocks_disabled' ) }
toggling={ this.props.isSavingAnyOption( [ 'jetpack_blocks_disabled' ] ) }
onChange={ this.toggleBlocks }
label={
<>
<span className="jp-form-toggle-explanation">
{ __(
'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'
) }
</span>
{ ! this.props.getOptionValue( 'jetpack_blocks_disabled' ) && (
<span className="jp-form-setting-explanation">
{ __(
'Caution: if there are Jetpack blocks used in existing posts or pages, disabling this setting will cause those blocks to stop working.',
'jetpack'
) }
</span>
<ModuleToggle
slug="blocks"
activated={ !! this.props.getOptionValue( 'blocks' ) }
toggling={ this.props.isSavingAnyOption( [ 'blocks' ] ) }
toggleModule={ this.props.toggleModuleNow }
>
<span className="jp-form-toggle-explanation">
{ __(
'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'
) }
</span>
{ this.props.getOptionValue( 'blocks' ) && (
<span className="jp-form-setting-explanation">
{ __(
'Caution: if there are Jetpack blocks used in existing posts or pages, disabling this setting will cause those blocks to stop working.',
'jetpack'
) }
</>
}
/>
</span>
) }
</ModuleToggle>
</FormFieldset>
</SettingsGroup>
<CompactCard
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/add-blocks-module
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: enhancement

Blocks: transition from an option to a module to improve caching
9 changes: 6 additions & 3 deletions projects/plugins/jetpack/class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
use Automattic\Jetpack\Modules;
use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer;
use Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Dismissed_Notices;
use Automattic\Jetpack\Status;
Expand Down Expand Up @@ -432,8 +433,10 @@ public static function should_load() {
return false;
}

if ( get_option( 'jetpack_blocks_disabled', false ) ) {
return false;
$return = true;

if ( ! ( new Modules() )->is_active( 'blocks' ) ) {
$return = false;
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -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 );
}

/**
Expand Down
13 changes: 13 additions & 0 deletions projects/plugins/jetpack/class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', $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 ) {
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();
Expand Down
13 changes: 13 additions & 0 deletions projects/plugins/jetpack/modules/blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Module Name: Blocks
* Module Description: Add additional blocks to your site and post editors.
* Sort Order: 5
* First Introduced: 13.9
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
* Requires Connection: Yes
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
* Auto Activate: Yes
* Module Tags: blocks
* Feature: Writing
*
* @package automattic/jetpack
*/
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
Loading