Last active
October 19, 2019 22:02
-
-
Save soderlind/93208fa1130668537024a950bd85dbf9 to your computer and use it in GitHub Desktop.
add_theme_support( 'disable_block_style') .. hide gutenberg block style.
This file contains 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 characters
/** | |
* Hide block styles | |
*/ | |
wp.domReady(() => { | |
if (_.isObject(oDelBlockStyles)) { | |
_.map(oDelBlockStyles, (styleVariationName, blockName) => { | |
styleVariationName.forEach((style) => { | |
wp.blocks.unregisterBlockStyle(blockName, style); | |
}); | |
}); | |
} | |
}); |
This file contains 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 characters
// find blocks styles | |
wp.domReady(() => { | |
// find blocks styles | |
wp.blocks.getBlockTypes().forEach((block) => { | |
if (_.isArray(block['styles'])) { | |
console.log(block.name, _.pluck(block['styles'], 'name')); | |
} | |
}); | |
}); |
This file contains 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 characters
<?php | |
require_once 'get_theme_support_block_style.php'; | |
add_theme_support( 'disable_block_style', [ | |
'cap' => 'manage_options', // hide if you don't have this capability, eg. hide for Editors ... | |
'core/image' => [ | |
'circle-mask', | |
], | |
'core/button' => [ | |
'default', | |
'fill', | |
'outline', | |
'squared', | |
], | |
] ); |
This file contains 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 characters
<?php | |
add_action( 'enqueue_block_assets', 'get_theme_support_block_style', 11 ); | |
function get_theme_support_block_style() { | |
if ( ! current_theme_supports( 'disable_block_style' ) ) { | |
return false; | |
} | |
$disable_block_style = get_theme_support( 'disable_block_style' )[0]; | |
if ( ! is_array( $disable_block_style ) ) { | |
return false; | |
} | |
if ( isset( $disable_block_style['cap'] ) and current_user_can( $disable_block_style['cap'] ) ) { | |
return false; | |
} | |
unset( $disable_block_style['cap'] ); | |
wp_enqueue_script( 'remove-block-style', get_stylesheet_directory_uri() . '/block-script.js', [ 'wp-blocks', 'wp-edit-post' ] ); | |
wp_localize_script( 'remove-block-style', 'oDelBlockStyles', $disable_block_style ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment