# firebox/1.0.2/Inc/Core/RESTAPI.php

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

- Page: https://pluginprobe.com/plugins/firebox/1.0.2/code/Inc/Core/RESTAPI.php
- Raw: https://pluginprobe.com/plugins/firebox/1.0.2/raw/Inc/Core/RESTAPI.php
- Modified: 2021-04-15T09:59:50+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.2/code/Inc/Core/RESTAPI.php#L10-L20`.

```php
<?php
/**
 * @package         FireBox
 * @version         1.0.2 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;

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

class RESTAPI
{
	/**
	 * REST Route namespace
	 * 
	 * @var  string
	 */
    private $namespace = 'fireplugins/firebox';
    
    public function __construct()
    {
		// set api call used by gutenberg block to fetch all boxes
		add_action( 'rest_api_init', array( $this, 'init_block_api' ) );
    }
	
	/**
	 * Sets REST route used by Gutenberg block to fetch all boxes
	 * 
	 * @return  void
	 */
	public function init_block_api()
	{
		register_rest_route(
			$this->namespace,
			'boxes',
			array(
				'methods'             => 'GET',
				'callback'            => array( $this, 'get_boxes' ),
				'permission_callback' => function ()
				{
					return current_user_can( 'manage_options' );
				}
			)
		);
	}
	
	/**
	 * Finds all boxes and returns them
	 * 
	 * @return  array
	 */
	public function get_boxes()
	{
		$boxes = \FireBox\Core\Helpers\BoxHelper::getAllBoxes();

		if (!count($boxes))
		{
			return [];
		}
		
		$data = [];
		
		foreach ($boxes as $box)
		{
			$data[] = [
				'id' => $box->ID,
				'title' => $box->post_title
			];
		}
		
		return $data;
	}
}
```
