|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Blocks Initializer |
| 4 | + * |
| 5 | + * Enqueue CSS/JS of all the blocks. |
| 6 | + * |
| 7 | + * @since 1.0.0 |
| 8 | + * @package GSBE |
| 9 | + */ |
| 10 | + |
| 11 | +// Exit if accessed directly. |
| 12 | +if ( ! defined( 'ABSPATH' ) ) { |
| 13 | + exit; |
| 14 | +} |
| 15 | + |
| 16 | +function getdave_sbe_block_editor_init( $hook ) { |
| 17 | + |
| 18 | + if ( 'toplevel_page_getdavesbe' !== $hook ) { |
| 19 | + return; |
| 20 | + } |
| 21 | + |
| 22 | + $settings = array( |
| 23 | + 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), |
| 24 | + 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), |
| 25 | + // 'imageSizes' => $available_image_sizes, |
| 26 | + 'isRTL' => is_rtl(), |
| 27 | + // 'maxUploadFileSize' => $max_upload_size, |
| 28 | + ); |
| 29 | + list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' ); |
| 30 | + list( $font_sizes, ) = (array) get_theme_support( 'editor-font-sizes' ); |
| 31 | + if ( false !== $color_palette ) { |
| 32 | + $settings['colors'] = $color_palette; |
| 33 | + } |
| 34 | + if ( false !== $font_sizes ) { |
| 35 | + $settings['fontSizes'] = $font_sizes; |
| 36 | + } |
| 37 | + |
| 38 | + wp_enqueue_script( |
| 39 | + 'getdave_aht-cgb-block-js', // Handle. |
| 40 | + plugins_url( 'getdave-standalone-block-editor/build/index.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack. |
| 41 | + array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-block-library' ), // Dependencies, defined above. |
| 42 | + // filemtime( plugin_dir_path( __DIR__ ) . 'build/blocks.build.js' ), // Version: File modification time. |
| 43 | + true // Enqueue the script in the footer. |
| 44 | + ); |
| 45 | + |
| 46 | + wp_enqueue_style( 'wp-format-library' ); |
| 47 | + |
| 48 | + // Styles. |
| 49 | + // wp_enqueue_style( |
| 50 | + // 'getdave_aht-cgb-block-editor-css', // Handle. |
| 51 | + // plugins_url( 'build/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS. |
| 52 | + // array( 'wp-edit-blocks' ) // Dependency to include the CSS after it. |
| 53 | + // filemtime( plugin_dir_path( __DIR__ ) . 'build/blocks.editor.build.css' ) // Version: File modification time. |
| 54 | + // ); |
| 55 | +} |
| 56 | + |
| 57 | +add_action( 'admin_enqueue_scripts', 'getdave_sbe_block_editor_init' ); |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +/** |
| 67 | + * Registers the new WP Admin Menu |
| 68 | + * |
| 69 | + * @return void |
| 70 | + */ |
| 71 | +function getdave_sbe_add_menu_page() { |
| 72 | + global $submenu; |
| 73 | + |
| 74 | + add_menu_page( |
| 75 | + 'Standalone Block Editor', |
| 76 | + 'Block Editor', |
| 77 | + 'edit_posts', |
| 78 | + 'getdavesbe', // hook/slug of page |
| 79 | + 'getdave_sbe_render_block_editor', // function to render page |
| 80 | + 'dashicons-welcome-widgets-menus' |
| 81 | + ); |
| 82 | +} |
| 83 | +add_action( 'admin_menu', 'getdave_sbe_add_menu_page' ); |
| 84 | + |
| 85 | + |
| 86 | +/** |
| 87 | + * Renders the Menu Page |
| 88 | + * |
| 89 | + * @return void |
| 90 | + */ |
| 91 | +function getdave_sbe_render_block_editor() { |
| 92 | + ?> |
| 93 | + <div |
| 94 | + id="getdave-sbe-block-editor" |
| 95 | + class="getdave-sbe-block-editor" |
| 96 | + > |
| 97 | + Block Editor here |
| 98 | + </div> |
| 99 | + <?php |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | + |
0 commit comments