post_type ) ] ) ) { $allowed_blocks = array_merge( $allowed_blocks, THEME_SETTINGS['allowed_blocks'][ get_post_type( $post->post_type ) ] ); } return $allowed_blocks; } /** * Check whether to use classic or block editor for a certain post type as defined in the settings */ function use_block_editor_for_post_type( $use_block_editor, $post_type ) { if ( in_array( $post_type, THEME_SETTINGS['use_classic_editor'], true ) ) { return false; } return true; } /** * Enqueue block editor JavaScript and CSS */ function register_block_editor_assets() { // Make paths variables so we don't write them twice $editor_scripts = 'js/dist/block.js'; $editor_styles = 'css/gutenberg.min.css'; // Dependencies $dependencies = array( 'wp-blocks', // Provides useful functions and components for extending the editor 'wp-i18n', // Provides localization functions 'wp-element', // Provides React.Component 'wp-components', // Provides many prebuilt components and controls ); // Enqueue the bundled block JS file wp_enqueue_script( 'block-editor-js', get_theme_file_uri( $editor_scripts, __FILE__ ), $dependencies, filemtime( get_theme_file_path( $editor_scripts ) ), 'all' ); // Enqueue optional editor only styles wp_enqueue_style( 'block-editor-css', get_theme_file_uri( $editor_styles, __FILE__ ), $dependencies, filemtime( get_theme_file_path( $editor_styles ) ), 'all' ); } /** * Register Gutenberg wp-admin editor style */ function setup_editor_styles() { // Add support for editor styles. add_theme_support( 'editor-styles' ); // Enqueue editor styles. add_editor_style( get_theme_file_uri( 'css/gutenberg.min.css' ) ); }