PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / switch-page-on-change / module.php
jetformbuilder / modules / switch-page-on-change Last commit date
assets 2 years ago module.php 2 years ago
module.php
146 lines
1 <?php
2
3
4 namespace JFB_Modules\Switch_Page_On_Change;
5
6 use Jet_Form_Builder\Classes\Arrayable\Array_Tools;
7 use JFB_Components\Module\Base_Module_After_Install_It;
8 use JFB_Components\Module\Base_Module_Dir_It;
9 use JFB_Components\Module\Base_Module_Dir_Trait;
10 use JFB_Components\Module\Base_Module_Handle_It;
11 use JFB_Components\Module\Base_Module_Handle_Trait;
12 use JFB_Components\Module\Base_Module_It;
13 use JFB_Components\Module\Base_Module_Url_It;
14 use JFB_Components\Module\Base_Module_Url_Trait;
15
16 // If this file is called directly, abort.
17 if ( ! defined( 'WPINC' ) ) {
18 die;
19 }
20
21 class Module implements
22 Base_Module_It,
23 Base_Module_Url_It,
24 Base_Module_Handle_It,
25 Base_Module_After_Install_It,
26 Base_Module_Dir_It {
27
28 use Base_Module_Url_Trait;
29 use Base_Module_Handle_Trait;
30 use Base_Module_Dir_Trait;
31
32 const SUPPORT_NAME = 'jetFBSwitchPageOnChange';
33 const ATTRIBUTE_NAME = 'switch_on_change';
34
35 public function rep_item_id() {
36 return 'switch-page-on-change';
37 }
38
39 public function condition(): bool {
40 return true;
41 }
42
43 public function on_install() {
44 \WP_Block_Supports::get_instance()->register(
45 self::SUPPORT_NAME,
46 array(
47 'register_attribute' => array( $this, 'register_support' ),
48 'apply' => array( $this, 'apply_support' ),
49 )
50 );
51 }
52
53 public function on_uninstall() {
54 \WP_Block_Supports::get_instance()->register( self::SUPPORT_NAME, array() );
55 }
56
57 public function init_hooks() {
58 add_action(
59 'jet-form-builder/editor-assets/before',
60 array( $this, 'register_editor_scripts' ),
61 0
62 );
63
64 add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend_scripts' ) );
65 add_action( 'jet_plugins/frontend/register_scripts', array( $this, 'register_frontend_scripts' ) );
66 }
67
68 public function remove_hooks() {
69 remove_action(
70 'jet-form-builder/editor-assets/before',
71 array( $this, 'register_editor_scripts' ),
72 0
73 );
74
75 remove_action( 'wp_enqueue_scripts', array( $this, 'register_frontend_scripts' ) );
76 remove_action( 'jet_plugins/frontend/register_scripts', array( $this, 'register_frontend_scripts' ) );
77 }
78
79 public function register_editor_scripts() {
80 $script_asset = require_once $this->get_dir( 'assets/build/editor.asset.php' );
81
82 wp_enqueue_script(
83 $this->get_handle(),
84 $this->get_url( 'assets/build/editor.js' ),
85 $script_asset['dependencies'],
86 $script_asset['version'],
87 true
88 );
89 }
90
91 public function register_frontend_scripts() {
92 $script_asset = require_once $this->get_dir( 'assets/build/frontend.asset.php' );
93
94 if ( true === $script_asset ) {
95 return;
96 }
97
98 array_push(
99 $script_asset['dependencies'],
100 \Jet_Form_Builder\Blocks\Module::MAIN_SCRIPT_HANDLE
101 );
102
103 wp_register_script(
104 $this->get_handle(),
105 $this->get_url( 'assets/build/frontend.js' ),
106 $script_asset['dependencies'],
107 $script_asset['version'],
108 true
109 );
110 }
111
112 public function register_support( \WP_Block_Type $block_type ) {
113 // Setup attributes and styles within that if needed.
114 if ( ! $block_type->attributes ) {
115 $block_type->attributes = array();
116 }
117
118 if ( block_has_support( $block_type, array( self::SUPPORT_NAME ) ) &&
119 ! array_key_exists( self::ATTRIBUTE_NAME, $block_type->attributes )
120 ) {
121 $block_type->attributes[ self::ATTRIBUTE_NAME ] = array(
122 'type' => 'boolean',
123 'default' => false,
124 );
125 }
126 }
127
128 public function apply_support( \WP_Block_Type $block_type, array $block_attributes ): array {
129 if ( ! is_array( $block_type->supports ) ) {
130 return array();
131 }
132 $support_config = Array_Tools::get( $block_type->supports, array( self::SUPPORT_NAME ), false );
133 $value = $block_attributes[ self::ATTRIBUTE_NAME ] ?? array();
134
135 if ( empty( $support_config ) || empty( $value ) ) {
136 return array();
137 }
138
139 wp_enqueue_script( $this->get_handle() );
140
141 return array(
142 'class' => $this->get_handle(),
143 );
144 }
145 }
146