'dashicons-editor-code', 'category' => 'specific', 'preview_image' => Consts::get_url() . 'admin/img/blocks/code.jpg', 'description' => __( "Syntax highlighting with custom themes for every languages.", 'advanced-gutenberg-blocks' ), 'options_callback' => array( $this, 'settings' ), 'credits_callback' => array( $this, 'credits' ), ); Blocks::register_block( 'advanced-gutenberg-blocks/code', __( 'Code', 'advanced-gutenberg-blocks' ), $args ); // Register settings Blocks::register_setting( 'advanced-gutenberg-blocks-code-theme' ); } public function settings() { $selected_theme = $this->get_selected_theme(); $select_html = ''; foreach( $this->get_theme_list() as $theme ) { $value = $theme['value']; $label = $theme['label']; $selected = ( $theme['value'] == $selected_theme ) ? ' selected ' : ''; $select_html .= ""; } echo '
' . __( 'what does it look like? Find it out here. ', 'advanced-gutenberg-blocks' ) . '
'; } public function credits() { echo '' . __('This block uses Code Mirror and React Code Mirror from Marijn Haverbeke and Jed Watson.', 'advanced-gutenberg-blocks' ) . '
'; } public function editor_assets() { wp_localize_script( Consts::BLOCKS_SCRIPT, 'advancedGutenbergBlocksCode', array( 'themes' => $this->get_theme_list(), 'selectedTheme' => $this->get_selected_theme(), 'languages' => $this->get_language_list(), ) ); } public function front_assets() { if ( has_block('advanced-gutenberg-blocks/code') ) { wp_enqueue_style( Consts::PLUGIN_NAME . '-code-mirror', Consts::get_url() . 'vendor/codemirror/codemirror.css', array(), Consts::VERSION ); // Enqueue Theme $theme = $this->get_selected_theme(); wp_enqueue_style( Consts::PLUGIN_NAME . '-code-mirror-theme', Consts::get_url() . "vendor/codemirror/themes/$theme.css", [ Consts::PLUGIN_NAME . '-code-mirror' ], Consts::VERSION ); wp_enqueue_script( Consts::PLUGIN_NAME . '-code-mirror', Consts::get_url() . 'vendor/codemirror/codemirror.js', array(), Consts::VERSION ); wp_enqueue_script( Consts::PLUGIN_NAME . '-code-mirror-matchbrackets', Consts::get_url() . 'vendor/codemirror/addons/edit/matchbrackets.js', array(), Consts::VERSION ); // Enqueue languages // -- First: get content and fetch used languages $content = get_post( $post_id ); $regex = "#