-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjet-form-builder-update-field.php
152 lines (99 loc) · 3.4 KB
/
jet-form-builder-update-field.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* Plugin Name: JetFormBuilder - Update Fields
* Plugin URI:
* Description:
* Version: 1.2.2
* Author:
* Author URI:
* Text Domain:
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Domain Path: /languages
*/
namespace JFB_Update_Field;
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die();
}
if ( ! class_exists( '\JFB_Update_Field\Plugin' ) ) {
class Plugin {
private $path = null;
private static $instance = null;
public $db = null;
public $storage = null;
private $version = '1.2.2';
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'jec_init' ) );
}
public function get_version() {
return $this->version;
}
public function plugin_path( $path = '' ) {
if ( ! $this->path ) {
$this->path = trailingslashit( plugin_dir_path( __FILE__ ) );
}
return $this->path . $path;
}
public function jec_init() {
if ( ! function_exists( 'jet_form_builder' ) ) {
add_action( 'admin_notices', function() {
$class = 'notice notice-error';
$message = '<b>WARNING!</b> <b>JetFormBuilder - Update Fields</b> plugin requires <b>JetFormBuilder</b> plugin to be installed and activated.';
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), wp_kses_post( $message ) );
} );
return;
}
// it can work only on JetFormBuilder >=3.1.0
if ( ! function_exists( 'jet_fb_context' ) ) {
add_action( 'admin_notices', function() {
$class = 'notice notice-error';
$message = '<b>WARNING!</b> <b>JetFormBuilder - Update Fields</b> plugin requires <b>JetFormBuilder</b> plugin to be updated to version 3.1+.';
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), wp_kses_post( $message ) );
} );
return;
}
add_action( 'after_setup_theme', array( $this, 'init_components' ), 0 );
}
public function init_components() {
$this->path = trailingslashit( plugin_dir_path( __FILE__ ) );
require $this->plugin_path( 'rest-api/endpoint.php' );
new Endpoint();
require $this->plugin_path( 'additional-block-attributes.php' );
new Additional_Block_Attributes();
require $this->plugin_path( 'storage.php' );
$this->storage = new Storage();
require $this->plugin_path( 'compatibility/manager.php' );
new Compatibility\Compatibility_Manager();
require $this->plugin_path( 'blocks/manager.php' );
new Blocks();
add_action( 'enqueue_block_editor_assets', array( $this, 'block_assets' ), -100 );
add_filter( 'jet-form-builder/frontend-settings', array( $this, 'enable_strict_mode' ) );
add_action( 'jet-engine/register-macros', array( $this, 'register_macros' ) );
}
public function register_macros() {
require_once $this->plugin_path( 'macros/form-field-value.php' );
new Macros\Form_Field_Value();
}
public function enable_strict_mode( $settings ) {
$settings['strict_mode'] = true;
return $settings;
}
public function block_assets() {
wp_enqueue_script(
'jfb-update-field',
plugins_url( 'assets/js/blocks.js', __FILE__ ),
array( 'wp-components', 'wp-element', 'wp-blocks', 'wp-block-editor', 'wp-edit-post' ),
$this->get_version(),
false
);
}
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
}
}
Plugin::instance();