Inventory_Presser_Blocks
On This Page
Description Description
Creates blocks
Source Source
File: includes/class-blocks.php
class Inventory_Presser_Blocks { /** * Adds a block category to hold all our blocks * * @param array $block_categories * @return array */ public function add_category( $block_categories ) { return array_merge( $block_categories, array( array( 'slug' => 'inventory-presser', 'title' => __( 'Inventory Presser', 'inventory-presser' ), 'icon' => 'dashicons-admin-network', // it's a key. ), ) ); } /** * Adds hooks * * @return void */ public function add_hooks() { add_action( 'init', array( $this, 'register_block_types' ) ); add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) ); add_filter( 'block_categories_all', array( $this, 'add_category' ), 10, 1 ); } /** * Enqueues block editor assets * * @return void */ public function enqueue_block_editor_assets() { wp_enqueue_script( 'invp-blocks' ); wp_enqueue_style( 'invp-block-editor' ); } /** * Registers block types * * @return void */ public function register_block_types() { if ( ! function_exists( 'register_block_type' ) ) { // running on WordPress < 5.0.0, no blocks for you. return; } $block_types = array( 'year-make-model-and-trim', 'beam', // For boats. 'body-style', 'color', 'description', 'down-payment', 'engine', 'interior-color', 'last-modified', 'length', // For trailers & boats. 'make', 'model', 'msrp', 'odometer', 'payment', 'price', 'stock-number', 'title-status', 'transmission-speeds', 'trim', 'vin', 'year', 'youtube', ); foreach ( $block_types as $block_type ) { register_block_type( dirname( INVP_PLUGIN_FILE_PATH ) . '/build/blocks/' . $block_type . '/block.json' ); } } }
Expand full source codeCollapse full source codeView on Github
Methods Methods
- add_category — Adds a block category to hold all our blocks
- add_hooks — Adds hooks
- enqueue_block_editor_assets — Enqueues block editor assets
- register_block_types — Registers block types