PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.7
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.7
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
← All changes | Libs/adminify-framework/classes/setup.class.php +605 -677 4.2.263.1.7 View file →
@@ -1,5 +1,6 @@
1 -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
1 +<?php if ( ! defined( 'ABSPATH' ) ) {
2 + die; } // Cannot access directly.
2 3 /**
3 4 *
4 5 * Setup Class
5 6 *
@@ -4,805 +5,733 @@
4 5 * Setup Class
5 6 *
6 7 * @since 1.0.0
7 8 * @version 1.0.0
8 - *
9 9 */
10 10 if ( ! class_exists( 'ADMINIFY_Setup' ) ) {
11 - class ADMINIFY_Setup {
11 + class ADMINIFY_Setup {
12 12
13 - // Default constants
14 - public static $premium = true;
15 - public static $version = '2.3.1';
16 - public static $dir = '';
17 - public static $url = '';
18 - public static $css = '';
19 - public static $file = '';
20 - public static $enqueue = false;
21 - public static $webfonts = array();
22 - public static $subsets = array();
23 - public static $inited = array();
24 - public static $fields = array();
25 - public static $args = array(
26 - 'admin_options' => array(),
27 - 'customize_options' => array(),
28 - 'metabox_options' => array(),
29 - 'nav_menu_options' => array(),
30 - 'profile_options' => array(),
31 - 'taxonomy_options' => array(),
32 - 'widget_options' => array(),
33 - 'comment_options' => array(),
34 - 'shortcode_options' => array(),
35 - );
13 + // Default constants
14 + public static $premium = true;
15 + public static $version = '2.2.8';
16 + public static $dir = '';
17 + public static $url = '';
18 + public static $css = '';
19 + public static $file = '';
20 + public static $enqueue = false;
21 + public static $webfonts = [];
22 + public static $subsets = [];
23 + public static $inited = [];
24 + public static $fields = [];
25 + public static $args = [
26 + 'admin_options' => [],
27 + 'customize_options' => [],
28 + 'metabox_options' => [],
29 + 'nav_menu_options' => [],
30 + 'profile_options' => [],
31 + 'taxonomy_options' => [],
32 + 'widget_options' => [],
33 + 'comment_options' => [],
34 + 'shortcode_options' => [],
35 + ];
36 36
37 - // Shortcode instances
38 - public static $shortcode_instances = array();
37 + // Shortcode instances
38 + public static $shortcode_instances = [];
39 39
40 - private static $instance = null;
40 + private static $instance = null;
41 41
42 - public static function init( $file = __FILE__, $premium = true ) {
42 + public static function init( $file = __FILE__, $premium = true ) {
43 43
44 - // Set file constant
45 - self::$file = $file;
44 + // Set file constant
45 + self::$file = $file;
46 46
47 - // Set file constant
48 - self::$premium = $premium;
47 + // Set file constant
48 + self::$premium = $premium;
49 49
50 - // Set constants
51 - self::constants();
50 + // Set constants
51 + self::constants();
52 52
53 - // Include files
54 - self::includes();
53 + // Include files
54 + self::includes();
55 55
56 - if ( is_null( self::$instance ) ) {
57 - self::$instance = new self();
58 - }
56 + if ( is_null( self::$instance ) ) {
57 + self::$instance = new self();
58 + }
59 59
60 - return self::$instance;
60 + return self::$instance;
61 + }
61 62
62 - }
63 + // Initalize
64 + public function __construct() {
63 65
64 - // Initalize
65 - public function __construct() {
66 + // Init action
67 + do_action( 'adminify_init' );
66 68
67 - // Init action
68 - do_action( 'adminify_init' );
69 + // Setup textdomain
70 + self::textdomain();
69 71
70 - // Setup textdomain
71 - add_action( 'init', function(){
72 - self::textdomain();
73 - });
72 + add_action( 'after_setup_theme', [ 'ADMINIFY', 'setup' ] );
73 + add_action( 'init', [ 'ADMINIFY', 'setup' ] );
74 + add_action( 'switch_theme', [ 'ADMINIFY', 'setup' ] );
75 + add_action( 'admin_enqueue_scripts', [ 'ADMINIFY', 'add_admin_enqueue_scripts' ] );
76 + add_action( 'wp_enqueue_scripts', [ 'ADMINIFY', 'add_typography_enqueue_styles' ], 80 );
77 + add_action( 'wp_head', [ 'ADMINIFY', 'add_custom_css' ], 80 );
78 + add_filter( 'admin_body_class', [ 'ADMINIFY', 'add_admin_body_class' ] );
79 + }
74 80
75 - add_action( 'after_setup_theme', array( 'ADMINIFY', 'setup' ) );
76 - add_action( 'init', array( 'ADMINIFY', 'setup' ) );
77 - add_action( 'switch_theme', array( 'ADMINIFY', 'setup' ) );
78 - add_action( 'admin_enqueue_scripts', array( 'ADMINIFY', 'add_admin_enqueue_scripts' ) );
79 - add_action( 'wp_enqueue_scripts', array( 'ADMINIFY', 'add_typography_enqueue_styles' ), 80 );
80 - add_action( 'wp_head', array( 'ADMINIFY', 'add_custom_css' ), 80 );
81 - add_filter( 'admin_body_class', array( 'ADMINIFY', 'add_admin_body_class' ) );
81 + // Setup frameworks
82 + public static function setup() {
82 83
83 - }
84 + // Welcome
85 + self::include_plugin_file( 'views/welcome.php' );
84 86
85 - // Setup frameworks
86 - public static function setup() {
87 + // Setup admin option framework
88 + $params = [];
89 + if ( class_exists( 'ADMINIFY_Options' ) && ! empty( self::$args['admin_options'] ) ) {
90 + foreach ( self::$args['admin_options'] as $key => $value ) {
91 + if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
92 + $params['args'] = $value;
93 + $params['sections'] = self::$args['sections'][ $key ];
94 + self::$inited[ $key ] = true;
87 95
88 - // Welcome
89 - self::include_plugin_file( 'views/welcome.php' );
96 + ADMINIFY_Options::instance( $key, $params );
90 97
91 - // Setup admin option framework
92 - $params = array();
93 - if ( class_exists( 'ADMINIFY_Options' ) && ! empty( self::$args['admin_options'] ) ) {
94 - foreach ( self::$args['admin_options'] as $key => $value ) {
95 - if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
98 + if ( ! empty( $value['show_in_customizer'] ) ) {
99 + $value['output_css'] = false;
100 + $value['enqueue_webfont'] = false;
101 + self::$args['customize_options'][ $key ] = $value;
102 + self::$inited[ $key ] = null;
103 + }
104 + }
105 + }
106 + }
96 107
97 - $params['args'] = $value;
98 - $params['sections'] = self::$args['sections'][$key];
99 - self::$inited[$key] = true;
108 + // Setup customize option framework
109 + $params = [];
110 + if ( class_exists( 'ADMINIFY_Customize_Options' ) && ! empty( self::$args['customize_options'] ) ) {
111 + foreach ( self::$args['customize_options'] as $key => $value ) {
112 + if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
113 + $params['args'] = $value;
114 + $params['sections'] = self::$args['sections'][ $key ];
115 + self::$inited[ $key ] = true;
100 116
101 - ADMINIFY_Options::instance( $key, $params );
117 + ADMINIFY_Customize_Options::instance( $key, $params );
118 + }
119 + }
120 + }
102 121
103 - if ( ! empty( $value['show_in_customizer'] ) ) {
104 - $value['output_css'] = false;
105 - $value['enqueue_webfont'] = false;
106 - self::$args['customize_options'][$key] = $value;
107 - self::$inited[$key] = null;
108 - }
122 + // Setup metabox option framework
123 + $params = [];
124 + if ( class_exists( 'ADMINIFY_Metabox' ) && ! empty( self::$args['metabox_options'] ) ) {
125 + foreach ( self::$args['metabox_options'] as $key => $value ) {
126 + if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
127 + $params['args'] = $value;
128 + $params['sections'] = self::$args['sections'][ $key ];
129 + self::$inited[ $key ] = true;
109 130
110 - }
111 - }
112 - }
131 + ADMINIFY_Metabox::instance( $key, $params );
132 + }
133 + }
134 + }
113 135
114 - // Setup customize option framework
115 - $params = array();
116 - if ( class_exists( 'ADMINIFY_Customize_Options' ) && ! empty( self::$args['customize_options'] ) ) {
117 - foreach ( self::$args['customize_options'] as $key => $value ) {
118 - if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
136 + // Setup nav menu option framework
137 + $params = [];
138 + if ( class_exists( 'ADMINIFY_Nav_Menu_Options' ) && ! empty( self::$args['nav_menu_options'] ) ) {
139 + foreach ( self::$args['nav_menu_options'] as $key => $value ) {
140 + if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
141 + $params['args'] = $value;
142 + $params['sections'] = self::$args['sections'][ $key ];
143 + self::$inited[ $key ] = true;
119 144
120 - $params['args'] = $value;
121 - $params['sections'] = self::$args['sections'][$key];
122 - self::$inited[$key] = true;
145 + ADMINIFY_Nav_Menu_Options::instance( $key, $params );
146 + }
147 + }
148 + }
123 149
124 - ADMINIFY_Customize_Options::instance( $key, $params );
150 + // Setup profile option framework
151 + $params = [];
152 + if ( class_exists( 'ADMINIFY_Profile_Options' ) && ! empty( self::$args['profile_options'] ) ) {
153 + foreach ( self::$args['profile_options'] as $key => $value ) {
154 + if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
155 + $params['args'] = $value;
156 + $params['sections'] = self::$args['sections'][ $key ];
157 + self::$inited[ $key ] = true;
125 158
126 - }
127 - }
128 - }
159 + ADMINIFY_Profile_Options::instance( $key, $params );
160 + }
161 + }
162 + }
129 163
130 - // Setup metabox option framework
131 - $params = array();
132 - if ( class_exists( 'ADMINIFY_Metabox' ) && ! empty( self::$args['metabox_options'] ) ) {
133 - foreach ( self::$args['metabox_options'] as $key => $value ) {
134 - if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
164 + // Setup taxonomy option framework
165 + $params = [];
166 + if ( class_exists( 'ADMINIFY_Taxonomy_Options' ) && ! empty( self::$args['taxonomy_options'] ) ) {
167 + $taxonomy = ( isset( $_GET['taxonomy'] ) ) ? sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ) : '';
168 + foreach ( self::$args['taxonomy_options'] as $key => $value ) {
169 + if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
170 + $params['args'] = $value;
171 + $params['sections'] = self::$args['sections'][ $key ];
172 + self::$inited[ $key ] = true;
135 173
136 - $params['args'] = $value;
137 - $params['sections'] = self::$args['sections'][$key];
138 - self::$inited[$key] = true;
174 + ADMINIFY_Taxonomy_Options::instance( $key, $params );
175 + }
176 + }
177 + }
139 178
140 - ADMINIFY_Metabox::instance( $key, $params );
179 + // Setup widget option framework
180 + if ( class_exists( 'ADMINIFY_Widget' ) && class_exists( 'WP_Widget_Factory' ) && ! empty( self::$args['widget_options'] ) ) {
181 + $wp_widget_factory = new WP_Widget_Factory();
182 + global $wp_widget_factory;
183 + foreach ( self::$args['widget_options'] as $key => $value ) {
184 + if ( ! isset( self::$inited[ $key ] ) ) {
185 + self::$inited[ $key ] = true;
186 + $wp_widget_factory->register( ADMINIFY_Widget::instance( $key, $value ) );
187 + }
188 + }
189 + }
141 190
142 - }
143 - }
144 - }
191 + // Setup comment option framework
192 + $params = [];
193 + if ( class_exists( 'ADMINIFY_Comment_Metabox' ) && ! empty( self::$args['comment_options'] ) ) {
194 + foreach ( self::$args['comment_options'] as $key => $value ) {
195 + if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
196 + $params['args'] = $value;
197 + $params['sections'] = self::$args['sections'][ $key ];
198 + self::$inited[ $key ] = true;
145 199
146 - // Setup nav menu option framework
147 - $params = array();
148 - if ( class_exists( 'ADMINIFY_Nav_Menu_Options' ) && ! empty( self::$args['nav_menu_options'] ) ) {
149 - foreach ( self::$args['nav_menu_options'] as $key => $value ) {
150 - if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
200 + ADMINIFY_Comment_Metabox::instance( $key, $params );
201 + }
202 + }
203 + }
151 204
152 - $params['args'] = $value;
153 - $params['sections'] = self::$args['sections'][$key];
154 - self::$inited[$key] = true;
205 + // Setup shortcode option framework
206 + $params = [];
207 + if ( class_exists( 'ADMINIFY_Shortcoder' ) && ! empty( self::$args['shortcode_options'] ) ) {
208 + foreach ( self::$args['shortcode_options'] as $key => $value ) {
209 + if ( ! empty( self::$args['sections'][ $key ] ) && ! isset( self::$inited[ $key ] ) ) {
210 + $params['args'] = $value;
211 + $params['sections'] = self::$args['sections'][ $key ];
212 + self::$inited[ $key ] = true;
155 213
156 - ADMINIFY_Nav_Menu_Options::instance( $key, $params );
214 + ADMINIFY_Shortcoder::instance( $key, $params );
215 + }
216 + }
157 217
158 - }
159 - }
160 - }
218 + // Once editor setup for gutenberg and media buttons
219 + if ( class_exists( 'ADMINIFY_Shortcoder' ) && ! empty( self::$shortcode_instances ) ) {
220 + foreach ( self::$shortcode_instances as $instance ) {
221 + if ( ! empty( $instance['show_in_editor'] ) ) {
222 + ADMINIFY_Shortcoder::once_editor_setup();
223 + break;
224 + }
225 + }
226 + }
227 + }
161 228
162 - // Setup profile option framework
163 - $params = array();
164 - if ( class_exists( 'ADMINIFY_Profile_Options' ) && ! empty( self::$args['profile_options'] ) ) {
165 - foreach ( self::$args['profile_options'] as $key => $value ) {
166 - if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
229 + do_action( 'adminify_loaded' );
230 + }
167 231
168 - $params['args'] = $value;
169 - $params['sections'] = self::$args['sections'][$key];
170 - self::$inited[$key] = true;
232 + // Create options
233 + public static function createOptions( $id, $args = [] ) {
234 + self::$args['admin_options'][ $id ] = $args;
235 + }
171 236
172 - ADMINIFY_Profile_Options::instance( $key, $params );
237 + // Create customize options
238 + public static function createCustomizeOptions( $id, $args = [] ) {
239 + self::$args['customize_options'][ $id ] = $args;
240 + }
173 241
174 - }
175 - }
176 - }
242 + // Create metabox options
243 + public static function createMetabox( $id, $args = [] ) {
244 + self::$args['metabox_options'][ $id ] = $args;
245 + }
177 246
178 - // Setup taxonomy option framework
179 - $params = array();
180 - if ( class_exists( 'ADMINIFY_Taxonomy_Options' ) && ! empty( self::$args['taxonomy_options'] ) ) {
181 - $taxonomy = ( isset( $_GET['taxonomy'] ) ) ? sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change.
182 - foreach ( self::$args['taxonomy_options'] as $key => $value ) {
183 - if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
247 + // Create menu options
248 + public static function createNavMenuOptions( $id, $args = [] ) {
249 + self::$args['nav_menu_options'][ $id ] = $args;
250 + }
184 251
185 - $params['args'] = $value;
186 - $params['sections'] = self::$args['sections'][$key];
187 - self::$inited[$key] = true;
252 + // Create shortcoder options
253 + public static function createShortcoder( $id, $args = [] ) {
254 + self::$args['shortcode_options'][ $id ] = $args;
255 + }
188 256
189 - ADMINIFY_Taxonomy_Options::instance( $key, $params );
257 + // Create taxonomy options
258 + public static function createTaxonomyOptions( $id, $args = [] ) {
259 + self::$args['taxonomy_options'][ $id ] = $args;
260 + }
190 261
191 - }
192 - }
193 - }
262 + // Create profile options
263 + public static function createProfileOptions( $id, $args = [] ) {
264 + self::$args['profile_options'][ $id ] = $args;
265 + }
194 266
195 - // Setup widget option framework
196 - if ( class_exists( 'ADMINIFY_Widget' ) && class_exists( 'WP_Widget_Factory' ) && ! empty( self::$args['widget_options'] ) ) {
197 - $wp_widget_factory = new WP_Widget_Factory();
198 - global $wp_widget_factory;
199 - foreach ( self::$args['widget_options'] as $key => $value ) {
200 - if ( ! isset( self::$inited[$key] ) ) {
267 + // Create widget
268 + public static function createWidget( $id, $args = [] ) {
269 + self::$args['widget_options'][ $id ] = $args;
270 + self::set_used_fields( $args );
271 + }
201 272
202 - self::$inited[$key] = true;
203 - $wp_widget_factory->register( ADMINIFY_Widget::instance( $key, $value ) );
273 + // Create comment metabox
274 + public static function createCommentMetabox( $id, $args = [] ) {
275 + self::$args['comment_options'][ $id ] = $args;
276 + }
204 277
205 - }
206 - }
207 - }
278 + // Create section
279 + public static function createSection( $id, $sections ) {
280 + self::$args['sections'][ $id ][] = $sections;
281 + self::set_used_fields( $sections );
282 + }
208 283
209 - // Setup comment option framework
210 - $params = array();
211 - if ( class_exists( 'ADMINIFY_Comment_Metabox' ) && ! empty( self::$args['comment_options'] ) ) {
212 - foreach ( self::$args['comment_options'] as $key => $value ) {
213 - if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
284 + // Set directory constants
285 + public static function constants() {
214 286
215 - $params['args'] = $value;
216 - $params['sections'] = self::$args['sections'][$key];
217 - self::$inited[$key] = true;
287 + // We need this path-finder code for set URL of framework
288 + $dirname = str_replace( '//', '/', wp_normalize_path( dirname( dirname( self::$file ) ) ) );
289 + $theme_dir = str_replace( '//', '/', wp_normalize_path( get_parent_theme_file_path() ) );
290 + $plugin_dir = str_replace( '//', '/', wp_normalize_path( WP_PLUGIN_DIR ) );
291 + $plugin_dir = str_replace( '/opt/bitnami', '/bitnami', $plugin_dir );
292 + $located_plugin = ( preg_match( '#' . self::sanitize_dirname( $plugin_dir ) . '#', self::sanitize_dirname( $dirname ) ) ) ? true : false;
293 + $directory = ( $located_plugin ) ? $plugin_dir : $theme_dir;
294 + $directory_uri = ( $located_plugin ) ? WP_PLUGIN_URL : get_parent_theme_file_uri();
295 + $foldername = str_replace( $directory, '', $dirname );
296 + $protocol_uri = ( is_ssl() ) ? 'https' : 'http';
297 + $directory_uri = set_url_scheme( $directory_uri, $protocol_uri );
218 298
219 - ADMINIFY_Comment_Metabox::instance( $key, $params );
299 + self::$dir = $dirname;
300 + self::$url = $directory_uri . $foldername;
301 + }
220 302
221 - }
222 - }
223 - }
303 + // Include file helper
304 + public static function include_plugin_file( $file, $load = true ) {
305 + $path = '';
306 + $file = ltrim( $file, '/' );
307 + $override = apply_filters( 'adminify_override', 'adminify-override' );
224 308
225 - // Setup shortcode option framework
226 - $params = array();
227 - if ( class_exists( 'ADMINIFY_Shortcoder' ) && ! empty( self::$args['shortcode_options'] ) ) {
228 - foreach ( self::$args['shortcode_options'] as $key => $value ) {
229 - if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
309 + if ( file_exists( get_parent_theme_file_path( $override . '/' . $file ) ) ) {
310 + $path = get_parent_theme_file_path( $override . '/' . $file );
311 + } elseif ( file_exists( get_theme_file_path( $override . '/' . $file ) ) ) {
312 + $path = get_theme_file_path( $override . '/' . $file );
313 + } elseif ( file_exists( self::$dir . '/' . $override . '/' . $file ) ) {
314 + $path = self::$dir . '/' . $override . '/' . $file;
315 + } elseif ( file_exists( self::$dir . '/' . $file ) ) {
316 + $path = self::$dir . '/' . $file;
317 + }
230 318
231 - $params['args'] = $value;
232 - $params['sections'] = self::$args['sections'][$key];
233 - self::$inited[$key] = true;
319 + if ( ! empty( $path ) && ! empty( $file ) && $load ) {
320 + global $wp_query;
234 321
235 - ADMINIFY_Shortcoder::instance( $key, $params );
322 + if ( is_object( $wp_query ) && function_exists( 'load_template' ) ) {
323 + load_template( $path, true );
324 + } else {
325 + require_once $path;
326 + }
327 + } else {
328 + return self::$dir . '/' . $file;
329 + }
330 + }
236 331
237 - }
238 - }
332 + // Is active plugin helper
333 + public static function is_active_plugin( $file = '' ) {
334 + return in_array( $file, (array) get_option( 'active_plugins', [] ) );
335 + }
239 336
240 - // Once editor setup for gutenberg and media buttons
241 - if ( class_exists( 'ADMINIFY_Shortcoder' ) && ! empty( self::$shortcode_instances ) ) {
242 - foreach ( self::$shortcode_instances as $instance ) {
243 - if ( ! empty( $instance['show_in_editor'] ) ) {
244 - ADMINIFY_Shortcoder::once_editor_setup();
245 - break;
246 - }
247 - }
248 - }
337 + // Sanitize dirname
338 + public static function sanitize_dirname( $dirname ) {
339 + return preg_replace( '/[^A-Za-z]/', '', $dirname );
340 + }
249 341
250 - }
342 + // Set url constant
343 + public static function include_plugin_url( $file ) {
344 + return esc_url( self::$url ) . '/' . ltrim( $file, '/' );
345 + }
251 346
252 - do_action( 'adminify_loaded' );
347 + // Include files
348 + public static function includes() {
253 349
254 - }
350 + // Include common functions
351 + self::include_plugin_file( 'functions/actions.php' );
352 + self::include_plugin_file( 'functions/helpers.php' );
353 + self::include_plugin_file( 'functions/sanitize.php' );
354 + self::include_plugin_file( 'functions/validate.php' );
255 355
256 - // Create options
257 - public static function createOptions( $id, $args = array() ) {
258 - self::$args['admin_options'][$id] = $args;
259 - }
356 + // Include free version classes
357 + self::include_plugin_file( 'classes/abstract.class.php' );
358 + self::include_plugin_file( 'classes/fields.class.php' );
359 + self::include_plugin_file( 'classes/admin-options.class.php' );
260 360
261 - // Create customize options
262 - public static function createCustomizeOptions( $id, $args = array() ) {
263 - self::$args['customize_options'][$id] = $args;
264 - }
361 + // Include premium version classes
362 + if ( self::$premium ) {
363 + self::include_plugin_file( 'classes/customize-options.class.php' );
364 + self::include_plugin_file( 'classes/metabox-options.class.php' );
365 + self::include_plugin_file( 'classes/nav-menu-options.class.php' );
366 + self::include_plugin_file( 'classes/profile-options.class.php' );
367 + self::include_plugin_file( 'classes/shortcode-options.class.php' );
368 + self::include_plugin_file( 'classes/taxonomy-options.class.php' );
369 + self::include_plugin_file( 'classes/widget-options.class.php' );
370 + self::include_plugin_file( 'classes/comment-options.class.php' );
371 + }
265 372
266 - // Create metabox options
267 - public static function createMetabox( $id, $args = array() ) {
268 - self::$args['metabox_options'][$id] = $args;
269 - }
373 + // Include all framework fields
374 + $fields = apply_filters(
375 + 'adminify_fields',
376 + [
377 + 'accordion',
378 + 'background',
379 + 'backup',
380 + 'border',
381 + 'button_set',
382 + 'callback',
383 + 'checkbox',
384 + 'code_editor',
385 + 'color',
386 + 'color_group',
387 + 'content',
388 + 'date',
389 + 'datetime',
390 + 'dimensions',
391 + 'fieldset',
392 + 'gallery',
393 + 'group',
394 + 'heading',
395 + 'icon',
396 + 'image_select',
397 + 'link',
398 + 'link_color',
399 + 'map',
400 + 'media',
401 + 'notice',
402 + 'number',
403 + 'palette',
404 + 'radio',
405 + 'repeater',
406 + 'select',
407 + 'slider',
408 + 'sortable',
409 + 'sorter',
410 + 'spacing',
411 + 'spinner',
412 + 'subheading',
413 + 'submessage',
414 + 'switcher',
415 + 'tabbed',
416 + 'text',
417 + 'textarea',
418 + 'typography',
419 + 'upload',
420 + 'wp_editor',
421 + ]
422 + );
270 423
271 - // Create menu options
272 - public static function createNavMenuOptions( $id, $args = array() ) {
273 - self::$args['nav_menu_options'][$id] = $args;
274 - }
424 + if ( ! empty( $fields ) ) {
425 + foreach ( $fields as $field ) {
426 + if ( ! class_exists( 'ADMINIFY_Field_' . $field ) && class_exists( 'ADMINIFY_Fields' ) ) {
427 + self::include_plugin_file( 'fields/' . $field . '/' . $field . '.php' );
428 + }
429 + }
430 + }
431 + }
275 432
276 - // Create shortcoder options
277 - public static function createShortcoder( $id, $args = array() ) {
278 - self::$args['shortcode_options'][$id] = $args;
279 - }
433 + // Setup textdomain
434 + public static function textdomain() {
435 + load_textdomain( 'adminify', self::$dir . '/languages/' . get_locale() . '.mo' );
436 + }
280 437
281 - // Create taxonomy options
282 - public static function createTaxonomyOptions( $id, $args = array() ) {
283 - self::$args['taxonomy_options'][$id] = $args;
284 - }
438 + // Set all of used fields
439 + public static function set_used_fields( $sections ) {
440 + if ( ! empty( $sections['fields'] ) ) {
441 + foreach ( $sections['fields'] as $field ) {
442 + if ( ! empty( $field['fields'] ) ) {
443 + self::set_used_fields( $field );
444 + }
285 445
286 - // Create profile options
287 - public static function createProfileOptions( $id, $args = array() ) {
288 - self::$args['profile_options'][$id] = $args;
289 - }
446 + if ( ! empty( $field['tabs'] ) ) {
447 + self::set_used_fields( [ 'fields' => $field['tabs'] ] );
448 + }
290 449
291 - // Create widget
292 - public static function createWidget( $id, $args = array() ) {
293 - self::$args['widget_options'][$id] = $args;
294 - self::set_used_fields( $args );
295 - }
450 + if ( ! empty( $field['accordions'] ) ) {
451 + self::set_used_fields( [ 'fields' => $field['accordions'] ] );
452 + }
296 453
297 - // Create comment metabox
298 - public static function createCommentMetabox( $id, $args = array() ) {
299 - self::$args['comment_options'][$id] = $args;
300 - }
454 + if ( ! empty( $field['type'] ) ) {
455 + self::$fields[ $field['type'] ] = $field;
456 + }
457 + }
458 + }
459 + }
301 460
302 - // Create section
303 - public static function createSection( $id, $sections ) {
304 - self::$args['sections'][$id][] = $sections;
305 - self::set_used_fields( $sections );
306 - }
461 + // Enqueue admin and fields styles and scripts
462 + public static function add_admin_enqueue_scripts() {
463 + if ( ! self::$enqueue ) {
307 464
308 - // Set directory constants
309 - public static function constants() {
465 + // Loads scripts and styles only when needed
466 + $wpscreen = get_current_screen();
310 467
311 - // We need this path-finder code for set URL of framework
312 - $dirname = str_replace( '//', '/', wp_normalize_path( dirname( dirname( self::$file ) ) ) );
313 - $theme_dir = str_replace( '//', '/', wp_normalize_path( get_parent_theme_file_path() ) );
314 - $plugin_dir = str_replace( '//', '/', wp_normalize_path( WP_PLUGIN_DIR ) );
315 - $plugin_dir = str_replace( '/opt/bitnami', '/bitnami', $plugin_dir );
316 - $located_plugin = ( preg_match( '#'. self::sanitize_dirname( $plugin_dir ) .'#', self::sanitize_dirname( $dirname ) ) ) ? true : false;
317 - $directory = ( $located_plugin ) ? $plugin_dir : $theme_dir;
318 - $directory_uri = ( $located_plugin ) ? WP_PLUGIN_URL : get_parent_theme_file_uri();
319 - $foldername = str_replace( $directory, '', $dirname );
320 - $protocol_uri = ( is_ssl() ) ? 'https' : 'http';
321 - $directory_uri = set_url_scheme( $directory_uri, $protocol_uri );
468 + if ( ! empty( self::$args['admin_options'] ) ) {
469 + foreach ( self::$args['admin_options'] as $argument ) {
470 + if ( substr( $wpscreen->id, -strlen( $argument['menu_slug'] ) ) === $argument['menu_slug'] ) {
471 + self::$enqueue = true;
472 + }
473 + }
474 + }
322 475
323 - self::$dir = $dirname;
324 - self::$url = $directory_uri . $foldername;
476 + if ( ! empty( self::$args['metabox_options'] ) ) {
477 + foreach ( self::$args['metabox_options'] as $argument ) {
478 + if ( in_array( $wpscreen->post_type, (array) $argument['post_type'] ) ) {
479 + self::$enqueue = true;
480 + }
481 + }
482 + }
325 483
326 - }
484 + if ( ! empty( self::$args['taxonomy_options'] ) ) {
485 + foreach ( self::$args['taxonomy_options'] as $argument ) {
486 + if ( in_array( $wpscreen->taxonomy, (array) $argument['taxonomy'] ) ) {
487 + self::$enqueue = true;
488 + }
489 + }
490 + }
327 491
328 - // Include file helper
329 - public static function include_plugin_file( $file, $load = true ) {
492 + if ( ! empty( self::$shortcode_instances ) ) {
493 + foreach ( self::$shortcode_instances as $argument ) {
494 + if ( ( $argument['show_in_editor'] && $wpscreen->base === 'post' ) || $argument['show_in_custom'] ) {
495 + self::$enqueue = true;
496 + }
497 + }
498 + }
330 499
331 - $path = '';
332 - $file = ltrim( $file, '/' );
333 - $override = apply_filters( 'adminify_override', 'adminify-override' );
500 + if ( ! empty( self::$args['widget_options'] ) && ( $wpscreen->id === 'widgets' || $wpscreen->id === 'customize' ) ) {
501 + self::$enqueue = true;
502 + }
334 503
335 - if ( file_exists( get_parent_theme_file_path( $override .'/'. $file ) ) ) {
336 - $path = get_parent_theme_file_path( $override .'/'. $file );
337 - } elseif ( file_exists( get_theme_file_path( $override .'/'. $file ) ) ) {
338 - $path = get_theme_file_path( $override .'/'. $file );
339 - } elseif ( file_exists( self::$dir .'/'. $override .'/'. $file ) ) {
340 - $path = self::$dir .'/'. $override .'/'. $file;
341 - } elseif ( file_exists( self::$dir .'/'. $file ) ) {
342 - $path = self::$dir .'/'. $file;
343 - }
504 + if ( ! empty( self::$args['customize_options'] ) && $wpscreen->id === 'customize' ) {
505 + self::$enqueue = true;
506 + }
344 507
345 - if ( ! empty( $path ) && ! empty( $file ) && $load ) {
508 + if ( ! empty( self::$args['nav_menu_options'] ) && $wpscreen->id === 'nav-menus' ) {
509 + self::$enqueue = true;
510 + }
346 511
347 - global $wp_query;
512 + if ( ! empty( self::$args['profile_options'] ) && ( $wpscreen->id === 'profile' || $wpscreen->id === 'user-edit' ) ) {
513 + self::$enqueue = true;
514 + }
348 515
349 - if ( is_object( $wp_query ) && function_exists( 'load_template' ) ) {
516 + if ( ! empty( self::$args['comment_options'] ) && $wpscreen->id === 'comment' ) {
517 + self::$enqueue = true;
518 + }
350 519
351 - load_template( $path, true );
520 + if ( $wpscreen->id === 'tools_page_adminify-welcome' ) {
521 + self::$enqueue = true;
522 + }
523 + }
352 524
353 - } else {
525 + if ( ! apply_filters( 'adminify_enqueue_assets', self::$enqueue ) ) {
526 + return;
527 + }
354 528
355 - require_once( $path );
529 + // Admin utilities
530 + wp_enqueue_media();
356 531
357 - }
532 + // Wp color picker
533 + wp_enqueue_style( 'wp-color-picker' );
534 + wp_enqueue_script( 'wp-color-picker' );
358 535
359 - } else {
536 + // Font awesome 4 and 5 loader
537 + if ( apply_filters( 'adminify_fa4', false ) ) {
538 + wp_enqueue_style( 'adminify-fa', 'https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css', [], '4.7.0', 'all' );
539 + } else {
540 + wp_enqueue_style( 'adminify-fa5', 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/all.min.css', [], '5.15.5', 'all' );
541 + wp_enqueue_style( 'adminify-fa5-v4-shims', 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/v4-shims.min.css', [], '5.15.5', 'all' );
542 + }
360 543
361 - return self::$dir .'/'. $file;
544 + // Check for developer mode
545 + $min = ( self::$premium && SCRIPT_DEBUG ) ? '' : '.min';
362 546
363 - }
547 + // Main style
548 + wp_enqueue_style( 'adminify', self::include_plugin_url( 'assets/css/style' . $min . '.css' ), [], self::$version, 'all' );
364 549
365 - }
550 + // Main RTL styles
551 + if ( is_rtl() ) {
552 + wp_enqueue_style( 'adminify-rtl', self::include_plugin_url( 'assets/css/style-rtl' . $min . '.css' ), [], self::$version, 'all' );
553 + }
366 554
367 - // Is active plugin helper
368 - public static function is_active_plugin( $file = '' ) {
369 - return in_array( $file, (array) get_option( 'active_plugins', array() ) );
370 - }
555 + // Main scripts
556 + wp_enqueue_script( 'adminify-plugins', self::include_plugin_url( 'assets/js/plugins' . $min . '.js' ), [], self::$version, true );
557 + wp_enqueue_script( 'adminify', self::include_plugin_url( 'assets/js/main' . $min . '.js' ), [ 'adminify-plugins' ], self::$version, true );
371 558
372 - // Sanitize dirname
373 - public static function sanitize_dirname( $dirname ) {
374 - return preg_replace( '/[^A-Za-z]/', '', $dirname );
375 - }
559 + // Main variables
560 + wp_localize_script(
561 + 'adminify',
562 + 'adminify_vars',
563 + [
564 + 'color_palette' => apply_filters( 'adminify_color_palette', [] ),
565 + 'i18n' => [
566 + 'confirm' => esc_html__( 'Are you sure?', 'adminify' ),
567 + 'typing_text' => esc_html__( 'Please enter %s or more characters', 'adminify' ),
568 + 'searching_text' => esc_html__( 'Searching...', 'adminify' ),
569 + 'no_results_text' => esc_html__( 'No results found.', 'adminify' ),
570 + ],
571 + ]
572 + );
376 573
377 - // Set url constant
378 - public static function include_plugin_url( $file ) {
379 - return esc_url( self::$url ) .'/'. ltrim( $file, '/' );
380 - }
574 + // Enqueue fields scripts and styles
575 + $enqueued = [];
381 576
382 - // Include files
383 - public static function includes() {
577 + if ( ! empty( self::$fields ) ) {
578 + foreach ( self::$fields as $field ) {
579 + if ( ! empty( $field['type'] ) ) {
580 + $classname = 'ADMINIFY_Field_' . $field['type'];
581 + if ( class_exists( $classname ) && method_exists( $classname, 'enqueue' ) ) {
582 + $instance = new $classname( $field );
583 + if ( method_exists( $classname, 'enqueue' ) ) {
584 + $instance->enqueue();
585 + }
586 + unset( $instance );
587 + }
588 + }
589 + }
590 + }
384 591
385 - // Include common functions
386 - self::include_plugin_file( 'functions/actions.php' );
387 - self::include_plugin_file( 'functions/helpers.php' );
388 - self::include_plugin_file( 'functions/sanitize.php' );
389 - self::include_plugin_file( 'functions/validate.php' );
592 + do_action( 'adminify_enqueue' );
593 + }
390 594
391 - // Include free version classes
392 - self::include_plugin_file( 'classes/abstract.class.php' );
393 - self::include_plugin_file( 'classes/fields.class.php' );
394 - self::include_plugin_file( 'classes/admin-options.class.php' );
595 + // Add typography enqueue styles to front page
596 + public static function add_typography_enqueue_styles() {
597 + if ( ! empty( self::$webfonts ) ) {
598 + if ( ! empty( self::$webfonts['enqueue'] ) ) {
599 + $query = [];
600 + $fonts = [];
395 601
396 - // Include premium version classes
397 - if ( self::$premium ) {
398 - self::include_plugin_file( 'classes/customize-options.class.php' );
399 - self::include_plugin_file( 'classes/metabox-options.class.php' );
400 - self::include_plugin_file( 'classes/nav-menu-options.class.php' );
401 - self::include_plugin_file( 'classes/profile-options.class.php' );
402 - self::include_plugin_file( 'classes/shortcode-options.class.php' );
403 - self::include_plugin_file( 'classes/taxonomy-options.class.php' );
404 - self::include_plugin_file( 'classes/widget-options.class.php' );
405 - self::include_plugin_file( 'classes/comment-options.class.php' );
406 - }
602 + foreach ( self::$webfonts['enqueue'] as $family => $styles ) {
603 + $fonts[] = $family . ( ( ! empty( $styles ) ) ? ':' . implode( ',', $styles ) : '' );
604 + }
407 605
408 - // Include all framework fields
409 - $fields = apply_filters( 'adminify_fields', array(
410 - 'accordion',
411 - 'background',
412 - 'backup',
413 - 'border',
414 - 'button_set',
415 - 'callback',
416 - 'checkbox',
417 - 'code_editor',
418 - 'color',
419 - 'color_group',
420 - 'content',
421 - 'date',
422 - 'datetime',
423 - 'dimensions',
424 - 'fieldset',
425 - 'gallery',
426 - 'group',
427 - 'heading',
428 - 'icon',
429 - 'image_select',
430 - 'link',
431 - 'link_color',
432 - 'map',
433 - 'media',
434 - 'notice',
435 - 'number',
436 - 'palette',
437 - 'radio',
438 - 'repeater',
439 - 'select',
440 - 'slider',
441 - 'sortable',
442 - 'sorter',
443 - 'spacing',
444 - 'spinner',
445 - 'subheading',
446 - 'submessage',
447 - 'switcher',
448 - 'tabbed',
449 - 'text',
450 - 'textarea',
451 - 'typography',
452 - 'upload',
453 - 'wp_editor',
454 - ) );
606 + if ( ! empty( $fonts ) ) {
607 + $query['family'] = implode( '%7C', $fonts );
608 + }
455 609
456 - if ( ! empty( $fields ) ) {
457 - foreach ( $fields as $field ) {
458 - if ( ! class_exists( 'ADMINIFY_Field_'. $field ) && class_exists( 'ADMINIFY_Fields' ) ) {
459 - self::include_plugin_file( 'fields/'. $field .'/'. $field .'.php' );
460 - }
461 - }
462 - }
610 + if ( ! empty( self::$subsets ) ) {
611 + $query['subset'] = implode( ',', self::$subsets );
612 + }
463 613
464 - }
614 + $query['display'] = 'swap';
465 615
466 - // Setup textdomain
467 - public static function textdomain() {
468 - load_textdomain( 'adminify', self::$dir .'/languages/'. get_locale() .'.mo' );
469 - }
616 + wp_enqueue_style( 'adminify-google-web-fonts', esc_url( add_query_arg( $query, '//fonts.googleapis.com/css' ) ), [], null );
617 + }
470 618
471 - // Set all of used fields
472 - public static function set_used_fields( $sections ) {
619 + if ( ! empty( self::$webfonts['async'] ) ) {
620 + $fonts = [];
473 621
474 - if ( ! empty( $sections['fields'] ) ) {
622 + foreach ( self::$webfonts['async'] as $family => $styles ) {
623 + $fonts[] = $family . ( ( ! empty( $styles ) ) ? ':' . implode( ',', $styles ) : '' );
624 + }
475 625
476 - foreach ( $sections['fields'] as $field ) {
626 + wp_enqueue_script( 'adminify-google-web-fonts', esc_url( '//ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js' ), [], null );
477 627
478 - if ( ! empty( $field['fields'] ) ) {
479 - self::set_used_fields( $field );
480 - }
628 + wp_localize_script( 'adminify-google-web-fonts', 'WebFontConfig', [ 'google' => [ 'families' => $fonts ] ] );
629 + }
630 + }
631 + }
481 632
482 - if ( ! empty( $field['tabs'] ) ) {
483 - self::set_used_fields( array( 'fields' => $field['tabs'] ) );
484 - }
633 + // Add admin body class
634 + public static function add_admin_body_class( $classes ) {
635 + if ( apply_filters( 'adminify_fa4', false ) ) {
636 + $classes .= 'adminify-fa5-shims';
637 + }
485 638
486 - if ( ! empty( $field['accordions'] ) ) {
487 - self::set_used_fields( array( 'fields' => $field['accordions'] ) );
488 - }
639 + return $classes;
640 + }
489 641
490 - if ( ! empty( $field['elements'] ) ) {
491 - self::set_used_fields( array( 'fields' => $field['elements'] ) );
492 - }
642 + // Add custom css to front page
643 + public static function add_custom_css() {
644 + if ( ! empty( self::$css ) ) {
645 + echo '<style type="text/css">' . esc_attr( self::$css ) . '</style>';
646 + }
647 + }
493 648
494 - if ( ! empty( $field['type'] ) ) {
495 - self::$fields[$field['type']] = $field;
496 - }
649 + // Add a new framework field
650 + public static function field( $field = [], $value = '', $unique = '', $where = '', $parent = '' ) {
497 651
498 - }
652 + // Check for unallow fields
653 + if ( ! empty( $field['_notice'] ) ) {
654 + $field_type = $field['type'];
499 655
500 - }
656 + $field = [];
657 + $field['content'] = esc_html__( 'Oops! Not allowed.', 'adminify' ) . ' <strong>(' . $field_type . ')</strong>';
658 + $field['type'] = 'notice';
659 + $field['style'] = 'danger';
660 + }
501 661
502 - }
662 + $depend = '';
663 + $visible = '';
664 + $unique = ( ! empty( $unique ) ) ? $unique : '';
665 + $class = ( ! empty( $field['class'] ) ) ? ' ' . esc_attr( $field['class'] ) : '';
666 + $is_pseudo = ( ! empty( $field['pseudo'] ) ) ? ' adminify-pseudo-field' : '';
667 + $field_type = ( ! empty( $field['type'] ) ) ? esc_attr( $field['type'] ) : '';
503 668
504 - // Enqueue admin and fields styles and scripts
505 - public static function add_admin_enqueue_scripts() {
669 + if ( ! empty( $field['dependency'] ) ) {
670 + $dependency = $field['dependency'];
671 + $depend_visible = '';
672 + $data_controller = '';
673 + $data_condition = '';
674 + $data_value = '';
675 + $data_global = '';
506 676
507 - if ( ! self::$enqueue ) {
677 + if ( is_array( $dependency[0] ) ) {
678 + $data_controller = implode( '|', array_column( $dependency, 0 ) );
679 + $data_condition = implode( '|', array_column( $dependency, 1 ) );
680 + $data_value = implode( '|', array_column( $dependency, 2 ) );
681 + $data_global = implode( '|', array_column( $dependency, 3 ) );
682 + $depend_visible = implode( '|', array_column( $dependency, 4 ) );
683 + } else {
684 + $data_controller = ( ! empty( $dependency[0] ) ) ? $dependency[0] : '';
685 + $data_condition = ( ! empty( $dependency[1] ) ) ? $dependency[1] : '';
686 + $data_value = ( ! empty( $dependency[2] ) ) ? $dependency[2] : '';
687 + $data_global = ( ! empty( $dependency[3] ) ) ? $dependency[3] : '';
688 + $depend_visible = ( ! empty( $dependency[4] ) ) ? $dependency[4] : '';
689 + }
508 690
509 - // Loads scripts and styles only when needed
510 - $wpscreen = get_current_screen();
691 + $depend .= ' data-controller="' . $data_controller . '"';
692 + $depend .= ' data-condition="' . $data_condition . '"';
693 + $depend .= ' data-value="' . $data_value . '"';
694 + $depend .= ( ! empty( $data_global ) ) ? ' data-depend-global="true"' : '';
511 695
512 - if ( ! empty( self::$args['admin_options'] ) ) {
513 - foreach ( self::$args['admin_options'] as $argument ) {
514 - if ( substr( $wpscreen->id, -strlen( $argument['menu_slug'] ) ) === $argument['menu_slug'] ) {
515 - self::$enqueue = true;
516 - }
517 - }
518 - }
696 + $visible = ( ! empty( $depend_visible ) ) ? ' adminify-depend-visible' : ' adminify-depend-hidden';
697 + }
519 698
520 - if ( ! empty( self::$args['metabox_options'] ) ) {
521 - foreach ( self::$args['metabox_options'] as $argument ) {
522 - if ( in_array( $wpscreen->post_type, (array) $argument['post_type'] ) ) {
523 - self::$enqueue = true;
524 - }
525 - }
526 - }
699 + // These attributes has been sanitized above.
700 + echo '<div class="adminify-field adminify-field-' . esc_attr( $field_type . $is_pseudo . $class . $visible ) . '"' . wp_kses_post( $depend ) . '>';
527 701
528 - if ( ! empty( self::$args['taxonomy_options'] ) ) {
529 - foreach ( self::$args['taxonomy_options'] as $argument ) {
530 - if ( in_array( $wpscreen->taxonomy, (array) $argument['taxonomy'] ) ) {
531 - self::$enqueue = true;
532 - }
533 - }
534 - }
702 + if ( ! empty( $field_type ) ) {
703 + if ( ! empty( $field['title'] ) ) {
704 + echo '<div class="adminify-title">';
705 + echo '<h4>' . wp_kses_post( $field['title'] ) . '</h4>';
706 + echo ( ! empty( $field['subtitle'] ) ) ? '<div class="adminify-subtitle-text">' . wp_kses_post( $field['subtitle'] ) . '</div>' : '';
707 + echo '</div>';
708 + }
535 709
536 - if ( ! empty( self::$shortcode_instances ) ) {
537 - foreach ( self::$shortcode_instances as $argument ) {
538 - if ( ( $argument['show_in_editor'] && $wpscreen->base === 'post' ) || $argument['show_in_custom'] ) {
539 - self::$enqueue = true;
540 - }
541 - }
542 - }
710 + echo ( ! empty( $field['title'] ) ) ? '<div class="adminify-fieldset">' : '';
543 711
544 - if ( ! empty( self::$args['widget_options'] ) && ( $wpscreen->id === 'widgets' || $wpscreen->id === 'customize' ) ) {
545 - self::$enqueue = true;
546 - }
712 + $value = ( ! isset( $value ) && isset( $field['default'] ) ) ? $field['default'] : $value;
713 + $value = ( isset( $field['value'] ) ) ? $field['value'] : $value;
547 714
548 - if ( ! empty( self::$args['customize_options'] ) && $wpscreen->id === 'customize' ) {
549 - self::$enqueue = true;
550 - }
715 + $classname = 'ADMINIFY_Field_' . $field_type;
551 716
552 - if ( ! empty( self::$args['nav_menu_options'] ) && $wpscreen->id === 'nav-menus' ) {
553 - self::$enqueue = true;
554 - }
717 + if ( class_exists( $classname ) ) {
718 + $instance = new $classname( $field, $value, $unique, $where, $parent );
719 + $instance->render();
720 + } else {
721 + echo '<p>' . esc_html__( 'Field not found!', 'adminify' ) . '</p>';
722 + }
723 + } else {
724 + echo '<p>' . esc_html__( 'Field not found!', 'adminify' ) . '</p>';
725 + }
555 726
556 - if ( ! empty( self::$args['profile_options'] ) && ( $wpscreen->id === 'profile' || $wpscreen->id === 'user-edit' ) ) {
557 - self::$enqueue = true;
558 - }
727 + echo ( ! empty( $field['title'] ) ) ? '</div>' : '';
728 + echo '<div class="clear"></div>';
729 + echo '</div>';
730 + }
559 731
560 - if ( ! empty( self::$args['comment_options'] ) && $wpscreen->id === 'comment' ) {
561 - self::$enqueue = true;
562 - }
732 + }
563 733
564 - if ( $wpscreen->id === 'tools_page_adminify-welcome' ) {
565 - self::$enqueue = true;
566 - }
567 -
568 - }
569 -
570 - if ( ! apply_filters( 'adminify_enqueue_assets', self::$enqueue ) ) {
571 - return;
572 - }
573 -
574 - // Admin utilities
575 - wp_enqueue_media();
576 -
577 - // Wp color picker
578 - wp_enqueue_style( 'wp-color-picker' );
579 - wp_enqueue_script( 'wp-color-picker' );
580 -
581 - // Font awesome 4 and 5 loader. The font files live in the main plugin's
582 - // assets/ directory, not inside the framework, so resolve the base URL
583 - // from there to avoid a 404 on the framework-relative path.
584 - $adminify_fa_base = defined( 'PXLBSADMINIFY_ASSETS' )
585 - ? PXLBSADMINIFY_ASSETS . 'vendors/fontawesome/'
586 - : self::include_plugin_url( 'assets/vendors/fontawesome/' );
587 - if ( apply_filters( 'adminify_fa4', false ) ) {
588 - wp_enqueue_style( 'adminify-fa', $adminify_fa_base . 'fa4/css/font-awesome.min.css', array(), '4.7.0', 'all' );
589 - } else {
590 - wp_enqueue_style( 'adminify-fa5', $adminify_fa_base . 'fa5/css/all.min.css', array(), '5.15.4', 'all' );
591 - wp_enqueue_style( 'adminify-fa5-v4-shims', $adminify_fa_base . 'fa5/css/v4-shims.min.css', array(), '5.15.4', 'all' );
592 - }
593 -
594 - // Check for developer mode
595 - $min = ( self::$premium && SCRIPT_DEBUG ) ? '' : '.min';
596 -
597 - // Main style
598 - wp_enqueue_style( 'adminify', self::include_plugin_url( 'assets/css/style'. $min .'.css' ), array(), self::$version, 'all' );
599 -
600 - // Main RTL styles
601 - if ( is_rtl() ) {
602 - wp_enqueue_style( 'adminify-rtl', self::include_plugin_url( 'assets/css/style-rtl'. $min .'.css' ), array(), self::$version, 'all' );
603 - }
604 -
605 - // Main scripts
606 - wp_enqueue_script( 'adminify-plugins', self::include_plugin_url( 'assets/js/plugins'. $min .'.js' ), array(), self::$version, true );
607 - wp_enqueue_script( 'adminify', self::include_plugin_url( 'assets/js/main'. $min .'.js' ), array( 'adminify-plugins' ), self::$version, true );
608 -
609 - // Main variables
610 - wp_localize_script( 'adminify', 'adminify_vars', array(
611 - 'color_palette' => apply_filters( 'adminify_color_palette', array() ),
612 - 'i18n' => array(
613 - 'confirm' => esc_html__( 'Are you sure?', 'adminify' ),
614 - /* translators: %s: minimum number of characters required to trigger a search. */
615 - 'typing_text' => esc_html__( 'Please enter %s or more characters', 'adminify' ),
616 - 'searching_text' => esc_html__( 'Searching...', 'adminify' ),
617 - 'no_results_text' => esc_html__( 'No results found.', 'adminify' ),
618 - ),
619 - ) );
620 -
621 - // Enqueue fields scripts and styles
622 - $enqueued = array();
623 -
624 - if ( ! empty( self::$fields ) ) {
625 - foreach ( self::$fields as $field ) {
626 - if ( ! empty( $field['type'] ) ) {
627 - $classname = 'ADMINIFY_Field_' . $field['type'];
628 - if ( class_exists( $classname ) && method_exists( $classname, 'enqueue' ) ) {
629 - $instance = new $classname( $field );
630 - if ( method_exists( $classname, 'enqueue' ) ) {
631 - $instance->enqueue();
632 - }
633 - unset( $instance );
634 - }
635 - }
636 - }
637 - }
638 -
639 - do_action( 'adminify_enqueue' );
640 -
641 - }
642 -
643 - // Add typography enqueue styles to front page
644 - public static function add_typography_enqueue_styles() {
645 -
646 - if ( ! empty( self::$webfonts ) ) {
647 -
648 - if ( ! empty( self::$webfonts['enqueue'] ) ) {
649 -
650 - $query = array();
651 - $fonts = array();
652 -
653 - foreach ( self::$webfonts['enqueue'] as $family => $styles ) {
654 - $fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' );
655 - }
656 -
657 - if ( ! empty( $fonts ) ) {
658 - $query['family'] = implode( '%7C', $fonts );
659 - }
660 -
661 - if ( ! empty( self::$subsets ) ) {
662 - $query['subset'] = implode( ',', self::$subsets );
663 - }
664 -
665 - $query['display'] = 'swap';
666 -
667 - wp_enqueue_style( 'adminify-google-web-fonts', esc_url( add_query_arg( $query, '//fonts.googleapis.com/css' ) ), array(), PXLBSADMINIFY_VER );
668 -
669 - }
670 -
671 - if ( ! empty( self::$webfonts['async'] ) ) {
672 -
673 - $fonts = array();
674 -
675 - foreach ( self::$webfonts['async'] as $family => $styles ) {
676 - $fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' );
677 - }
678 -
679 - wp_enqueue_script( 'adminify-google-web-fonts', self::include_plugin_url( 'assets/js/webfont.js' ), array(), self::$version, false );
680 -
681 - wp_localize_script( 'adminify-google-web-fonts', 'WebFontConfig', array( 'google' => array( 'families' => $fonts ) ) );
682 -
683 - }
684 -
685 - }
686 -
687 - }
688 -
689 - // Add admin body class
690 - public static function add_admin_body_class( $classes ) {
691 -
692 - if ( apply_filters( 'adminify_fa4', false ) ) {
693 - $classes .= 'adminify-fa5-shims';
694 - }
695 -
696 - return $classes;
697 -
698 - }
699 -
700 - // Add custom css to front page
701 - public static function add_custom_css() {
702 -
703 - if ( ! empty( self::$css ) ) {
704 - echo '<style type="text/css">'. wp_strip_all_tags( self::$css ) .'</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_strip_all_tags() removes all markup; CSS-only content cannot break out of the <style> block.
705 - }
706 -
707 - }
708 -
709 - // Add a new framework field
710 - public static function field( $field = array(), $value = '', $unique = '', $where = '', $parent = '' ) {
711 -
712 - // Check for unallow fields
713 - if ( ! empty( $field['_notice'] ) ) {
714 -
715 - $field_type = $field['type'];
716 -
717 - $field = array();
718 - $field['content'] = esc_html__( 'Oops! Not allowed.', 'adminify' ) .' <strong>('. $field_type .')</strong>';
719 - $field['type'] = 'notice';
720 - $field['style'] = 'danger';
721 -
722 - }
723 -
724 - $depend = '';
725 - $visible = '';
726 - $unique = ( ! empty( $unique ) ) ? $unique : '';
727 - $class = ( ! empty( $field['class'] ) ) ? ' ' . esc_attr( $field['class'] ) : '';
728 - $is_pseudo = ( ! empty( $field['pseudo'] ) ) ? ' adminify-pseudo-field' : '';
729 - $field_type = ( ! empty( $field['type'] ) ) ? esc_attr( $field['type'] ) : '';
730 -
731 - if ( ! empty( $field['dependency'] ) ) {
732 -
733 - $dependency = $field['dependency'];
734 - $depend_visible = '';
735 - $data_controller = '';
736 - $data_condition = '';
737 - $data_value = '';
738 - $data_global = '';
739 -
740 - if ( is_array( $dependency[0] ) ) {
741 - $data_controller = implode( '|', array_column( $dependency, 0 ) );
742 - $data_condition = implode( '|', array_column( $dependency, 1 ) );
743 - $data_value = implode( '|', array_column( $dependency, 2 ) );
744 - $data_global = implode( '|', array_column( $dependency, 3 ) );
745 - $depend_visible = implode( '|', array_column( $dependency, 4 ) );
746 - } else {
747 - $data_controller = ( ! empty( $dependency[0] ) ) ? $dependency[0] : '';
748 - $data_condition = ( ! empty( $dependency[1] ) ) ? $dependency[1] : '';
749 - $data_value = ( ! empty( $dependency[2] ) ) ? $dependency[2] : '';
750 - $data_global = ( ! empty( $dependency[3] ) ) ? $dependency[3] : '';
751 - $depend_visible = ( ! empty( $dependency[4] ) ) ? $dependency[4] : '';
752 - }
753 -
754 - $depend .= ' data-controller="'. esc_attr( $data_controller ) .'"';
755 - $depend .= ' data-condition="'. esc_attr( $data_condition ) .'"';
756 - $depend .= ' data-value="'. esc_attr( $data_value ) .'"';
757 - $depend .= ( ! empty( $data_global ) ) ? ' data-depend-global="true"' : '';
758 -
759 - $visible = ( ! empty( $depend_visible ) ) ? ' adminify-depend-visible' : ' adminify-depend-hidden';
760 -
761 - }
762 -
763 - // These attributes has been sanitized above.
764 - ob_start();
765 - echo '<div class="adminify-field adminify-field-'. esc_attr( $field_type . $is_pseudo . $class . $visible ) .'"'. $depend .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- value pre-escaped where built.
766 -
767 - if ( ! empty( $field_type ) ) {
768 -
769 - if ( ! empty( $field['title'] ) ) {
770 - echo '<div class="adminify-title">';
771 - echo '<h4>'. wp_kses_post( $field['title'] ) .'</h4>';
772 - echo ( ! empty( $field['subtitle'] ) ) ? '<div class="adminify-subtitle-text">'. wp_kses_post( $field['subtitle'] ) .'</div>' : '';
773 - echo '</div>';
774 - }
775 -
776 - echo ( ! empty( $field['title'] ) ) ? '<div class="adminify-fieldset">' : '';
777 -
778 - $value = ( ! isset( $value ) && isset( $field['default'] ) ) ? $field['default'] : $value;
779 - $value = ( isset( $field['value'] ) ) ? $field['value'] : $value;
780 -
781 - $classname = 'ADMINIFY_Field_'. $field_type;
782 -
783 - if ( class_exists( $classname ) ) {
784 - $instance = new $classname( $field, $value, $unique, $where, $parent );
785 - $instance->render();
786 - } else {
787 - echo '<p>'. esc_html__( 'Field not found!', 'adminify' ) .'</p>';
788 - }
789 -
790 - } else {
791 - echo '<p>'. esc_html__( 'Field not found!', 'adminify' ) .'</p>';
792 - }
793 -
794 - echo ( ! empty( $field['title'] ) ) ? '</div>' : '';
795 - echo '<div class="clear"></div>';
796 - echo '</div>';
797 -
798 - $html = ob_get_clean();
799 - echo apply_filters( 'pxlbsadminify_render_field_html', $html, $field ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- value pre-escaped where built.
800 -
801 - }
802 -
803 - }
804 -
805 734 }
806 735
807 736 ADMINIFY_Setup::init( __FILE__, true );
808 737
@@ -811,9 +740,8 @@
811 740 * Extended Setup Class for Shortland
812 741 *
813 742 * @since 1.0.0
814 743 * @version 1.0.0
815 - *
816 744 */
817 745 if ( ! class_exists( 'ADMINIFY' ) ) {
818 - class ADMINIFY extends ADMINIFY_Setup{}
746 + class ADMINIFY extends ADMINIFY_Setup{}
819 747 }