Forked from michealengland/block-filters-plugin-enqueue.php
Created
June 15, 2021 01:32
-
-
Save rafszul/9b0639b69f6549f199fae5051098197c to your computer and use it in GitHub Desktop.
Gutenberg registerBlockStyle
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 characters
/** | |
* Enqueue Block Filters. | |
*/ | |
function enqueue_my_block_filters() { | |
wp_register_script( | |
'block-style-filter', | |
plugins_url( 'block-style-filter', __FILE__ ), | |
array( 'wp-blocks', 'wp-element' ) | |
); | |
} | |
add_action( 'init', 'enqueue_my_block_filters' ); |
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 characters
wp.blocks.registerBlockStyle( 'core/quote', { | |
name: 'fancy-quote', | |
label: 'Fancy Quote' | |
} ); |
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 characters
/** | |
* Enqueue block editor only JavaScript. | |
*/ | |
function gfd_blocks_editor_scripts() { | |
wp_enqueue_script( | |
'gfd-blocks-js', | |
plugins_url( '../build/index.js', __FILE__ ), | |
[ 'wp-blocks', 'wp-dom-ready', 'wp-edit-post', 'wp-hooks' ], | |
filemtime( plugin_dir_path( __FILE__ ) . $blockPath ) | |
); | |
} | |
add_action( 'enqueue_block_editor_assets', 'gfd_blocks_editor_scripts' ); |
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 characters
/** | |
* Registers a new block style variation for the given block. | |
* | |
* @param {string} blockName Name of block (example: “core/latest-posts”). | |
* @param {Object} styleVariation Object containing `name` which is the class name applied to the block and `label` which identifies the variation to the user. | |
*/ | |
export const registerBlockStyle = ( blockName, styleVariation ) => { | |
dispatch( 'core/blocks' ).addBlockStyles( blockName, styleVariation ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment