All sounds possible. Look into https://wordpress.org/plugins/advanced-custom-fields/ if you’re not familiar with it.A user with Editor level access can not edit/delete any of the Admin created blocks.
Hi @tugbucket,
I appreciate you taking the time to respond.
However that is not quite what I mean.
I’ve been using ACF since it came out so I am very familair with it.
However it uses fields, not blocks.
With a custom fields plugin you develop the fields, and attach them to a CPT. Then you write code to display those fields in a template for the CPT.
The user sees fields, not blocks. For example, there is no block properties window shown with fields.
If you are familiar with WP blocks, such as the Gutenberg editor, you will know that with blocks, a user fills in the blocks, saves the entry, and then can view the entry on the front end. No need to write code to display fields since fields are not being used.
What I am asking about is about presenting a user with a standard set of blocks to fill in, with the associated block properties window.
Hi @sterndata,
Thanks for your input.
https://www.advancedcustomfields.com/resources/blocks/ is to develop custom (non-existing) blocks using the great ACF plugin.
However I mean using existing blocks, such as WP core blocks such as Cover, Paragraph, etc, and not using a custom field plugin such as ACF.
If you can imagine a user creating a new entry of a page, with different blocks in it, such as Heading, Image, Gallery, etc.
Now take that set of blocks in that page, and make it a standard page with those blocks. Where, when a user creates a new entry of that page, all they see is those blocks to be entered info into. No blocks can be deleted or added…..
Of course, the “page” woudl be better to not be the standard built in Page post type, it would be better to first create a custom CPT and add a set of standard blocks to it.
That is what I am trying to ask about…….
/* guttenburg post template */
/* https://developer.wordpress.org/block-editor/developers/block-api/block-templates/ */
/* https://www.billerickson.net/gutenberg-block-templates/ */
function myplugin_register_template() {
$post_type_object = get_post_type_object( 'post' );
$post_type_object->template = array(
array( 'core/heading', array( 'level' => '5', 'content' => 'Paragraph' ) ),
array( 'core/paragraph' ),
array( 'core/heading', array( 'level' => '5', 'content' => 'Image' ) ),
array( 'core/image' ),
);
$post_type_object->template_lock = 'all';
}
add_action( 'init', 'myplugin_register_template' );
that’ll get you a Heading, a Paragraph (with heading) and Image (with heading).
-
This reply was modified 3 years, 11 months ago by tugbucket.
Hi @tugbucket,
Thanks!
That is exactly what I was looking for!
I wasn’t even sure if it could be done.
I look forward to trying your sample code in near future and learning more about how it works, how to add other blocks, etc.
I know enough about WP coding to understand your sample code, so I can see now how I can proceed.
So you just helped me a great deal by pointing out what to do….
Would it be correct to say:
$post_type_object->template_lock = 'all';
Prevents additions and deletions of blocks?
there is a reference to: https://www.billerickson.net/gutenberg-block-templates/ in that code block. it’s a great run down of what it all does.
I just took a look – thanks again!!