Compare commits

...

12 Commits

Author SHA1 Message Date
e692225429 stop loading blocks in main app.js 2025-12-09 22:11:20 +00:00
76290560de block whitelist json 2025-12-09 22:10:55 +00:00
73aaf300ae remove BadExample css 2025-12-09 22:10:35 +00:00
ddbc6ad468 remove old code 2025-12-09 22:09:49 +00:00
70988bf19b move Blocks.php stuff alongside top level includes 2025-12-09 22:07:50 +00:00
a233611582 use json file for block whitelist 2025-12-09 22:06:47 +00:00
6c6b028bf1 basic block styles within editor 2025-12-09 22:04:29 +00:00
3db971e2f4 remove blocks.js 2025-12-09 22:02:59 +00:00
d49d6720fe tweak acf block settings 2025-12-09 22:02:24 +00:00
ae35f92d4d add $wpblue var 2025-12-09 22:01:52 +00:00
4508bc33e9 fix container width in blocks 2025-12-09 22:01:23 +00:00
9528b61867 update .editorconfig 2025-12-09 21:57:25 +00:00
15 changed files with 133 additions and 255 deletions

View File

@@ -1,15 +1,25 @@
root = true root = true
[*] [*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space indent_style = space
indent_size = 2 indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true quote_type = single
[*.php]
indent_size = 2
[*.md] [*.md]
trim_trailing_whitespace = false trim_trailing_whitespace = false
[*.php]
indent_size = 4
[*.blade.php]
indent_size = 2
[resources/views/**.php]
indent_size = 2
[index.php]
indent_size = 2

View File

@@ -1,155 +0,0 @@
<?php
namespace App\Admin;
use Blocks\Editor;
class Blocks
{
public function __construct()
{
add_filter( 'block_categories_all' , [$this, 'categories']);
add_action('allowed_block_types_all', [$this, 'blacklist'], 100, 2);
}
public function categories( $categories )
{
// Adding a new category.
$categories = array_merge([
[
'slug' => 'badegg',
'title' => __('Provided by Bad Egg Digital'),
],
], $categories);
return $categories;
}
public function blacklist()
{
// Reference:
// https://www.wpexplorer.com/how-to-remove-gutenberg-blocks/
// https://www.wpexplorer.com/wordpress-core-blocks-list/
// Existing blocks with Blade templates
// https://roots.io/acorn/docs/rendering-blade-views/#existing-blocks-with-blade-templates
$blocks = array_keys( \WP_Block_Type_Registry::get_instance()->get_all_registered() );
$blacklist = [
// Design
'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',
// Embed
'core/embed',
// Media
'core/cover',
'core/file',
'core/gallery',
'core/image',
'core/media-text',
'core/audio',
'core/video',
// Reusable
'core/block',
// 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',
// Theme
'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',
// Widgets
'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',
];
$Editor = new Editor\Editor();
$blacklist = array_diff($blacklist, $Editor->inner_blocks());
return array_values( array_diff( $blocks, $blacklist ) );
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Theme Blocks.
*/
namespace App;
add_filter( 'block_categories_all' , function ( $categories ) {
// Adding a new category.
$categories = array_merge([
[
'slug' => 'badegg',
'title' => __('Provided by Bad Egg Digital'),
],
], $categories);
return $categories;
});
add_action('allowed_block_types_all', function(){
$blocks = block_all();
$blacklist = array_diff($blocks, block_whitelist());
return array_values( array_diff( $blocks, $blacklist ) );
}, 100, 2);
function block_whitelist()
{
$file = file_get_contents(get_theme_file_path("resources/json/core-block-whitelist.json"));
$json = json_decode($file);
return $json;
}
function block_all()
{
$enabled_blocks = array_map(function($block) {
$name = $block->name;
return $block->name;
}, \WP_Block_Type_Registry::get_instance()->get_all_registered());
return array_values($enabled_blocks);
}
add_action('wp_footer', function(){
echo '<pre>',print_r(block_all()),'</pre>';
});

View File

@@ -46,16 +46,6 @@ add_filter('admin_head', function () {
])->toHtml(); ])->toHtml();
}); });
add_action( 'enqueue_block_editor_assets', function(){
wp_enqueue_script(
'restrict-core-blocks',
Vite::asset('resources/js/admin/block-restrictions.js'),
array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-blocks', 'wp-hooks' ),
'v1.0.0',
true
);
});
/** /**
* Use the generated theme.json file. * Use the generated theme.json file.
* *

View File

@@ -85,7 +85,7 @@ autoload_psr4_blocks();
| |
*/ */
collect(['setup', 'filters']) collect(['setup', 'filters', 'blocks'])
->each(function ($file) { ->each(function ($file) {
if (! locate_template($file = "app/{$file}.php", true, true)) { if (! locate_template($file = "app/{$file}.php", true, true)) {
wp_die( wp_die(

View File

@@ -17,7 +17,7 @@
"id": "" "id": ""
}, },
"open": 0, "open": 0,
"multi_expand": 0, "multi_expand": 1,
"endpoint": 0 "endpoint": 0
}, },
{ {
@@ -55,19 +55,22 @@
"id": "" "id": ""
}, },
"choices": { "choices": {
"0": "Full Width", "full": "Full Width",
"large": "Large", "large": "Large",
"medium": "Medium", "medium": "Medium",
"small": "Small", "small": "Small",
"narrow": "Narrow" "narrow": "Narrow"
}, },
"default_value": 0, "default_value": "medium",
"return_format": "value", "return_format": "value",
"multiple": 0, "multiple": 0,
"allow_null": 0, "allow_null": 0,
"allow_in_bindings": 1,
"ui": 0, "ui": 0,
"ajax": 0, "ajax": 0,
"placeholder": "" "placeholder": "",
"create_options": 0,
"save_options": 0
}, },
{ {
"key": "field_67350eb62cdf9", "key": "field_67350eb62cdf9",
@@ -133,8 +136,8 @@
"class": "", "class": "",
"id": "" "id": ""
}, },
"open": 0, "open": 1,
"multi_expand": 0, "multi_expand": 1,
"endpoint": 0 "endpoint": 0
}, },
{ {
@@ -159,28 +162,6 @@
"prefix_label": 0, "prefix_label": 0,
"prefix_name": 0 "prefix_name": 0
}, },
{
"key": "field_67fff4d4ddbb7",
"label": "Angle",
"name": "angle",
"aria-label": "",
"type": "clone",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"clone": [
"group_clone_angle"
],
"display": "seamless",
"layout": "block",
"prefix_label": 1,
"prefix_name": 1
},
{ {
"key": "field_6828da67543fc", "key": "field_6828da67543fc",
"label": "Settings (end)", "label": "Settings (end)",
@@ -218,5 +199,5 @@
"active": true, "active": true,
"description": "", "description": "",
"show_in_rest": 0, "show_in_rest": 0,
"modified": 1747508044 "modified": 1764247227
} }

