name = 'blocks_editor'; $this->label = __( 'Block Editor', 'frontend-admin' ); $this->category = 'content'; $this->defaults = array( 'tabs' => 'all', 'toolbar' => 'full', 'media_upload' => 1, 'default_value' => '', 'delay' => 0, ); //add_filter( 'frontend_admin/forms/sanitize_input', [ $this, 'sanitize_field_input' ], 10, 3 ); add_action( 'frontend_admin/form_assets/type=blocks_editor', array( $this, 'form_assets' ) ); add_action( 'frontend_admin/form_assets/type=post_content', array( $this, 'form_assets' ) ); add_action( 'frontend_admin/form_assets/type=product_description', array( $this, 'form_assets' ) ); } /** * Sanitize the data of the field's input * * @param bool $sanitized Whether or not we sanitized the data * @param mixed $input Form input to sanitize * @param array $field An array holding all the field's data * * @return string */ public function sanitize_field_input( $sanitized, $input, $field ) { if( $this->name != $field['type'] ) return $sanitized; return $input; } /** * Load any third-party blocks * * @return void */ private function load_extra_blocks() { // phpcs:ignore $GLOBALS['hook_suffix'] = ''; /** * @psalm-suppress MissingFile */ require_once ABSPATH . 'wp-admin/includes/class-wp-screen.php'; /** * @psalm-suppress MissingFile */ require_once ABSPATH . 'wp-admin/includes/screen.php'; /** * @psalm-suppress MissingFile */ require_once ABSPATH . 'wp-admin/includes/post.php'; // Fake a WP_Screen object so we can pretend we're in the block editor, and therefore other block libraries load set_current_screen(); $current_screen = get_current_screen(); if ( $current_screen ) { $current_screen->is_block_editor( true ); } } /** * Restrict TinyMCE to the basics * * @param array $settings TinyMCE settings. * @return array */ public function tiny_mce_before_init( $settings ) { $settings['toolbar1'] = 'bold,italic,bullist,numlist,blockquote,pastetext,removeformat,undo,redo'; $settings['toolbar2'] = ''; return $settings; } /** * Ensure media works in Gutenberg * * @return void */ public function setup_media() { // If we've already loaded the media stuff then don't do it again if ( did_action( 'wp_enqueue_media' ) > 0 ) { return; } /** * @psalm-suppress MissingFile */ require_once ABSPATH . 'wp-admin/includes/media.php'; wp_enqueue_media(); } /* * input_admin_enqueue_scripts * * description * * @type function * @date 16/12/2015 * @since 5.3.2 * * @param $post_id (int) * @return $post_id (int) */ function form_assets( $field ) { if( isset( $field['field_type'] ) && 'blocks_editor' != $field['field_type'] ){ return; } global $block_assets, $post, $editor_assets; //try to get editor assets if( empty( $editor_assets ) ) $editor_assets = include_once FEA_DIR . '/assets/build/frontend-block-editor/index.asset.php'; //return if there are no editor assets if( empty( $editor_assets ) ) return; wp_enqueue_script( 'fea-block-editor', FEA_URL . 'assets/build/frontend-block-editor/index.js', $editor_assets['dependencies'], $editor_assets['version'], true ); wp_enqueue_style( 'fea-isolated-editor', FEA_URL . 'assets/build/frontend-block-editor.css', [], $editor_assets['version'] ); wp_enqueue_style( 'fea-block-editor', FEA_URL . 'assets/css/block-editor-min.css', [], $editor_assets['version'] ); } /** * Create the HTML interface for your field * * @param array $field An array holding all the field's data * * @type action * @since 3.6 * @date 23/01/13 */ function render_field( $field ) { $js_deps = include_once FEA_DIR . '/assets/build/frontend-block-editor/index.asset.php'; $js_url = FEA_URL . 'assets/build/frontend-block-editor/index.js'; wp_enqueue_script( 'fea-block-editor', $js_url, $js_deps['dependencies'], $js_deps['version'], true ); //enqueueu //unpkg.com/grapesjs/dist/css/grapes.min.css wp_enqueue_style( 'fea-grapesjs', 'https://unpkg.com/grapesjs/dist/css/grapes.min.css', array(), '0.17.29' ); wp_enqueue_style( 'fea-block-editor', FEA_URL . '/assets/build/frontend-block-editor.css', array(), $js_deps['version'] ); echo '