-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrbm-field-helpers-wrapper.php
More file actions
286 lines (229 loc) · 7.56 KB
/
rbm-field-helpers-wrapper.php
File metadata and controls
286 lines (229 loc) · 7.56 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
/**
* Plugin Name: RBM Field Helpers Wrapper
* Plugin URI: https://github.com/realbig/rbm-field-helpers-wrapper
* Description: A simple wrapper plugin for RBM Field Helpers. It uses the legacy "_rbm" prefix and may be a good option in cases where you have legacy RBM FH data and you do not want to bother migrating it
* Version: 1.4.0
* Text Domain: rbm-field-helpers-wrapper
* Author: Eric Defore
* Author URI: https://realbigmarketing.com/
* Contributors: d4mation
* GitHub Plugin URI: https://github.com/realbig/rbm-field-helpers-wrapper
* Release Asset: true
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'RBM_Field_Helpers_Wrapper' ) ) {
/**
* Main RBM_Field_Helpers_Wrapper class
*
* @since 1.0.0
*/
class RBM_Field_Helpers_Wrapper {
/**
* @var array $plugin_data Holds Plugin Header Info
* @since 1.0.0
*/
public $plugin_data;
/**
* @var array $admin_errors Stores all our Admin Errors to fire at once
* @since 1.0.0
*/
private $admin_errors;
/**
* @var RBM_FieldHelpers RBM FH
* @since 1.0.0
*/
public $field_helpers;
/**
* Get active instance
*
* @access public
* @since 1.0.0
* @return object self::$instance The one true RBM_Field_Helpers_Wrapper
*/
public static function instance() {
static $instance = null;
if ( null === $instance ) {
$instance = new static();
}
return $instance;
}
protected function __construct() {
$this->setup_constants();
$this->load_textdomain();
if ( version_compare( get_bloginfo( 'version' ), '4.4' ) < 0 ) {
$this->admin_errors[] = sprintf( _x( '%s requires v%s of %s or higher to be installed!', 'Outdated Dependency Error', 'rbm-field-helpers-wrapper' ), '<strong>' . $this->plugin_data['Name'] . '</strong>', '4.4', '<a href="' . admin_url( 'update-core.php' ) . '"><strong>WordPress</strong></a>' );
if ( ! has_action( 'admin_notices', array( $this, 'admin_errors' ) ) ) {
add_action( 'admin_notices', array( $this, 'admin_errors' ) );
}
return false;
}
$this->require_necessities();
// Register our CSS/JS for the whole plugin
add_action( 'init', array( $this, 'register_scripts' ) );
add_action( 'after_setup_theme', array( $this, 'deprecated_support_integrate'), 15);
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0.0
* @return void
*/
private function setup_constants() {
// WP Loads things so weird. I really want this function.
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
// Only call this once, accessible always
$this->plugin_data = get_plugin_data( __FILE__ );
if ( ! defined( 'RBM_Field_Helpers_Wrapper_VER' ) ) {
// Plugin version
define( 'RBM_Field_Helpers_Wrapper_VER', $this->plugin_data['Version'] );
}
if ( ! defined( 'RBM_Field_Helpers_Wrapper_DIR' ) ) {
// Plugin path
define( 'RBM_Field_Helpers_Wrapper_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'RBM_Field_Helpers_Wrapper_URL' ) ) {
// Plugin URL
define( 'RBM_Field_Helpers_Wrapper_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'RBM_Field_Helpers_Wrapper_FILE' ) ) {
// Plugin File
define( 'RBM_Field_Helpers_Wrapper_FILE', __FILE__ );
}
}
/**
* Internationalization
*
* @access private
* @since 1.0.0
* @return void
*/
private function load_textdomain() {
// Set filter for language directory
$lang_dir = RBM_Field_Helpers_Wrapper_DIR . '/languages/';
$lang_dir = apply_filters( 'rbm_field_helpers_wrapper_languages_directory', $lang_dir );
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), 'rbm-field-helpers-wrapper' );
$mofile = sprintf( '%1$s-%2$s.mo', 'rbm-field-helpers-wrapper', $locale );
// Setup paths to current locale file
$mofile_local = $lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/rbm-field-helpers-wrapper/' . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/rbm-field-helpers-wrapper/ folder
// This way translations can be overridden via the Theme/Child Theme
load_textdomain( 'rbm-field-helpers-wrapper', $mofile_global );
}
else if ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/rbm-field-helpers-wrapper/languages/ folder
load_textdomain( 'rbm-field-helpers-wrapper', $mofile_local );
}
else {
// Load the default language files
load_plugin_textdomain( 'rbm-field-helpers-wrapper', false, $lang_dir );
}
}
/**
* Include different aspects of the Plugin
*
* @access private
* @since 1.0.0
* @return void
*/
private function require_necessities() {
require_once __DIR__ . '/core/rbm-field-helpers/rbm-field-helpers.php';
require_once __DIR__ . '/core/rbm-field-helpers-functions.php';
}
/**
* Show admin errors.
*
* @access public
* @since 1.0.0
* @return HTML
*/
public function admin_errors() {
?>
<div class="error">
<?php foreach ( $this->admin_errors as $notice ) : ?>
<p>
<?php echo $notice; ?>
</p>
<?php endforeach; ?>
</div>
<?php
}
/**
* Register our CSS/JS to use later
*
* @access public
* @since 1.0.0
* @return void
*/
public function register_scripts() {
wp_register_style(
'rbm-field-helpers-wrapper',
RBM_Field_Helpers_Wrapper_URL . 'assets/css/style.css',
null,
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RBM_Field_Helpers_Wrapper_VER
);
wp_register_script(
'rbm-field-helpers-wrapper',
RBM_Field_Helpers_Wrapper_URL . 'assets/js/script.js',
array( 'jquery' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RBM_Field_Helpers_Wrapper_VER,
true
);
wp_localize_script(
'rbm-field-helpers-wrapper',
'rBMFieldHelpersWrapper',
apply_filters( 'rbm_field_helpers_wrapper_localize_script', array() )
);
wp_register_style(
'rbm-field-helpers-wrapper-admin',
RBM_Field_Helpers_Wrapper_URL . 'assets/css/admin.css',
null,
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RBM_Field_Helpers_Wrapper_VER
);
wp_register_script(
'rbm-field-helpers-wrapper-admin',
RBM_Field_Helpers_Wrapper_URL . 'assets/js/admin.js',
array( 'jquery' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RBM_Field_Helpers_Wrapper_VER,
true
);
wp_localize_script(
'rbm-field-helpers-wrapper-admin',
'rBMFieldHelpersWrapper',
apply_filters( 'rbm_field_helpers_wrapper_localize_admin_script', array() )
);
}
/**
* Sets the deprecated global to this main instance, to prevent duplicate.
*
* @version 1.0.1
* @access private
*/
function deprecated_support_integrate() {
global $rbm_fh_deprecated_support;
$this->field_helpers = $rbm_fh_deprecated_support;
}
}
} // End Class Exists Check
/**
* The main function responsible for returning the one true RBM_Field_Helpers_Wrapper
* instance to functions everywhere
*
* @since 1.0.0
* @return \RBM_Field_Helpers_Wrapper The one true RBM_Field_Helpers_Wrapper
*/
add_action( 'plugins_loaded', 'rbm_field_helpers_wrapper_load', 1 );
function rbm_field_helpers_wrapper_load() {
if ( ! defined( 'RBM_FH_DEPRECATED_SUPPORT' ) ) {
define( 'RBM_FH_DEPRECATED_SUPPORT', true );
}
require_once __DIR__ . '/core/rbm-field-helpers-wrapper-functions.php';
RBMFIELDHELPERSWRAPPER();
}