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

Gutenberg: jetpack_set_available_blocks revert to get data only from manifest file #10844

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ class Jetpack_Gutenberg {

// BLOCKS
private static $default_blocks = array(
'contact-form',
'field-text',
'field-name',
'field-email',
'field-url',
'field-date',
'field-telephone',
'field-textarea',
'field-checkbox',
'field-checkbox-multiple',
'field-radio',
'field-select',
'map',
'markdown',
'simple-payments',
'related-posts',
'contact-form',
'field-text',
'field-name',
'field-email',
'field-url',
'field-date',
'field-telephone',
'field-textarea',
'field-checkbox',
'field-checkbox-multiple',
'field-radio',
'field-select'
'publicize',
'simple-payments'
);

/**
Expand Down Expand Up @@ -149,7 +149,7 @@ static function load( $request = null ) {
/**
* Filter the list of block editor blocks that are available through jetpack.
*
* This filter is populated by Jetpack_Gutenberg::jetpack_set_available_blocks
* This filter is populated by Jetpack_Gutenberg::jetpack_set_available_blocks in develpment mode
*
* @since 6.8.0
*
Expand Down Expand Up @@ -275,21 +275,17 @@ public static function get_preset( $preset ) {
}

/**
* Filters the results of `apply_filter( 'jetpack_set_available_blocks', array() )`
* using the merged contents of `blocks-manifest.json` ( $preset_blocks )
* and self::$jetpack_blocks ( $internal_blocks )
* Add the blocks as specified in the `_inc/blocks/index.json`
* This filters gets applied if `JETPACK_BETA_BLOCKS` is set or Jetpack::is_development_mode() is set.
*
* @param $blocks The default list.
*
* @return array A list of blocks: eg [ 'publicize', 'markdown' ]
*/
public static function jetpack_set_available_blocks( $blocks ) {
$preset_blocks_manifest = self::preset_exists( 'index' ) ? self::get_preset( 'index' ) : (object) array( 'blocks' => $blocks );
// manifest shouldn't remove default blocks...

$preset_blocks = isset( $preset_blocks_manifest->production ) ? (array) $preset_blocks_manifest->production : array() ;
$preset_blocks = array_unique( array_merge( $preset_blocks, $blocks ) );


if ( Jetpack_Constants::is_true( 'JETPACK_BETA_BLOCKS' ) ) {
$beta_blocks = isset( $preset_blocks_manifest->beta ) ? (array) $preset_blocks_manifest->beta : array();
return array_unique( array_merge( $preset_blocks, $beta_blocks ) );
Expand Down
5 changes: 4 additions & 1 deletion class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,10 @@ private function __construct() {
require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php';
add_action( 'init', array( 'Jetpack_Gutenberg', 'load_blocks' ), 99 ); // Registers all the Jetpack blocks .
add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) );
add_filter( 'jetpack_set_available_blocks', array( 'Jetpack_Gutenberg', 'jetpack_set_available_blocks' ) );
if ( Jetpack_Constants::is_true( 'JETPACK_BETA_BLOCKS' ) || self::is_development_mode() ) {
add_filter( 'jetpack_set_available_blocks', array( 'Jetpack_Gutenberg', 'jetpack_set_available_blocks' ) );
}


add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 );

Expand Down