| @@ -45,14 +45,10 @@ | ||
| 45 | 45 | */ |
| 46 | 46 | public function init() { |
| 47 | 47 | $this->shortcode_data = WINP_Helper::get_shortcode_data(); |
| 48 | 48 | |
| 49 | - if ( empty( $this->shortcode_data ) ) { | |
| 50 | - return; | |
| 51 | - } | |
| 52 | - | |
| 53 | 49 | // Register the block type and get the WP_Block_Type instance. |
| 54 | - $block_type = register_block_type( WINP_PLUGIN_DIR . '/admin/assets/gutenberg/build/block.json' ); | |
| 50 | + $block_type = $this->register_block(); | |
| 55 | 51 | |
| 56 | 52 | /** |
| 57 | 53 | * Register snippets object, so it can be accessible within Gutenberg. |
| 58 | 54 | * The script handle is automatically generated by WordPress from the block name. |
| @@ -61,12 +57,22 @@ | ||
| 61 | 57 | wp_localize_script( |
| 62 | 58 | $block_type->editor_script_handles[0], |
| 63 | 59 | 'winp_snippets', |
| 64 | 60 | [ |
| 65 | - 'data' => $this->prepared_snippets_data(), | |
| 61 | + 'data' => $this->prepared_snippets_data(), | |
| 62 | + 'createUrl' => admin_url( 'post-new.php?post_type=' . WINP_SNIPPETS_POST_TYPE ), | |
| 66 | 63 | ] |
| 67 | 64 | ); |
| 68 | 65 | } |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Register the block type. | |
| 70 | + * | |
| 71 | + * @return WP_Block_Type|false | |
| 72 | + */ | |
| 73 | + protected function register_block() { | |
| 74 | + return register_block_type( WINP_PLUGIN_DIR . '/admin/assets/gutenberg/build/block.json' ); | |
| 69 | 75 | } |
| 70 | 76 | |
| 71 | 77 | /** |
| 72 | 78 | * Prepare snippets data for the block editor. |