restrict core blocks to inner blocks of specified parent blocks. blocks blocks blocks
This commit is contained in:
@@ -19,13 +19,44 @@ add_filter( 'block_categories_all' , function ( $categories ) {
|
|||||||
return $categories;
|
return $categories;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// add_action('init', function () {
|
||||||
|
// $blocks = glob(get_theme_file_path('resources/blocks/*/block.json'));
|
||||||
|
|
||||||
|
// foreach ($blocks as $block_json) {
|
||||||
|
// register_block_type($block_json, [
|
||||||
|
// 'render_callback' => function ($attributes, $content, $block) {
|
||||||
|
// $slug = basename($block->name);
|
||||||
|
// $view = "blocks.{$slug}.render";
|
||||||
|
|
||||||
|
// if (\Roots\view()->exists($view)) {
|
||||||
|
// return \Roots\view($view, [
|
||||||
|
// 'attributes' => $attributes,
|
||||||
|
// 'content' => $content,
|
||||||
|
// 'block' => $block,
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return $content;
|
||||||
|
// }
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
add_action('allowed_block_types_all', function(){
|
add_action('allowed_block_types_all', function(){
|
||||||
$blocks = block_all();
|
$blocks = array_keys( \WP_Block_Type_Registry::get_instance()->get_all_registered() );
|
||||||
$blacklist = array_diff($blocks, block_whitelist());
|
$blacklist = array_diff(block_blacklist(), block_whitelist());
|
||||||
|
|
||||||
return array_values( array_diff( $blocks, $blacklist ) );
|
return array_values( array_diff( $blocks, $blacklist ) );
|
||||||
}, 100, 2);
|
}, 100, 2);
|
||||||
|
|
||||||
|
function block_blacklist()
|
||||||
|
{
|
||||||
|
$file = file_get_contents(get_theme_file_path("resources/json/core-block-blacklist.json"));
|
||||||
|
$json = json_decode($file);
|
||||||
|
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
|
||||||
function block_whitelist()
|
function block_whitelist()
|
||||||
{
|
{
|
||||||
$file = file_get_contents(get_theme_file_path("resources/json/core-block-whitelist.json"));
|
$file = file_get_contents(get_theme_file_path("resources/json/core-block-whitelist.json"));
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import.meta.glob([
|
|||||||
'../fonts/**',
|
'../fonts/**',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
import Header from './sections/header.js';
|
import Header from '../views/sections/header/header.js';
|
||||||
import LazyLoad from './lib/Lazy.js';
|
import LazyLoad from './lib/Lazy.js';
|
||||||
|
|
||||||
LazyLoad();
|
LazyLoad();
|
||||||
|
|||||||
@@ -1,23 +1,51 @@
|
|||||||
import domReady from '@wordpress/dom-ready';
|
import domReady from '@wordpress/dom-ready';
|
||||||
import blockWhitelist from '../json/core-block-whitelist.json';
|
|
||||||
|
|
||||||
domReady(() => {
|
domReady(() => {
|
||||||
|
|
||||||
const restrictEditorParentBlocks = (settings, name) => {
|
const restrictEditorParentBlocks = (settings, name) => {
|
||||||
const TEXT_EDITOR_BLOCKS = blockWhitelist;
|
const TEXT_EDITOR_BLOCKS = [
|
||||||
|
// Design
|
||||||
|
'core/separator',
|
||||||
|
'core/spacer',
|
||||||
|
|
||||||
|
// Media
|
||||||
|
'core/cover',
|
||||||
|
'core/file',
|
||||||
|
'core/gallery',
|
||||||
|
'core/image',
|
||||||
|
'core/media-text',
|
||||||
|
'core/audio',
|
||||||
|
'core/video',
|
||||||
|
|
||||||
|
// Text
|
||||||
|
'core/footnotes',
|
||||||
|
'core/heading',
|
||||||
|
'core/list',
|
||||||
|
'core/code',
|
||||||
|
'core/details',
|
||||||
|
'core/freeform',
|
||||||
|
'core/list-item',
|
||||||
|
'core/missing',
|
||||||
|
'core/paragraph',
|
||||||
|
'core/preformatted',
|
||||||
|
'core/pullquote',
|
||||||
|
'core/quote',
|
||||||
|
'core/table',
|
||||||
|
'core/verse',
|
||||||
|
];
|
||||||
|
|
||||||
if (TEXT_EDITOR_BLOCKS.includes(name)) {
|
if (TEXT_EDITOR_BLOCKS.includes(name)) {
|
||||||
settings.parent = [
|
settings.parent = ['acf/badegg-editor']
|
||||||
'acf/badegg-editor',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// console.log(settings, name)
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
wp.hooks.addFilter(
|
wp.hooks.addFilter(
|
||||||
'blocks.registerBlockType',
|
'blocks.registerBlockType',
|
||||||
'badegg/restrict-parent-blocks',
|
'your-project-name/restrict-parent-blocks',
|
||||||
restrictEditorParentBlocks
|
restrictEditorParentBlocks
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
102
web/app/themes/badegg/resources/json/core-block-blacklist.json
Normal file
102
web/app/themes/badegg/resources/json/core-block-blacklist.json
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
[
|
||||||
|
"core/button",
|
||||||
|
"core/comment-template",
|
||||||
|
"core/home-link",
|
||||||
|
"core/navigation-link",
|
||||||
|
"core/navigation-submenu",
|
||||||
|
"core/buttons",
|
||||||
|
"core/column",
|
||||||
|
"core/columns",
|
||||||
|
"core/group",
|
||||||
|
"core/more",
|
||||||
|
"core/nextpage",
|
||||||
|
"core/separator",
|
||||||
|
"core/spacer",
|
||||||
|
"core/text-columns",
|
||||||
|
|
||||||
|
"core/embed",
|
||||||
|
|
||||||
|
"core/cover",
|
||||||
|
"core/file",
|
||||||
|
"core/gallery",
|
||||||
|
"core/image",
|
||||||
|
"core/media-text",
|
||||||
|
"core/audio",
|
||||||
|
"core/video",
|
||||||
|
|
||||||
|
"core/block",
|
||||||
|
|
||||||
|
"core/footnotes",
|
||||||
|
"core/heading",
|
||||||
|
"core/list",
|
||||||
|
"core/code",
|
||||||
|
"core/details",
|
||||||
|
"core/freeform",
|
||||||
|
"core/list-item",
|
||||||
|
"core/missing",
|
||||||
|
"core/paragraph",
|
||||||
|
"core/preformatted",
|
||||||
|
"core/pullquote",
|
||||||
|
"core/quote",
|
||||||
|
"core/table",
|
||||||
|
"core/verse",
|
||||||
|
|
||||||
|
"core/avatar",
|
||||||
|
"core/comment-author-name",
|
||||||
|
"core/comment-content",
|
||||||
|
"core/comment-date",
|
||||||
|
"core/comment-edit-link",
|
||||||
|
"core/comment-reply-link",
|
||||||
|
"core/comments",
|
||||||
|
"core/comments-pagination",
|
||||||
|
"core/comments-pagination-next",
|
||||||
|
"core/comments-pagination-numbers",
|
||||||
|
"core/comments-pagination-previous",
|
||||||
|
"core/comments-title",
|
||||||
|
"core/loginout",
|
||||||
|
"core/navigation",
|
||||||
|
"core/pattern",
|
||||||
|
"core/post-author",
|
||||||
|
"core/post-author-biography",
|
||||||
|
"core/post-author-name",
|
||||||
|
"core/post-comments-form",
|
||||||
|
"core/post-content",
|
||||||
|
"core/post-date",
|
||||||
|
"core/post-excerpt",
|
||||||
|
"core/post-featured-image",
|
||||||
|
"core/post-navigation-link",
|
||||||
|
"core/post-template",
|
||||||
|
"core/post-terms",
|
||||||
|
"core/post-title",
|
||||||
|
"core/query",
|
||||||
|
"core/query-no-results",
|
||||||
|
"core/query-pagination",
|
||||||
|
"core/query-pagination-next",
|
||||||
|
"core/query-pagination-numbers",
|
||||||
|
"core/query-pagination-previous",
|
||||||
|
"core/query-title",
|
||||||
|
"core/read-more",
|
||||||
|
"core/site-logo",
|
||||||
|
"core/site-tagline",
|
||||||
|
"core/site-title",
|
||||||
|
"core/template-part",
|
||||||
|
"core/term-description",
|
||||||
|
"core/post-comments",
|
||||||
|
|
||||||
|
"core/legacy-widget",
|
||||||
|
"core/widget-group",
|
||||||
|
"core/archives",
|
||||||
|
"core/calendar",
|
||||||
|
"core/categories",
|
||||||
|
"core/latest-comments",
|
||||||
|
"core/latest-posts",
|
||||||
|
"core/page-list",
|
||||||
|
"core/page-list-item",
|
||||||
|
"core/rss",
|
||||||
|
"core/search",
|
||||||
|
"core/shortcode",
|
||||||
|
"core/social-link",
|
||||||
|
"core/tag-cloud",
|
||||||
|
"core/html",
|
||||||
|
"core/social-links"
|
||||||
|
]
|
||||||
@@ -35,7 +35,7 @@ class Editor
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render($block, $content = '', $is_preview = false)
|
public function render($block, string $content = '', bool $is_preview = false, int $post_id = 0)
|
||||||
{
|
{
|
||||||
$name = basename(__FILE__, '.php');
|
$name = basename(__FILE__, '.php');
|
||||||
$themeURL = get_template_directory_uri();
|
$themeURL = get_template_directory_uri();
|
||||||
@@ -66,7 +66,7 @@ class Editor
|
|||||||
|
|
||||||
$data = array_merge($data, $block);
|
$data = array_merge($data, $block);
|
||||||
$data['section_classes'] = $CssClasses->section($data);
|
$data['section_classes'] = $CssClasses->section($data);
|
||||||
$data['allowed_blocks'] = $this->inner_blocks();
|
$data['allowed_blocks'] = \App\block_whitelist();
|
||||||
$data['template'] = $this->default_template();
|
$data['template'] = $this->default_template();
|
||||||
$data['block'] = $block;
|
$data['block'] = $block;
|
||||||
|
|
||||||
@@ -100,38 +100,4 @@ class Editor
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function inner_blocks()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
// Design
|
|
||||||
'core/separator',
|
|
||||||
'core/spacer',
|
|
||||||
|
|
||||||
// Media
|
|
||||||
'core/cover',
|
|
||||||
'core/file',
|
|
||||||
'core/gallery',
|
|
||||||
'core/image',
|
|
||||||
'core/media-text',
|
|
||||||
'core/audio',
|
|
||||||
'core/video',
|
|
||||||
|
|
||||||
// Text
|
|
||||||
'core/footnotes',
|
|
||||||
'core/heading',
|
|
||||||
'core/list',
|
|
||||||
'core/code',
|
|
||||||
'core/details',
|
|
||||||
'core/freeform',
|
|
||||||
'core/list-item',
|
|
||||||
'core/missing',
|
|
||||||
'core/paragraph',
|
|
||||||
'core/preformatted',
|
|
||||||
'core/pullquote',
|
|
||||||
'core/quote',
|
|
||||||
'core/table',
|
|
||||||
'core/verse',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ export default function Header() {
|
|||||||
const position = body.offsetTop;
|
const position = body.offsetTop;
|
||||||
const header = document.querySelector(".site-header");
|
const header = document.querySelector(".site-header");
|
||||||
|
|
||||||
|
if(!header) return;
|
||||||
|
|
||||||
if (scrolled > position + header.offsetHeight) {
|
if (scrolled > position + header.offsetHeight) {
|
||||||
body.classList.add("scrolled");
|
body.classList.add("scrolled");
|
||||||
} else {
|
} else {
|
||||||
Reference in New Issue
Block a user