PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.2.4.1
Adminify – White Label, Admin Menu Editor, Login Customizer v3.2.4.1
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/customize-options.class.php +217 -208 4.2.133.2.4.1 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 * Customize Options Class
5 6 *
@@ -4,258 +5,266 @@
4 5 * Customize Options Class
5 6 *
6 7 * @since 1.0.0
7 8 * @version 1.0.0
8 - *
9 9 */
10 10 if ( ! class_exists( 'ADMINIFY_Customize_Options' ) ) {
11 - class ADMINIFY_Customize_Options extends ADMINIFY_Abstract {
11 + class ADMINIFY_Customize_Options extends ADMINIFY_Abstract {
12 12
13 - // constans
14 - public $unique = '';
15 - public $abstract = 'customize';
16 - public $options = array();
17 - public $sections = array();
18 - public $pre_fields = array();
19 - public $pre_sections = array();
20 - public $priority = 10;
21 - public $args = array(
22 - 'database' => 'option',
23 - 'transport' => 'refresh',
24 - 'capability' => 'manage_options',
25 - 'save_defaults' => true,
26 - 'enqueue_webfont' => true,
27 - 'async_webfont' => false,
28 - 'output_css' => true,
29 - 'defaults' => array()
30 - );
13 + // constans
14 + public $unique = '';
15 + public $abstract = 'customize';
16 + public $options = [];
17 + public $sections = [];
18 + public $pre_fields = [];
19 + public $pre_tabs = [];
20 + public $priority = 10;
21 + public $args = [
22 + 'database' => 'option',
23 + 'transport' => 'refresh',
24 + 'capability' => 'manage_options',
25 + 'save_defaults' => true,
26 + 'enqueue_webfont' => true,
27 + 'async_webfont' => false,
28 + 'output_css' => true,
29 + 'defaults' => [],
30 + ];
31 31
32 - // run customize construct
33 - public function __construct( $key, $params ) {
32 + // run customize construct
33 + public function __construct( $key, $params ) {
34 + $this->unique = $key;
35 + $this->args = apply_filters( "adminify_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
36 + $this->sections = apply_filters( "adminify_{$this->unique}_sections", $params['sections'], $this );
37 + $this->pre_fields = $this->pre_fields( $this->sections );
34 38
35 - $this->unique = $key;
36 - $this->args = apply_filters( "adminify_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
37 - $this->sections = apply_filters( "adminify_{$this->unique}_sections", $params['sections'], $this );
38 - $this->pre_fields = $this->pre_fields( $this->sections );
39 - $this->pre_sections = $this->pre_sections_customize( $this->sections );
39 + $this->get_options();
40 + $this->save_defaults();
40 41
41 - $this->get_options();
42 - $this->save_defaults();
42 + add_action( 'customize_register', [ $this, 'add_customize_options' ] );
43 + add_action( 'customize_save_after', [ $this, 'add_customize_save_after' ] );
43 44
44 - add_action( 'customize_register', array( $this, 'add_customize_options' ) );
45 - add_action( 'customize_save_after', array( $this, 'add_customize_save_after' ) );
45 + // Get options for enqueue actions
46 + if ( is_customize_preview() ) {
47 + add_action( 'wp_enqueue_scripts', [ $this, 'get_options' ] );
48 + }
46 49
47 - // Get options for enqueue actions
48 - if ( is_customize_preview() ) {
49 - add_action( 'wp_enqueue_scripts', array( $this, 'get_options' ) );
50 - }
50 + // wp enqeueu for typography and output css
51 + parent::__construct();
52 + }
51 53
52 - // wp enqeueu for typography and output css
53 - parent::__construct();
54 + // instance
55 + public static function instance( $key, $params = [] ) {
56 + return new self( $key, $params );
57 + }
54 58
55 - }
59 + public function add_customize_save_after( $wp_customize ) {
60 + do_action( "adminify_{$this->unique}_save_before", $this->get_options(), $this, $wp_customize );
61 + do_action( "adminify_{$this->unique}_saved", $this->get_options(), $this, $wp_customize );
62 + do_action( "adminify_{$this->unique}_save_after", $this->get_options(), $this, $wp_customize );
63 + }
56 64
57 - // instance
58 - public static function instance( $key, $params = array() ) {
59 - return new self( $key, $params );
60 - }
65 + // get default value
66 + public function get_default( $field ) {
67 + $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
68 + $default = ( isset( $this->args['defaults'][ $field['id'] ] ) ) ? $this->args['defaults'][ $field['id'] ] : $default;
61 69
62 - public function add_customize_save_after( $wp_customize ) {
63 - do_action( "adminify_{$this->unique}_save_before", $this->get_options(), $this, $wp_customize );
64 - do_action( "adminify_{$this->unique}_saved", $this->get_options(), $this, $wp_customize );
65 - do_action( "adminify_{$this->unique}_save_after", $this->get_options(), $this, $wp_customize );
66 - }
70 + return $default;
71 + }
67 72
68 - // get default value
69 - public function get_default( $field ) {
73 + // get option
74 + public function get_options() {
75 + if ( $this->args['database'] === 'theme_mod' ) {
76 + $this->options = get_theme_mod( $this->unique, [] );
77 + } else {
78 + $this->options = get_option( $this->unique, [] );
79 + }
70 80
71 - $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
72 - $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
81 + if ( empty( $this->options ) ) {
82 + $this->options = [];
83 + }
73 84
74 - return $default;
85 + return $this->options;
86 + }
75 87
76 - }
88 + // save defaults and set new fields value to main options
89 + public function save_defaults() {
90 + $tmp_options = $this->options;
77 91
78 - // get option
79 - public function get_options() {
92 + if ( ! empty( $this->pre_fields ) ) {
93 + foreach ( $this->pre_fields as $field ) {
94 + if ( ! empty( $field['id'] ) ) {
95 + $this->options[ $field['id'] ] = ( isset( $this->options[ $field['id'] ] ) ) ? $this->options[ $field['id'] ] : $this->get_default( $field );
96 + }
97 + }
98 + }
80 99
81 - if ( $this->args['database'] === 'theme_mod' ) {
82 - $this->options = get_theme_mod( $this->unique, array() );
83 - } else {
84 - $this->options = get_option( $this->unique, array() );
85 - }
100 + if ( $this->args['save_defaults'] && empty( $this->args['show_in_customizer'] ) && empty( $tmp_options ) ) {
101 + if ( $this->args['database'] === 'theme_mod' ) {
102 + set_theme_mod( $this->unique, $this->options );
103 + } else {
104 + update_option( $this->unique, $this->options );
105 + }
106 + }
107 + }
86 108
87 - if ( empty( $this->options ) ) {
88 - $this->options = array();
89 - }
109 + public function pre_fields( $sections ) {
110 + $result = [];
90 111
91 - return $this->options;
112 + foreach ( $sections as $key => $section ) {
113 + if ( ! empty( $section['fields'] ) ) {
114 + foreach ( $section['fields'] as $field ) {
115 + $result[] = $field;
116 + }
117 + }
118 + }
92 119
93 - }
120 + return $result;
121 + }
94 122
95 - // save defaults and set new fields value to main options
96 - public function save_defaults() {
97 123
98 - $tmp_options = $this->options;
124 + public function pre_tabs( $sections ) {
125 + $result = [];
126 + $parents = [];
99 127
100 - if ( ! empty( $this->pre_fields ) ) {
101 - foreach ( $this->pre_fields as $field ) {
102 - if ( ! empty( $field['id'] ) ) {
103 - $this->options[$field['id']] = ( isset( $this->options[$field['id']] ) ) ? $this->options[$field['id']] : $this->get_default( $field );
104 - }
105 - }
106 - }
128 + foreach ( $sections as $key => $section ) {
129 + if ( ! empty( $section['parent'] ) ) {
130 + $parents[ $section['parent'] ][] = $section;
131 + unset( $sections[ $key ] );
132 + }
133 + }
107 134
108 - if ( $this->args['save_defaults'] && empty( $this->args['show_in_customizer'] ) && empty( $tmp_options ) ) {
135 + foreach ( $sections as $key => $section ) {
136 + if ( ! empty( $section['id'] ) && ! empty( $parents[ $section['id'] ] ) ) {
137 + $section['subs'] = $parents[ $section['id'] ];
138 + }
139 + $result[] = $section;
140 + }
109 141
110 - if ( $this->args['database'] === 'theme_mod' ) {
111 - set_theme_mod( $this->unique, $this->options );
112 - } else {
113 - update_option( $this->unique, $this->options );
114 - }
142 + return $result;
143 + }
115 144
116 - }
145 + public function add_customize_options( $wp_customize ) {
146 + if ( ! class_exists( 'WP_Customize_Panel_ADMINIFY' ) ) {
147 + ADMINIFY::include_plugin_file( 'functions/customize.php' );
148 + }
117 149
118 - }
150 + if ( ! empty( $this->sections ) ) {
151 + $sections = $this->pre_tabs( $this->sections );
119 152
120 - public function pre_sections_customize( $sections ) {
153 + foreach ( $sections as $section ) {
154 + if ( ! empty( $section['subs'] ) ) {
155 + $panel_id = ( isset( $section['id'] ) ) ? $section['id'] : $this->unique . '-panel-' . $this->priority;
121 156
122 - $result = array();
123 - $parents = array();
157 + $wp_customize->add_panel(
158 + new WP_Customize_Panel_ADMINIFY(
159 + $wp_customize,
160 + $panel_id,
161 + [
162 + 'title' => ( isset( $section['title'] ) ) ? $section['title'] : null,
163 + 'description' => ( isset( $section['description'] ) ) ? $section['description'] : null,
164 + 'priority' => ( isset( $section['priority'] ) ) ? $section['priority'] : null,
165 + ]
166 + )
167 + );
124 168
125 - foreach ( $sections as $key => $section ) {
126 - if ( ! empty( $section['parent'] ) ) {
127 - $parents[$section['parent']][] = $section;
128 - unset( $sections[$key] );
129 - }
130 - }
169 + $this->priority++;
131 170
132 - foreach ( $sections as $key => $section ) {
133 - if ( ! empty( $section['id'] ) && ! empty( $parents[$section['id']] ) ) {
134 - $section['subs'] = $parents[$section['id']];
135 - }
136 - $result[] = $section;
137 - }
171 + foreach ( $section['subs'] as $sub_section ) {
172 + $section_id = ( isset( $sub_section['id'] ) ) ? $sub_section['id'] : $this->unique . '-section-' . $this->priority;
138 173
139 - return $result;
174 + $this->add_section( $wp_customize, $section_id, $sub_section, $panel_id );
140 175
141 - }
176 + $this->priority++;
177 + }
178 + } else {
179 + $section_id = ( isset( $section['id'] ) ) ? $section['id'] : $this->unique . '-section-' . $this->priority;
142 180
143 - public function add_customize_options( $wp_customize ) {
181 + $this->add_section( $wp_customize, $section_id, $section, false );
144 182
145 - if ( ! class_exists( 'PXLBSAdminify_Customize_Panel' ) ) {
146 - ADMINIFY::include_plugin_file( 'functions/customize.php' );
147 - }
183 + $this->priority++;
184 + }
185 + }
186 + }
187 + }
148 188
149 - foreach ( $this->pre_sections as $section ) {
189 + // add customize section
190 + public function add_section( $wp_customize, $section_id, $section_args, $panel_id ) {
191 + if ( ! empty( $section_args['assign'] ) ) {
192 + $section_id = $section_args['assign'];
193 + } else {
194 + $wp_customize->add_section(
195 + new WP_Customize_Section_ADMINIFY(
196 + $wp_customize,
197 + $section_id,
198 + [
199 + 'title' => ( isset( $section_args['title'] ) ) ? $section_args['title'] : '',
200 + 'description' => ( isset( $section_args['description'] ) ) ? $section_args['description'] : '',
201 + 'priority' => ( isset( $section_args['priority'] ) ) ? $section_args['priority'] : '',
202 + 'panel' => ( $panel_id ) ? $panel_id : '',
203 + ]
204 + )
205 + );
206 + }
150 207
151 - if ( ! empty( $section['subs'] ) ) {
208 + if ( ! empty( $section_args['fields'] ) ) {
209 + $field_key = 1;
152 210
153 - $panel_id = ( isset( $section['id'] ) ) ? $section['id'] : $this->unique .'-panel-'. $this->priority;
211 + foreach ( $section_args['fields'] as $field ) {
212 + if ( isset( $field['id'] ) ) {
213 + $field['default'] = $this->get_default( $field );
214 + }
154 215
155 - $wp_customize->add_panel( new PXLBSAdminify_Customize_Panel( $wp_customize, $panel_id, array(
156 - 'title' => ( isset( $section['title'] ) ) ? $section['title'] : null,
157 - 'description' => ( isset( $section['description'] ) ) ? $section['description'] : null,
158 - 'priority' => ( isset( $section['priority'] ) ) ? $section['priority'] : null,
159 - ) ) );
216 + $field_id = ( isset( $field['id'] ) ) ? $field['id'] : '_nonce-' . $section_id . '-' . $field_key;
217 + $setting_args = ( isset( $field['setting_args'] ) ) ? $field['setting_args'] : [];
218 + $control_args = ( isset( $field['control_args'] ) ) ? $field['control_args'] : [];
219 + $field_transport = ( isset( $field['transport'] ) ) ? $field['transport'] : $this->args['transport'];
220 + $field_sanitize = ( isset( $field['sanitize'] ) ) ? $field['sanitize'] : '';
221 + $field_validate = ( isset( $field['validate'] ) ) ? $field['validate'] : '';
222 + $field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
223 + $field_customize = ( ( isset( $field['selectors'] ) || isset( $field['selector'] ) ) && ! isset( $field['transport'] ) ) ? true : false;
224 + $has_selective = ( isset( $field['selective_refresh'] ) && isset( $wp_customize->selective_refresh ) ) ? true : false;
160 225
161 - $this->priority++;
226 + $setting_id = $this->unique . '[' . $field_id . ']';
227 + $transport = ( $has_selective || $field_customize ) ? 'postMessage' : $field_transport;
162 228
163 - foreach ( $section['subs'] as $sub_section ) {
229 + $wp_customize->add_setting(
230 + $setting_id,
231 + wp_parse_args(
232 + $setting_args,
233 + [
234 + 'default' => $field_default,
235 + 'type' => $this->args['database'],
236 + 'capability' => $this->args['capability'],
237 + 'transport' => $transport,
238 + 'sanitize_callback' => $field_sanitize,
239 + 'validate_callback' => $field_validate,
240 + ]
241 + )
242 + );
164 243
165 - $section_id = ( isset( $sub_section['id'] ) ) ? $sub_section['id'] : $this->unique .'-section-'. $this->priority;
244 + $wp_customize->add_control(
245 + new WP_Customize_Control_ADMINIFY(
246 + $wp_customize,
247 + $setting_id,
248 + wp_parse_args(
249 + $control_args,
250 + [
251 + 'unique' => $this->unique,
252 + 'field' => $field,
253 + 'section' => $section_id,
254 + 'settings' => $setting_id,
255 + ]
256 + )
257 + )
258 + );
166 259
167 - $this->add_section( $wp_customize, $section_id, $sub_section, $panel_id );
260 + if ( $has_selective ) {
261 + $wp_customize->selective_refresh->add_partial( $setting_id, $field['selective_refresh'] );
262 + }
168 263
169 - $this->priority++;
264 + $field_key++;
265 + }
266 + }
267 + }
170 268
171 - }
172 -
173 - } else {
174 -
175 - $section_id = ( isset( $section['id'] ) ) ? $section['id'] : $this->unique .'-section-'. $this->priority;
176 -
177 - $this->add_section( $wp_customize, $section_id, $section, false );
178 -
179 - $this->priority++;
180 -
181 - }
182 -
183 - }
184 -
185 - }
186 -
187 - // add customize section
188 - public function add_section( $wp_customize, $section_id, $section_args, $panel_id ) {
189 -
190 - if ( ! empty( $section_args['assign'] ) ) {
191 -
192 - $section_id = $section_args['assign'];
193 -
194 - } else {
195 -
196 - $wp_customize->add_section( new PXLBSAdminify_Customize_Section( $wp_customize, $section_id, array(
197 - 'title' => ( isset( $section_args['title'] ) ) ? $section_args['title'] : '',
198 - 'description' => ( isset( $section_args['description'] ) ) ? $section_args['description'] : '',
199 - 'priority' => ( isset( $section_args['priority'] ) ) ? $section_args['priority'] : '',
200 - 'panel' => ( $panel_id ) ? $panel_id : '',
201 - ) ) );
202 -
203 - }
204 -
205 - if ( ! empty( $section_args['fields'] ) ) {
206 -
207 - $field_key = 1;
208 -
209 - foreach ( $section_args['fields'] as $field ) {
210 -
211 - if ( isset( $field['id'] ) ) {
212 - $field['default'] = $this->get_default( $field );
213 - }
214 -
215 - $field_id = ( isset( $field['id'] ) ) ? $field['id'] : '_nonce-'. $section_id .'-'. $field_key;
216 - $setting_args = ( isset( $field['setting_args'] ) ) ? $field['setting_args'] : array();
217 - $control_args = ( isset( $field['control_args'] ) ) ? $field['control_args'] : array();
218 - $field_transport = ( isset( $field['transport'] ) ) ? $field['transport'] : $this->args['transport'];
219 - $field_sanitize = ( isset( $field['sanitize'] ) ) ? $field['sanitize'] : '';
220 - $field_validate = ( isset( $field['validate'] ) ) ? $field['validate'] : '';
221 - $field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
222 - $field_customize = ( ( isset( $field['selectors'] ) || isset( $field['selector'] ) ) && ! isset( $field['transport'] ) ) ? true : false;
223 - $has_selective = ( isset( $field['selective_refresh'] ) && isset( $wp_customize->selective_refresh ) ) ? true : false;
224 -
225 - $setting_id = $this->unique .'['. $field_id .']';
226 - $transport = ( $has_selective || $field_customize ) ? 'postMessage' : $field_transport;
227 -
228 - $wp_customize->add_setting( $setting_id,
229 - wp_parse_args( $setting_args, array(
230 - 'default' => $field_default,
231 - 'type' => $this->args['database'],
232 - 'capability' => $this->args['capability'],
233 - 'transport' => $transport,
234 - 'sanitize_callback' => $field_sanitize,
235 - 'validate_callback' => $field_validate
236 - ) )
237 - );
238 -
239 - $wp_customize->add_control( new PXLBSAdminify_Customize_Control( $wp_customize, $setting_id,
240 - wp_parse_args( $control_args, array(
241 - 'unique' => $this->unique,
242 - 'field' => $field,
243 - 'section' => $section_id,
244 - 'settings' => $setting_id
245 - ) )
246 - ) );
247 -
248 - if ( $has_selective ) {
249 - $wp_customize->selective_refresh->add_partial( $setting_id, $field['selective_refresh'] );
250 - }
251 -
252 - $field_key++;
253 - }
254 -
255 - }
256 -
257 -
258 - }
259 -
260 - }
269 + }
261 270 }