# firebox/1.0.4/Inc/Core/Blocks/FireBox.php

FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin &amp; Cart Abandonment, version 1.0.4. 119 lines.

- Page: https://pluginprobe.com/plugins/firebox/1.0.4/code/Inc/Core/Blocks/FireBox.php
- Raw: https://pluginprobe.com/plugins/firebox/1.0.4/raw/Inc/Core/Blocks/FireBox.php
- Modified: 2021-07-19T14:57: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/firebox/1.0.4/code/Inc/Core/Blocks/FireBox.php#L10-L20`.

```php
<?php
/**
 * @package         FireBox
 * @version         1.0.4 Free
 * 
 * @author          FirePlugins <info@fireplugins.com>
 * @link            https://www.fireplugins.com
 * @copyright       Copyright © 2021 FirePlugins All Rights Reserved
 * @license         GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/

namespace FireBox\Core\Blocks;

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

class FireBox
{
	public function __construct()
	{
		if (!$this->canRun())
		{
			return;
		}

		// set custom gutenberg block category
		add_filter('block_categories_all', [$this, 'set_custom_block_category'], 10, 2);

		// load gutenberg block js
		add_action('admin_enqueue_scripts', [$this, 'registerMedia']);

		// register gutenberg block type
		register_block_type('fireplugins/firebox', array(
			'editor_script' => 'fb-gutenberg-block',
		));
	}

	/**
	 * Whether we can run
	 * 
	 * @return  boolean
	 */
	private function canRun()
	{
		if (!current_user_can('manage_options') || !current_user_can('edit_posts') || !current_user_can('edit_pages'))
		{
			return false;
		}

		global $pagenow;
		if (!in_array($pagenow, ['post.php', 'post-new.php', 'index.php']))
		{
			return false;
		}

		return true;
	}

	/**
	 * Adds custom gutenberg block category
	 * 
	 * @param   array					 $categories
	 * @param   WP_Block_Editor_Context  $context
	 * 
	 * @return  array
	 */
	public function set_custom_block_category($categories, $context)
	{
		// check fireplugins does not exist
		foreach ($categories as $cat)
		{
			if ($cat['slug'] == 'fireplugins')
			{
				return $categories;
			}
		}

		return array_merge(
			$categories,
			array(
				array(
					'slug' => 'fireplugins',
					'title' => fpframework()->_('FPF_NAME')
				),
			)
		);
	}

	/**
	 * Adds block media
	 * 
	 * @return  void
	 */
	public function registerMedia()
	{
		// load gutenberg block js
		wp_register_script(
			'fb-gutenberg-block',
			FBOX_MEDIA_ADMIN_URL . 'js/fb_gutenberg_block.js',
			['wp-i18n', 'wp-blocks', 'wp-editor', 'wp-components', 'wp-api-fetch'],
			FBOX_VERSION,
			false
		);
		wp_enqueue_script( 'fb-gutenberg-block' );

		// load gutenberg block button extend js
		wp_register_script(
			'fb-admin-block-button-extend',
			FBOX_MEDIA_ADMIN_URL . 'js/fb_block_button_extend.js',
			[],
			FBOX_VERSION,
			false
		);
		wp_enqueue_script( 'fb-admin-block-button-extend' );
	}

}
```
