PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.2.3
JetFormBuilder — Dynamic Blocks Form Builder v3.2.3
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-build 2 years ago module.php 2 years ago
module.php
129 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_Handle_It;
9 use JFB_Components\Module\Base_Module_Handle_Trait;
10 use JFB_Components\Module\Base_Module_It;
11 use JFB_Components\Module\Base_Module_Url_It;
12 use JFB_Components\Module\Base_Module_Url_Trait;
13
14 // If this file is called directly, abort.
15 if ( ! defined( 'WPINC' ) ) {
16 die;
17 }
18
19 class Module implements
20 Base_Module_It,
21 Base_Module_Url_It,
22 Base_Module_Handle_It,
23 Base_Module_After_Install_It {
24
25 use Base_Module_Url_Trait;
26 use Base_Module_Handle_Trait;
27
28 const SUPPORT_NAME = 'jetFBSwitchPageOnChange';
29 const ATTRIBUTE_NAME = 'switch_on_change';
30
31 public function rep_item_id() {
32 return 'switch-page-on-change';
33 }
34
35 public function condition(): bool {
36 return true;
37 }
38
39 public function on_install() {
40 \WP_Block_Supports::get_instance()->register(
41 self::SUPPORT_NAME,
42 array(
43 'register_attribute' => array( $this, 'register_support' ),
44 'apply' => array( $this, 'apply_support' ),
45 )
46 );
47 }
48
49 public function on_uninstall() {
50 \WP_Block_Supports::get_instance()->register( self::SUPPORT_NAME, array() );
51 }
52
53 public function init_hooks() {
54 add_action(
55 'jet-form-builder/editor-assets/before',
56 array( $this, 'register_editor_scripts' ),
57 0
58 );
59
60 add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend_scripts' ) );
61 add_action( 'jet_plugins/frontend/register_scripts', array( $this, 'register_frontend_scripts' ) );
62 }
63
64 public function remove_hooks() {
65 remove_action(
66 'jet-form-builder/editor-assets/before',
67 array( $this, 'register_editor_scripts' ),
68 0
69 );
70
71 remove_action( 'wp_enqueue_scripts', array( $this, 'register_frontend_scripts' ) );
72 remove_action( 'jet_plugins/frontend/register_scripts', array( $this, 'register_frontend_scripts' ) );
73 }
74
75 public function register_editor_scripts() {
76 wp_enqueue_script(
77 $this->get_handle(),
78 $this->get_url( 'assets-build/js/editor/main.js' ),
79 array(),
80 jet_form_builder()->get_version(),
81 true
82 );
83 }
84
85 public function register_frontend_scripts() {
86 wp_register_script(
87 $this->get_handle(),
88 $this->get_url( 'assets-build/js/frontend/main.js' ),
89 array( \Jet_Form_Builder\Blocks\Module::MAIN_SCRIPT_HANDLE ),
90 jet_form_builder()->get_version(),
91 true
92 );
93 }
94
95 public function register_support( \WP_Block_Type $block_type ) {
96 // Setup attributes and styles within that if needed.
97 if ( ! $block_type->attributes ) {
98 $block_type->attributes = array();
99 }
100
101 if ( block_has_support( $block_type, array( self::SUPPORT_NAME ) ) &&
102 ! array_key_exists( self::ATTRIBUTE_NAME, $block_type->attributes )
103 ) {
104 $block_type->attributes[ self::ATTRIBUTE_NAME ] = array(
105 'type' => 'boolean',
106 'default' => false,
107 );
108 }
109 }
110
111 public function apply_support( \WP_Block_Type $block_type, array $block_attributes ): array {
112 if ( ! is_array( $block_type->supports ) ) {
113 return array();
114 }
115 $support_config = Array_Tools::get( $block_type->supports, array( self::SUPPORT_NAME ), false );
116 $value = $block_attributes[ self::ATTRIBUTE_NAME ] ?? array();
117
118 if ( empty( $support_config ) || empty( $value ) ) {
119 return array();
120 }
121
122 wp_enqueue_script( $this->get_handle() );
123
124 return array(
125 'class' => $this->get_handle(),
126 );
127 }
128 }
129