PluginProbe ʕ •ᴥ•ʔ
SureForms – Drag & Drop Contact Form & Form Builder, Payment Form, Survey, Quiz & Calculator / 2.12.1
SureForms – Drag & Drop Contact Form & Form Builder, Payment Form, Survey, Quiz & Calculator v2.12.1
2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / blocks / register.php
sureforms / inc / blocks Last commit date
address 3 months ago checkbox 3 months ago dropdown 2 months ago email 3 months ago gdpr 3 months ago inlinebutton 3 months ago input 1 month ago multichoice 2 months ago number 3 months ago payment 2 months ago payment-history 3 months ago phone 3 months ago sform 3 months ago textarea 2 months ago url 3 months ago base.php 1 year ago register.php 1 year ago
register.php
88 lines
1 <?php
2 /**
3 * Call block registration.
4 *
5 * @package SureForms
6 */
7
8 namespace SRFM\Inc\Blocks;
9
10 use SRFM\Inc\Traits\Get_Instance;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 /**
17 * Manage Blocks registrations.
18 *
19 * @since 0.0.1
20 */
21 class Register {
22 use Get_Instance;
23
24 /**
25 * Constructor
26 *
27 * @since 0.0.1
28 */
29 public function __construct() {
30 $blocks = [
31 [
32 'dir' => SRFM_DIR . 'inc/blocks/**/*.php',
33 'namespace' => 'SRFM\\Inc\\Blocks',
34 ],
35 ];
36
37 // Filter to add and register additional blocks. Like Signature block.
38 $additional_blocks = apply_filters( 'srfm_register_additional_blocks', [] );
39
40 // Merge additional blocks with the default blocks. When the additional blocks are not empty.
41 if ( ! empty( $additional_blocks ) && count( $additional_blocks ) > 0 ) {
42 $blocks = [ ...$blocks, ...$additional_blocks ];
43 }
44
45 foreach ( $blocks as $block ) {
46 // Register the block.
47 $this->register_block( glob( $block['dir'] ), $block['namespace'], 'Block' );
48 }
49 }
50
51 /**
52 * Register Blocks
53 *
54 * @param array<int, string>|false $blocks_dir Block directory.
55 * @param string $namespace Namespace.
56 * @param string $base Base.
57 * @return void
58 * @since 0.0.1
59 */
60 public static function register_block( $blocks_dir, $namespace, $base ) {
61 if ( ! empty( $blocks_dir ) ) {
62 foreach ( $blocks_dir as $filename ) {
63 // Include the file.
64 require_once $filename;
65
66 // Replace hyphens with underscores.
67 $classname = str_replace( '-', '_', basename( dirname( $filename ) ) );
68
69 // Convert to title case (capitalizes the first letter of each word).
70 $classname = ucwords( $classname, '_' );
71
72 $full_class_name = $namespace . '\\' . $classname . '\\' . $base;
73
74 // Check if the class exists.
75 if ( class_exists( $full_class_name ) ) {
76 $block = new $full_class_name();
77
78 // Check if the register method exists.
79 if ( method_exists( $block, 'register' ) ) {
80 // Call register on the block object.
81 $block->register();
82 }
83 }
84 }
85 }
86 }
87 }
88