| 1 |
<?php |
| 2 |
/** |
| 3 |
* The blocks base file. |
| 4 |
* |
| 5 |
* @link https://sureforms.com |
| 6 |
* @since 0.0.1 |
| 7 |
* @package SureForms |
| 8 |
* @author SureForms <https://sureforms.com/> |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace SRFM\Inc\Blocks; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; // Exit if accessed directly. |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Block base class. |
| 19 |
*/ |
| 20 |
abstract class Base { |
| 21 |
/** |
| 22 |
* Optional directory to .json block data files. |
| 23 |
* |
| 24 |
* @var string |
| 25 |
* @since 0.0.1 |
| 26 |
*/ |
| 27 |
protected $directory = ''; |
| 28 |
|
| 29 |
/** |
| 30 |
* Register the block for dynamic output |
| 31 |
* |
| 32 |
* @return void |
| 33 |
* @since 0.0.1 |
| 34 |
*/ |
| 35 |
public function register() { |
| 36 |
register_block_type_from_metadata( |
| 37 |
$this->get_dir(), |
| 38 |
apply_filters( |
| 39 |
'srfm_block_registration_args', |
| 40 |
[ 'render_callback' => [ $this, 'render' ] ] |
| 41 |
) |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get the called class directory path |
| 47 |
* |
| 48 |
* @return string |
| 49 |
* @since 0.0.1 |
| 50 |
*/ |
| 51 |
public function get_dir() { |
| 52 |
if ( $this->directory ) { |
| 53 |
return $this->directory; |
| 54 |
} |
| 55 |
|
| 56 |
$reflector = new \ReflectionClass( $this ); |
| 57 |
$fn = (string) $reflector->getFileName(); |
| 58 |
return dirname( $fn ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Render the block |
| 63 |
* |
| 64 |
* @param array<mixed> $attributes Block attributes. |
| 65 |
* |
| 66 |
* @return string |
| 67 |
* @since 0.0.1 |
| 68 |
*/ |
| 69 |
public function render( $attributes ) { |
| 70 |
return ''; |
| 71 |
} |
| 72 |
} |
| 73 |
|