-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/Update-composer-packages
- Loading branch information
Showing
6 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Block Filters | ||
* Files within this directory are automatically enqueued. | ||
* Learn more: https://developer.wordpress.org/block-editor/reference-guides/filters/block-filters/ | ||
*/ | ||
|
||
// Import the block filter file. | ||
import './unregister-core-embed'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Functions to unregister and disable specific core Gutenberg blocks, styles, and variations. | ||
*/ | ||
|
||
wp.domReady(() => { | ||
// List of Gutenberg blocks to unregister. | ||
const unusedBlocks = [ | ||
'core/file', | ||
'core/latest-comments', | ||
'core/rss', | ||
'core/tag-cloud', | ||
'core/missing', | ||
'core/site-tagline', | ||
'core/loginout', | ||
'core/term-description', | ||
'core/query-title', | ||
]; | ||
|
||
// List of Gutenberg block variations to unregister. | ||
const unregisterBlockVariations = [ | ||
// Example: | ||
// { | ||
// blockName: 'core/group', | ||
// blockVariationName: 'group-row', | ||
// | ||
// blockName: 'core/group', | ||
// blockVariationName: 'group-stack', | ||
// }, | ||
]; | ||
|
||
// Keep only the necessary embed variations. | ||
const embedBlockVariations = wp.blocks.getBlockVariations('core/embed'); | ||
const keepEmbeds = [ | ||
'twitter', | ||
'wordpress', | ||
'spotify', | ||
'soundcloud', | ||
'flickr', | ||
]; | ||
|
||
// Unregister unused blocks. | ||
for (let i = 0; i < unusedBlocks.length; i++) { | ||
wp.blocks.unregisterBlockType(unusedBlocks[i]); | ||
} | ||
|
||
// Unregister unused block variations. | ||
for (let i = 0; i < unregisterBlockVariations.length; i++) { | ||
wp.blocks.unregisterBlockVariation( | ||
unregisterBlockVariations[i].blockName, | ||
unregisterBlockVariations[i].blockVariationName | ||
); | ||
} | ||
|
||
// Keep only necessary embed variations. | ||
for (let i = 0; i < embedBlockVariations.length; i++) { | ||
if (!keepEmbeds.includes(embedBlockVariations[i].name)) { | ||
wp.blocks.unregisterBlockVariation( | ||
'core/embed', | ||
embedBlockVariations[i].name | ||
); | ||
} | ||
} | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
<?php | ||
/** | ||
* Unregister custom block styles. | ||
* Functions to disable core Gutenberg blocks. | ||
* | ||
* @package wdsbt | ||
*/ | ||
|
||
namespace WebDevStudios\wdsbt; | ||
|
||
/** | ||
* Unregister block variations. | ||
* Prevents editors from adding unregistered core blocks to content or pages. | ||
* | ||
* @return void | ||
*/ | ||
function unregister_block_variations() { | ||
|
||
function remove_core_blocks_gutenberg_frontend() { | ||
wp_enqueue_script( | ||
'unregistered-blocks-list', | ||
get_template_directory_uri() . '/assets/js/unregistered-blocks-list.js', | ||
array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ), | ||
'unregister_core_blocks', | ||
get_template_directory_uri() . '/build/js/filters.js', | ||
array( 'wp-blocks', 'wp-dom-ready' ), | ||
wp_get_theme()->get( 'Version' ), | ||
false | ||
true | ||
); | ||
} | ||
|
||
add_filter( 'enqueue_block_editor_assets', __NAMESPACE__ . '\unregister_block_variations', 10, 1 ); | ||
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\remove_core_blocks_gutenberg_frontend' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters