1

I would like to create a block for Gutenberg. I currently have a default configuration:

function my_block_category($categories, $post)
{
    return array_merge(
        $categories,
        array(
            array(
                'slug' => 'my-block',
                'title' => __('BLOCK', 'my-block'),
            ),
        )
    );
}
add_filter('block_categories', 'my_block_category', 10, 2);

function gutenberg_boilerplate_block()
{
    wp_register_script(
        'myblock',
        plugins_url('js/gutenberg' . DIRECTORY_SEPARATOR . 'block.js'),
        array('wp-blocks', 'wp-element')
    );

    register_block_type('myblock/shortcodes', array(
        'editor_script' => 'myblock',
    ));
}
add_action('init', 'gutenberg_boilerplate_block');

It works. I get my category. The goal is that I get a Dropdown Select in my category, which is filled from a JSON file.

{
    "text": {
        "text": "Home",
        "value": "[home]",
        "content": "0"
    },
    ....
}

However, I currently have no idea how I can implement that? The shortcodes that are output are evaluated by the plugin.

Can you tell me how this can be done?

4
  • You want to include the json file data inside your script or inside your php?
    – Alvaro
    Jan 18, 2019 at 11:00
  • where I embed this I do not really care or I do not know the benefits of each option. I just want the values ​​to be available in a dropdown. If there is a preferable method here, I would choose this course
    – 180690
    Jan 21, 2019 at 6:17
  • But are those categories already registered in the page or do you need to register them from the Json data as well?
    – Alvaro
    Jan 21, 2019 at 12:11
  • I need to register them from the Json data.
    – 180690
    Jan 22, 2019 at 6:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.