| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly. |
| 5 |
} |
| 6 |
|
| 7 |
if (!class_exists('EW_Blocks')) : |
| 8 |
|
| 9 |
class EW_Blocks |
| 10 |
{ |
| 11 |
|
| 12 |
/** |
| 13 |
* @var null |
| 14 |
*/ |
| 15 |
private static $instance = null; |
| 16 |
|
| 17 |
public function __construct() |
| 18 |
{ |
| 19 |
// Hook: Editor assets. |
| 20 |
add_action('enqueue_block_editor_assets', [$this, 'ew_block_assets']); |
| 21 |
// Add custom block category |
| 22 |
add_filter( |
| 23 |
'block_categories_all', |
| 24 |
function ($categories, $post) { |
| 25 |
return array_merge( |
| 26 |
$categories, |
| 27 |
array( |
| 28 |
array( |
| 29 |
'slug' => 'ew-block', |
| 30 |
'title' => __('EW Blocks', 'essential-widgets'), |
| 31 |
), |
| 32 |
) |
| 33 |
); |
| 34 |
}, |
| 35 |
10, |
| 36 |
2 |
| 37 |
); |
| 38 |
|
| 39 |
// Load all the blocks |
| 40 |
$this->load_blocks(); |
| 41 |
} |
| 42 |
|
| 43 |
public function ew_block_assets() |
| 44 |
{ |
| 45 |
// Scripts. |
| 46 |
wp_enqueue_script( |
| 47 |
'ew-block-js', // Handle. |
| 48 |
plugins_url('ew-block/blocks.build.js', dirname(__FILE__)), // Block.build.js: We register the block here. Built with Webpack. |
| 49 |
array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor') // |
| 50 |
); |
| 51 |
|
| 52 |
// Styles. |
| 53 |
wp_enqueue_style( |
| 54 |
'ew-block-editor-css', // Handle. |
| 55 |
plugins_url('ew-block/blocks.editor.build.css', dirname(__FILE__)), // Block editor CSS. |
| 56 |
array('wp-edit-blocks') // Dependency to include the CSS after it. |
| 57 |
); |
| 58 |
} // End function catch_guten_cgb_editor_assets(). |
| 59 |
|
| 60 |
public function load_blocks() |
| 61 |
{ |
| 62 |
require_once 'blocks/ew-archive/index.php'; |
| 63 |
require_once 'blocks/ew-author/index.php'; |
| 64 |
require_once 'blocks/ew-category/index.php'; |
| 65 |
require_once 'blocks/ew-page/index.php'; |
| 66 |
require_once 'blocks/ew-post/index.php'; |
| 67 |
require_once 'blocks/ew-tags/index.php'; |
| 68 |
require_once 'blocks/ew-menu/index.php'; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* @return EW_Blocks|null |
| 73 |
*/ |
| 74 |
public static function instance() |
| 75 |
{ |
| 76 |
if (is_null(self::$instance)) { |
| 77 |
self::$instance = new self(); |
| 78 |
} |
| 79 |
|
| 80 |
return self::$instance; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
EW_Blocks::instance(); |
| 85 |
|
| 86 |
endif; |
| 87 |
|