# essential-widgets/trunk/includes/ew-block/index.php

Essential Widgets, version trunk. 90 lines.

- Page: https://pluginprobe.com/plugins/essential-widgets/trunk/code/includes/ew-block/index.php
- Raw: https://pluginprobe.com/plugins/essential-widgets/trunk/raw/includes/ew-block/index.php
- Modified: 2026-05-26T18:08:48+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/essential-widgets/trunk/code/includes/ew-block/index.php#L10-L20`.

```php
<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}

if (!class_exists('EW_Blocks')) :

	class EW_Blocks // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- EW_ is this plugin's abbreviated prefix; wrapped in class_exists() guard.
	{

		/**
		 * @var null
		 */
		private static $instance = null;

		public function __construct()
		{
			// Hook: Editor assets.
			add_action('enqueue_block_editor_assets', [$this, 'ew_block_assets']);
			// Add custom block category
			add_filter(
				'block_categories_all',
				function ($categories, $post) {
					return array_merge(
						$categories,
						array(
							array(
								'slug'  => 'ew-block',
								'title' => __('EW Blocks', 'essential-widgets'),
							),
						)
					);
				},
				10,
				2
			);

			// Load all the blocks
			$this->load_blocks();
		}

		public function ew_block_assets()
		{
			// Scripts.
			wp_enqueue_script(
				'ew-block-js', // Handle.
				plugins_url('ew-block/blocks.build.js', dirname(__FILE__)), // Block.build.js: We register the block here. Built with Webpack.
				array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-block-editor'),
				ESSENTIAL_WIDGETS_VERSION,
				true
			);

			// Styles.
			wp_enqueue_style(
				'ew-block-editor-css', // Handle.
				plugins_url('ew-block/blocks.editor.build.css', dirname(__FILE__)), // Block editor CSS.
				array('wp-edit-blocks'), // Dependency to include the CSS after it.
				ESSENTIAL_WIDGETS_VERSION
			);
		} // End function catch_guten_cgb_editor_assets().

		public function load_blocks()
		{
			require_once 'blocks/ew-archive/index.php';
			require_once 'blocks/ew-author/index.php';
			require_once 'blocks/ew-category/index.php';
			require_once 'blocks/ew-page/index.php';
			require_once 'blocks/ew-post/index.php';
			require_once 'blocks/ew-tags/index.php';
			require_once 'blocks/ew-menu/index.php';
		}

		/**
		 * @return EW_Blocks|null
		 */
		public static function instance()
		{
			if (is_null(self::$instance)) {
				self::$instance = new self();
			}

			return self::$instance;
		}
	}

	EW_Blocks::instance();

endif;

```