View File

@@ -18,9 +18,6 @@
@use "components/button"; @use "components/button";
@use "components/card"; @use "components/card";
// Blocks
@use "blocks/BadExample";
// Page Styles // Page Styles
@use "views/page"; @use "views/page";

View File

@@ -1,4 +1,18 @@
@use "./app"; @use "app";
@use "global/variables/colours";
.block-editor-block-list__layout .block-editor-block-list__block:not([contenteditable=true]) {
&:hover:after {
content: '';
outline: 2px solid colours.$wpblue;
position: absolute;
inset: 0;
}
&:focus:after {
outline-style: dashed;
}
}
.editor-styles-wrapper { .editor-styles-wrapper {
padding: 1em; padding: 1em;
@@ -10,11 +24,14 @@
max-width: none; max-width: none;
} }
.is-root-container > .wp-block:not(.block-list-appender) {
margin: 0;
}
.block-list-appender { .block-list-appender {
width: 350px; width: 350px;
max-width: 90%; max-width: 90%;
margin: 1em auto; margin: 1em auto;
background: white;
} }
&__post-title-wrapper { &__post-title-wrapper {
@@ -45,9 +62,4 @@
font-weight: 400; font-weight: 400;
} }
} }
.wp-block-post-content {
// background: white;
// box-shadow: 0 0.5rem 1rem rgba(black, 0.15);
}
} }

View File

@@ -1,5 +1,7 @@
@use "sass:color"; @use "sass:color";
$wpblue: #2271b1;
//== Status //== Status
$success: #39b54a; $success: #39b54a;
$error: #be1e2d; $error: #be1e2d;

View File

@@ -3,10 +3,8 @@ import.meta.glob([
'../fonts/**', '../fonts/**',
]); ]);
import blocks from './blocks.js';
import Header from './sections/header.js'; import Header from './sections/header.js';
import LazyLoad from './lib/Lazy.js'; import LazyLoad from './lib/Lazy.js';
LazyLoad(); LazyLoad();
blocks();
Header(); Header();

View File

@@ -1,6 +0,0 @@
// import BadExample from "./blocks/BadExample";
export default function()
{
// BadExample();
}

View File

@@ -1,51 +1,23 @@
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 = [ const TEXT_EDITOR_BLOCKS = blockWhitelist;
// 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 = ['acf/badegg-editor'] settings.parent = [
'acf/badegg-editor',
];
} }
// console.log(settings, name)
return settings return settings
} }
wp.hooks.addFilter( wp.hooks.addFilter(
'blocks.registerBlockType', 'blocks.registerBlockType',
'your-project-name/restrict-parent-blocks', 'badegg/restrict-parent-blocks',
restrictEditorParentBlocks restrictEditorParentBlocks
); );

View File

@@ -0,0 +1,26 @@
[
"core/separator",
"core/spacer",
"core/cover",
"core/file",
"core/gallery",
"core/image",
"core/media-text",
"core/audio",
"core/video",
"core/footnotes",
"core/heading",
"core/list",
"core/code",
"core/details",
"core/list-item",
"core/missing",
"core/paragraph",
"core/preformatted",
"core/pullquote",
"core/quote",
"core/table",
"core/verse"
]

View File

@@ -10,7 +10,7 @@
"> ">
<div class="section-{{ $block['name'] }}-inner"> <div class="section-{{ $block['name'] }}-inner">
<div class="container{{ @$data['container_width'] ? ' container-' . $data['container_width'] : '' }} block-content wysiwyg"> <div class="container container-{{ @$data['container_width'] ? $data['container_width'] : 'medium' }} block-content wysiwyg">
<InnerBlocks <InnerBlocks
allowedBlocks="{!! esc_attr( wp_json_encode( $data['allowed_blocks'] ) ) !!}" allowedBlocks="{!! esc_attr( wp_json_encode( $data['allowed_blocks'] ) ) !!}"
template="{!! esc_attr( wp_json_encode( $data['template'] ) ) !!}" template="{!! esc_attr( wp_json_encode( $data['template'] ) ) !!}"

View File

@@ -29,7 +29,7 @@
</div> </div>
@endif @endif
<div class="container{{ @$data['container_width'] ? ' container-' . $data['container_width'] : '' }} block-content"> <div class="container container-{{ @$data['container_width'] ? $data['container_width'] : 'medium' }} block-content">
@yield('block-content') @yield('block-content')
</div> </div>