Created
October 4, 2019 09:44
-
-
Save razwan/115bec953d0a4c4d2a95ab0d901d3d60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Gutenberg Test | |
* Description: Gutenberg Test | |
* Version: 0.0.0 | |
*/ | |
function gutenberg_test_register_meta() { | |
register_meta( 'post', 'my_block_meta', array( | |
'type' => 'number', | |
'single' => true, | |
'show_in_rest' => true, | |
) ); | |
} | |
add_action( 'init', 'gutenberg_test_register_meta' ); | |
if ( ! function_exists( 'gutenberg_test_my_block_init' ) ) { | |
function gutenberg_test_my_block_init() { | |
register_block_type( 'gutenberg-test/block', array( | |
'attributes' => array( | |
'my_attribute' => array( | |
'type' => 'string', | |
'source' => 'meta', | |
'meta' => 'my_block_meta', | |
), | |
), | |
'render_callback' => 'gutenberg_test_render_my_block' | |
) ); | |
} | |
} | |
add_action( 'init', 'gutenberg_test_my_block_init', 20 ); | |
if ( ! function_exists( 'gutenberg_test_render_my_block' ) ) { | |
function gutenberg_test_render_my_block( $attributes, $content ) { | |
return 'Gutenberg Test Block'; | |
} | |
} | |
function gutenberg_test_editor_assets() { | |
wp_enqueue_script( 'gutenberg-test-js', plugins_url( null, __FILE__ ) . '/gutenberg-test-scripts.js', array( 'wp-blocks', 'wp-element' ), '0.0.0', true ); | |
} | |
add_action( 'enqueue_block_editor_assets', 'gutenberg_test_editor_assets' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment