name = 'block_editor'; $this->label = __( 'Block Editor', 'frontend-admin' ); $this->category = 'content'; $this->public = true; $this->defaults = array( 'tabs' => 'all', 'toolbar' => 'full', 'media_upload' => 1, 'default_value' => '', 'delay' => 0, ); // add acf_the_content filters $this->add_filters(); // actions add_action( 'acf/enqueue_uploader', array( $this, 'acf_enqueue_uploader' ) ); add_action( 'acf/prepare_field/type=wysiwyg', array( $this, 'prepare_field' ) ); } /* * prepare_field() * * Prepares field setting prior to rendering field in form * * @param $field - an array holding all the field's data * @return $field * * @type action * @since 3.6 * @date 23/01/13 */ function prepare_field( $field ) { $field = array_merge( $this->defaults, $field ); if( feadmin_edit_mode() ){ $field['type'] = 'textarea'; $field['rows'] = 14; } return $field; } /* * add_filters * * This function will add filters to 'acf_the_content' * * @type function * @date 20/09/2016 * @since 5.4.0 * * @param n/a * @return n/a */ function add_filters() { // WordPress 5.5 introduced new function for applying image tags. $wp_filter_content_tags = function_exists( 'wp_filter_content_tags' ) ? 'wp_filter_content_tags' : 'wp_make_content_images_responsive'; // Mimic filters added to "the_content" in "wp-includes/default-filters.php". add_filter( 'acf_the_content', 'capital_P_dangit', 11 ); // add_filter( 'acf_the_content', 'do_blocks', 9 ); Not yet supported. add_filter( 'acf_the_content', 'wptexturize' ); add_filter( 'acf_the_content', 'convert_smilies', 20 ); add_filter( 'acf_the_content', 'wpautop' ); add_filter( 'acf_the_content', 'shortcode_unautop' ); // add_filter( 'acf_the_content', 'prepend_attachment' ); Causes double image on attachment page. add_filter( 'acf_the_content', $wp_filter_content_tags ); add_filter( 'acf_the_content', 'do_shortcode', 11 ); // Mimic filters added to "the_content" in "wp-includes/class-wp-embed.php" if ( isset( $GLOBALS['wp_embed'] ) ) { add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 ); add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 ); } } /* * get_toolbars * * This function will return an array of toolbars for the WYSIWYG field * * @type function * @date 18/04/2014 * @since 5.0.0 * * @param n/a * @return (array) */ function get_toolbars() { // vars $editor_id = 'acf_content'; $toolbars = array(); // mce buttons (Full) $mce_buttons = array( 'formatselect', 'bold', 'italic', 'bullist', 'numlist', 'blockquote', 'alignleft', 'aligncenter', 'alignright', 'link', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ); $mce_buttons_2 = array( 'strikethrough', 'hr', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' ); // mce buttons (Basic) $teeny_mce_buttons = array( 'bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright', 'undo', 'redo', 'link', 'fullscreen' ); // WP < 4.7 if ( acf_version_compare( 'wp', '<', '4.7' ) ) { $mce_buttons = array( 'bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ); $mce_buttons_2 = array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' ); } // Full $toolbars['Full'] = array( 1 => apply_filters( 'mce_buttons', $mce_buttons, $editor_id ), 2 => apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id ), 3 => apply_filters( 'mce_buttons_3', array(), $editor_id ), 4 => apply_filters( 'mce_buttons_4', array(), $editor_id ), ); // Basic $toolbars['Basic'] = array( 1 => apply_filters( 'teeny_mce_buttons', $teeny_mce_buttons, $editor_id ), ); // Filter for 3rd party $toolbars = apply_filters( 'acf/fields/wysiwyg/toolbars', $toolbars ); // return return $toolbars; } /* * acf_enqueue_uploader * * Registers toolbars data for the WYSIWYG field. * * @type function * @date 16/12/2015 * @since 5.3.2 * * @param void * @return void */ function acf_enqueue_uploader() { // vars $data = array(); $toolbars = $this->get_toolbars(); // loop if ( $toolbars ) { foreach ( $toolbars as $label => $rows ) { // vars $key = $label; $key = sanitize_title( $key ); $key = str_replace( '-', '_', $key ); // append $data[ $key ] = array(); if ( $rows ) { foreach ( $rows as $i => $row ) { $data[ $key ][ $i ] = implode( ',', $row ); } } } } // localize acf_localize_data( array( 'toolbars' => $data, ) ); } /** * 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' ); echo '