-
-
Save DahmaniAdame/a51b32c8f3599faa134049dcb9ad69e1 to your computer and use it in GitHub Desktop.
Revisions
-
jmccall75 revised this gist
May 4, 2022 . 1 changed file with 19 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,27 +2,39 @@ "$schema": "http://schemas.wp.org/trunk/theme.json", "version": 2, "settings": { "appearanceTools": false, "color": { "text": false, "background": false, "link": false, "custom": false, "customDuotone": false, "customGradient": false, "defaultDuotone": false, "defaultGradients": false, "defaultPalette": false }, "layout": { "contentSize": null, "wideSize": null }, "spacing": { "blockGap": null, "margin": false, "padding": false, "units": [] }, "typography": { "customFontSize": false, "fontStyle": false, "fontWeight": false, "letterSpacing": false, "lineHeight": false, "textDecoration": false, "textTransform": false, "dropCap": false, "fontSizes": [], "fontFamilies": [] } } } -
jmccall75 revised this gist
May 4, 2022 . 2 changed files with 62 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,60 +1,81 @@ <?php /** * Gutenberg Block customization for this theme. */ // gutenberg disable for posts //add_filter('use_block_editor_for_post', '__return_false', 10); // gutenberg disable for post types //add_filter('use_block_editor_for_post_type', '__return_false', 10); /** *Disable gutenberg stylesheets in frontend; requires creating custom styles for allowed core blocks **/ function jjm_deregister_styles() { wp_dequeue_style( 'wp-block-library' ); } add_action( 'wp_print_styles', 'jjm_deregister_styles', 100 ); /** * Customize core block functionality */ function jjm_2022_block_setup() { // Sometimes you disable block functionality by adding theme support... add_theme_support( 'disable-custom-colors' ); // User-defined colors add_theme_support( 'disable-custom-gradients' ); // User-defined gradient add_theme_support( 'disable-custom-font-sizes' ); // User-defined font sizes add_theme_support('editor-font-sizes', array( // Define our own allowed font sizes here array( 'name' => 'Normal', 'size' => 20, 'slug' => 'normal' ) ) ); // And sometimes by removing theme support... remove_theme_support( 'block-templates' ); // Allows user to create their own templates from within the editor remove_theme_support( 'core-block-patterns' ); // Allows user to create their own block patterns from within the editor remove_theme_support( 'widgets-block-editor' ); // Revert to the classic widget editing experience } add_action( 'after_setup_theme', 'jjm_2022_block_setup' ); /** * Some functionality is easier to remove with JS. Or only possible to remove with JS. **/ add_action( 'init', 'jjm_remove_block_styles' ); function jjm_remove_block_styles() { // Register the block editor script. wp_register_script( 'remove-block-style', get_stylesheet_directory_uri() . '/assets/js/remove-block-styles.js', [ 'wp-blocks', 'wp-edit-post' ] ); // I'm actually not at all sure what this does. register_block_type( 'remove/block-style', [ 'editor_script' => 'remove-block-style', ] ); } /** * Back to removing functionality via PHP **/ function jjm_docs_block_editor_settings( $editor_settings, $editor_context ) { $editor_settings['__experimentalFeatures']['typography']['dropCap'] = false; return $editor_settings; } add_filter( 'block_editor_settings_all', 'jjm_docs_block_editor_settings', 10, 2 ); /************************************************ * Default Block Whitelist: only blocks in the whitelist are allowed ************************************************/ add_filter( 'allowed_block_types_all', 'jjm_allowed_block_types', 10, 2 ); function jjm_allowed_block_types( $allowed_block_types, $editor_context ) { $home_id = get_option('page_on_front'); $current_post_id = $editor_context->post->ID; if ( $current_post_id == $home_id ) { // Restrict block(s) allowed on homepage. return array( 'acf/home-feature', @@ -91,10 +112,10 @@ function jjm_allowed_block_types( $allowed_block_types, $editor_context ) { } /** * Disable the block editor by template and/or page_id. Reverts to classic editor. * Courtesty of Bill Erickson: * https://www.billerickson.net/disabling-gutenberg-certain-templates/ **/ function jjm_disable_editor( $id = false ) { $excluded_templates = array( This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,19 @@ // Remove formatting options for image block wp.domReady(() => { wp.blocks.unregisterBlockStyle('core/image', 'rounded'); wp.blocks.unregisterBlockStyle('core/image', 'default'); } ); // Whitelist on specific embed block variations // Thanks Ty Baily (https://www.linkedin.com/in/tylerb24890) const { getBlockVariations, unregisterBlockVariation } = wp.blocks; wp.domReady(() => { const allowedEmbedBlocks = ['vimeo', 'youtube', 'twitter', 'soundcloud']; // Only these are allowed getBlockVariations('core/embed').forEach(function (blockVariation) { if (allowedEmbedBlocks.indexOf(blockVariation.name) === -1) { unregisterBlockVariation('core/embed', blockVariation.name); } }); }); -
jmccall75 revised this gist
May 3, 2022 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,6 @@ function jjm_deregister_styles() { } add_action( 'wp_print_styles', 'jjm_deregister_styles', 100 ); /** * Theme Block defaults */ @@ -24,7 +23,6 @@ function jjm_2022_block_setup() { ) ); remove_theme_support( 'widgets-block-editor' ); } add_action( 'after_setup_theme', 'jjm_2022_block_setup' ); // Remove some block style options via JS (See below JS file) -
jmccall75 revised this gist
May 3, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,9 +11,9 @@ function jjm_deregister_styles() { */ function jjm_2022_block_setup() { add_theme_support( 'disable-custom-colors' ); add_theme_support( 'disable-custom-gradients' ); // Sometimes you add theme support to disable functionality remove_theme_support( 'block-templates' ); // This one was not easy to Google remove_theme_support( 'core-block-patterns' ); // Sometimes you remove theme support to disable functionality add_theme_support( 'disable-custom-font-sizes' ); add_theme_support('editor-font-sizes', array( // Can't seem to remove entirely, so limit to our "normal" font size array( -
jmccall75 revised this gist
May 3, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,8 +12,8 @@ function jjm_deregister_styles() { function jjm_2022_block_setup() { add_theme_support( 'disable-custom-colors' ); add_theme_support( 'disable-custom-gradients' ); remove_theme_support( 'block-templates' ); // This one was not easy to Google remove_theme_support( 'core-block-patterns' ); add_theme_support( 'disable-custom-font-sizes' ); add_theme_support('editor-font-sizes', array( // Can't seem to remove entirely, so limit to our "normal" font size array( -
jmccall75 revised this gist
May 3, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ function jjm_2022_block_setup() { add_theme_support( 'disable-custom-colors' ); add_theme_support( 'disable-custom-gradients' ); remove_theme_support( 'block-templates' ); remove_theme_support( 'core-block-patterns' ); // This one was not easy to Google add_theme_support( 'disable-custom-font-sizes' ); add_theme_support('editor-font-sizes', array( // Can't seem to remove entirely, so limit to our "normal" font size array( -
jmccall75 created this gist
May 3, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,136 @@ <?php //Disable gutenberg style in Front function jjm_deregister_styles() { wp_dequeue_style( 'wp-block-library' ); } add_action( 'wp_print_styles', 'jjm_deregister_styles', 100 ); if ( ! function_exists( 'jjm_2022_block_setup' ) ) : /** * Theme Block defaults */ function jjm_2022_block_setup() { add_theme_support( 'disable-custom-colors' ); add_theme_support( 'disable-custom-gradients' ); remove_theme_support( 'block-templates' ); remove_theme_support( 'core-block-patterns' ); add_theme_support( 'disable-custom-font-sizes' ); add_theme_support('editor-font-sizes', array( // Can't seem to remove entirely, so limit to our "normal" font size array( 'name' => 'Normal', 'size' => 20, 'slug' => 'normal' ) ) ); remove_theme_support( 'widgets-block-editor' ); } endif; add_action( 'after_setup_theme', 'jjm_2022_block_setup' ); // Remove some block style options via JS (See below JS file) add_action( 'init', 'jjm_remove_block_styles' ); function jjm_remove_block_styles() { // Register the block editor script. wp_register_script( 'remove-block-style', get_stylesheet_directory_uri() . '/assets/js/remove-block-styles.js', [ 'wp-blocks', 'wp-edit-post' ] ); // register block editor script. register_block_type( 'remove/block-style', [ 'editor_script' => 'remove-block-style', ] ); } // See you later dropcaps function jjm_docs_block_editor_settings( $editor_settings, $editor_context ) { $editor_settings['__experimentalFeatures']['typography']['dropCap'] = false; return $editor_settings; } add_filter( 'block_editor_settings_all', 'jjm_docs_block_editor_settings', 10, 2 ); /************************************************ * Default Block Whitelist ************************************************/ add_filter( 'allowed_block_types_all', 'jjm_allowed_block_types', 10, 2 ); function jjm_allowed_block_types( $allowed_block_types, $editor_context ) { $home_id = get_option('page_on_front'); $current_post_id = $editor_context->post->ID; if ( $current_post_id == $home_id ) { // Restrict block(s) allowed on homepage return array( 'acf/home-feature', 'acf/home-post', 'acf/products', 'acf/magazine-highlights', ); } else { // Restrict blocks in all other contexts return array( 'core/image', 'core/paragraph', 'core/heading', 'core/list', 'core/gallery', 'core/shortcode', 'core/audio', 'core/file', 'core/video', 'core/verse', 'core/html', //'core/pullquote', 'core/preformatted', //'core/search', 'core/separator', 'core/embed', 'acf/largepullquote', 'acf/blockquote', 'acf/search-field', //'yoast/faq-block', ); } } /** * Disable Gutenberg on certain templates. Thanks Bill Erickson https://www.billerickson.net/disabling-gutenberg-certain-templates/ * Templates and Page IDs without editor * */ function jjm_disable_editor( $id = false ) { $excluded_templates = array( //'projects.php', ); $excluded_ids = array( //get_option( 'page_on_front' ), get_option( 'page_for_posts' ) ); if( empty( $id ) ) return false; $id = intval( $id ); $template = get_page_template_slug( $id ); return in_array( $id, $excluded_ids ) || in_array( $template, $excluded_templates ); } /** * Disable Gutenberg by template * */ function jjm_disable_gutenberg( $can_edit, $post_type ) { if( ! ( is_admin() && !empty( $_GET['post'] ) ) ) return $can_edit; if( jjm_disable_editor( $_GET['post'] ) ) $can_edit = false; return $can_edit; } add_filter( 'gutenberg_can_edit_post_type', 'jjm_disable_gutenberg', 10, 2 ); add_filter( 'use_block_editor_for_post_type', 'jjm_disable_gutenberg', 10, 2 ); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ wp.domReady(() => { wp.blocks.unregisterBlockStyle('core/image', 'rounded'); wp.blocks.unregisterBlockStyle('core/image', 'default'); } ); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ { "$schema": "http://schemas.wp.org/trunk/theme.json", "version": 2, "settings": { "layout": { "contentSize": "930px" }, "color": { "background": false, "custom": false, "customDuotone": false, "customGradient": false, "defaultGradients": false, "defaultPalette": false, "text": false }, "typography": { "customFontSize": false, "dropCap": false, "fontStyle": false, "fontWeight": false, "letterSpacing": false, "lineHeight": false, "textDecoration": false, "textTransform": false } } }