| 1 |
<?php |
| 2 |
|
| 3 |
function b_blocks_init() { |
| 4 |
// Custom Block Category |
| 5 |
function b_blocks_category( $categories ) { |
| 6 |
return array_merge( [ |
| 7 |
array( |
| 8 |
'slug' => 'bBlocks', |
| 9 |
'title' => 'B Blocks', |
| 10 |
), |
| 11 |
], $categories ); |
| 12 |
} |
| 13 |
add_filter( 'block_categories', 'b_blocks_category', 10, 2 ); |
| 14 |
|
| 15 |
// Register block styles for both frontend + backend. |
| 16 |
wp_register_style( 'b_blocks-style-css', plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), is_admin() ? array( 'wp-editor' ) : null, null ); |
| 17 |
|
| 18 |
// Register block editor script for backend. |
| 19 |
wp_register_script( 'b_blocks-js', plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-components', 'wp-block-editor', 'wp-api' ), null, true ); |
| 20 |
|
| 21 |
// Register block editor styles for backend. |
| 22 |
wp_register_style( 'b_blocks-editor-css', plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), array( 'wp-edit-blocks' ), null ); |
| 23 |
|
| 24 |
// WP Localized globals. Use dynamic PHP stuff in JavaScript via `cgbGlobal` object. |
| 25 |
wp_localize_script( |
| 26 |
'b_blocks-js', |
| 27 |
'bBlocksAdmin', // Array containing dynamic data for a JS Global. |
| 28 |
[ |
| 29 |
'pluginDirPath' => plugin_dir_path( __DIR__ ), |
| 30 |
'pluginDirUrl' => plugin_dir_url( __DIR__ ), |
| 31 |
// Add more data here that you want to access from `cgbGlobal` object. |
| 32 |
'siteUrl' => get_site_url(), |
| 33 |
] |
| 34 |
); |
| 35 |
|
| 36 |
// Register Gutenberg block on server-side. |
| 37 |
register_block_type( 'wasek/b-blocks', array( |
| 38 |
'style' => 'b_blocks-style-css', |
| 39 |
'editor_script' => 'b_blocks-js', |
| 40 |
'editor_style' => 'b_blocks-editor-css', |
| 41 |
) ); |
| 42 |
} |
| 43 |
add_action( 'init', 'b_blocks_init' ); |
| 44 |
|
| 45 |
// Posts Block |
| 46 |
require 'posts.php'; |
| 47 |
// require 'advance-posts.php'; |
| 48 |
|
| 49 |
function b_blocks_after_setup_theme() { |
| 50 |
add_theme_support( 'align-wide' ); |
| 51 |
} |
| 52 |
add_action( 'after_setup_theme', 'b_blocks_after_setup_theme' ); |