Inventory_Presser_Blocks::register_block_types()

register_block_types


Description Description

Registers block types


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-blocks.php

	function register_block_types()
	{
		if( ! function_exists( 'register_block_type' ) )
		{
			//running on WordPress < 5.0.0, no blocks for you
			return;
		}

		$asset_file = include( plugin_dir_path( INVP_PLUGIN_FILE_PATH ) . 'build/index.asset.php' );

		$keys = array(
			// 'beam',
			// 'body-style',
			// 'color',
			// 'engine',
			// 'hull-material',
			// 'interior-color',
			// 'last-modified',
			// 'length',
			'make',
			'model',
			// 'odometer',
		);

		wp_enqueue_script(
			'invp-blocks',
			plugins_url( 'build/index.js', INVP_PLUGIN_FILE_PATH ),
			$asset_file['dependencies'],
			$asset_file['version']
		);

		//Provide the vehicle post type meta keys and prefix to JavaScript
		wp_add_inline_script( 'invp-blocks', 'const invp_blocks = ' . json_encode( array(
			'keys'        => INVP::keys_and_types(),
			'meta_prefix' => INVP::meta_prefix(),
		) ), 'before' );


		foreach( $keys as $key )
		{
			register_block_type( 'inventory-presser/' . $key, array(
				'editor_script' => 'invp-blocks',
			) );
		}
	}