admin管理员组文章数量:1134247
I would like to create a new block, "Custom Paragraph," based on the "core/paragraph" block but with the color and typography options removed in the inspector controls. I've written the following plugin but upon activation, the "Custom Paragraph" block does not appear in my available block list.
My knowledge of creating a custom block using PHP is limited and any help would be appreciated.
<?php
/*
Plugin Name: Custom Paragraph Block
Plugin URI: /
Description: A custom paragraph block.
Version: 1.0
Author: Your Name
Author URI: /
*/
function custom_paragraph_block_settings( $settings, $blockname ) {
if ( $blockname !== 'core/paragraph-custom' ) {
return $settings;
}
// Remove 'color' and 'typography' settings from the inspector controls.
unset( $settings['supports']['color'] );
unset( $settings['supports']['typography'] );
return $settings;
}
add_filter( 'register_block_type_args', 'custom_paragraph_block_settings', 10, 2 );
function register_custom_paragraph_block() {
$args = array(
'attributes' => array(),
'render_callback' => 'render_custom_paragraph_block',
'supports' => array(
'align' => true,
),
);
register_block_type( 'core/paragraph-custom', $args );
}
add_action( 'init', 'register_custom_paragraph_block' );
function render_custom_paragraph_block( $attributes ) {
// Extract the 'content' and 'customAttribute' attributes from the $attributes array.
$content = isset( $attributes['content'] ) ? $attributes['content'] : '';
$customAttribute = isset( $attributes['customAttribute'] ) ? $attributes['customAttribute'] : '';
return '<p class="custom-paragraph">' . wp_kses_post( $content ) . '</p>';
}```
本文标签: pluginsCustom block based off core block using filter
版权声明:本文标题:plugins - Custom block based off core block using filter 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736851585a1955530.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论