最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Block developer cookbook. Plugin is not displaying anything

programmeradmin2浏览0评论

I have tried to make this plugin : /

So I have :

 /**
 * WordPress dependencies
 */
import { registerBlockVariation } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';

/**
 *  Register a parapgragh block variation with meta binding
 */
/**
 * Register a paragraph block variation with meta binding
 */
registerBlockVariation( 'core/paragraph', {
    name: 'show-my-data',
    title: __( 'Show My Data', 'block-binding-shortcut' ),
    description: __(
        'Display custom meta data in a paragraph',
        'block-binding-shortcut'
    ),
    attributes: {
        metadata: {
            bindings: {
                content: {
                    source: 'core/post-metadata', 
                    args: {
                        key: 'my_custom_data'
                    },
                },
            },
        },
    },
    isActive: ['metadata.bindings.content.args.key'],
    scope: [ 'inserter', 'transform' ],
} );

and

<?php
/**
 * Plugin Name:       Preset Block Bindings
 * Description:       Using a block variation to preset block bindings.
 * Requires at least: 6.1
 * Requires PHP:      7.0
 * Version:           1.0.2
 * Author:            The WordPress Contributors
 * License:           GPL-2.0-or-later
 * License URI:       .0.html
 * Text Domain:       preset-block-bindings
 *
 * @package block-developers-cookbook
 */

namespace BlockDevelopersCookbook;

add_action(
    'init',
    function() {
        register_post_meta(
            'post',
            'my_custom_data',
            array(
                'show_in_rest'  => true,
                'single'        => true,
                'type'          => 'string',
                'auth_callback' => function() {
                    return current_user_can( 'edit_posts' );
                },
                'default'       => 'This is a default value',
            )
        );
    }
);
/**
 * Register the block editor assets.
 */
add_action(
    'enqueue_block_editor_assets',
    function() {
        $block_binding_shortcut_file = plugin_dir_path( __FILE__ ) . '/build/block-binding-shortcut.asset.php';

        if ( file_exists( $block_binding_shortcut_file ) ) {
            $assets = include $block_binding_shortcut_file;
            wp_enqueue_script(
                'block-binding-shortcut',
                plugin_dir_url( __FILE__ ) . '/build/block-binding-shortcut.js',
                $assets['dependencies'],
                $assets['version'],
                true
            );
        }
    }
);

but on my wordpress nothing happens when I use this plugin. I do not see the text as described in the tutorial Anyone who can help me figure out what went wrong ?

发布评论

评论列表(0)

  1. 暂无评论