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
4 changes: 4 additions & 0 deletions projects/packages/status/changelog/add-blocks-module
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Added handling for deleting a previous option when the blocks module is enabled.
7 changes: 7 additions & 0 deletions projects/packages/status/src/class-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,13 @@ public function activate( $module, $exit = true, $redirect = true ) {

$state->state( 'error', false ); // the override.
ob_end_clean();

// This likely could/should be a filter in this function for post-activation, but will save that
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
// for a future PR.
// Special case to remove the option when blocks are enabled as a module.
if ( 'blocks' === $module ) {
delete_option( 'jetpack_blocks_disabled' ); // The function will check and return early if not present.
}
} else { // Not a Jetpack plugin.
$active[] = $module;
$this->update_active( $active );
Expand Down
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
14 changes: 10 additions & 4 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,18 +433,23 @@ 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
}

/**
* Filter to disable Gutenberg blocks
* Filter to enable Gutenberg blocks.
*
* Defaults to true if (connected or in offline mode) and the Blocks module is active.
*
* @since 6.5.0
* @since $$next-version$$ Filter is able to activate or deactivate Gutenberg blocks.
*
* @param bool true Whether to load Gutenberg blocks
*/
return (bool) apply_filters( 'jetpack_gutenberg', true );
return (bool) apply_filters( 'jetpack_gutenberg', $return );
}

/**
Expand Down
9 changes: 9 additions & 0 deletions projects/plugins/jetpack/class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,15 @@ public function filter_default_modules( $modules ) {
}
}

// 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.
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
$block_option = get_option( 'jetpack_blocks_disabled', null );
if ( $block_option ) {
unset( $modules[ $block_key ] );
}
}

return $modules;
}

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: No
* 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