PluginProbe
LoftLoader / trunk
LoftLoader vtrunk
trunk 1.0.0 1.0.1 1.0.2 2.0.0 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3 2.3.1 2.3.2 2.3.3 All 34 releases
loftloader / inc / class-loftloader-customize.php

class-loftloader-customize.php in LoftLoader trunk, at inc/class-loftloader-customize.php

381 lines 14.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! class_exists( 'LoftLoader_Customize' ) ) {
3 /**
4 * Load the Loftloader lite customize related functions
5 *
6 * @author Loft.Ocean
7 * @since 2.0.0
8 */
9 class LoftLoader_Customize {
10 public function __construct() {
11 $this->load_default_settings();
12 if ( loftloader_is_customize() ) {
13 $this->load_customize_controls();
14 add_action( 'customize_controls_init', array( $this, 'remove_sections' ), 1000 );
15 add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_scripts' ), 9999 );
16 add_action( 'customize_preview_init', array( $this, 'preview_scripts' ) );
17 }
18 }
19
20 private function load_default_settings() {
21 require_once LOFTLOADER_ROOT . 'inc/configs/default-settings.php';
22 }
23
24 public function load_customize_controls() {
25 $config_dir = LOFTLOADER_ROOT . 'inc/configs/';
26 require_once $config_dir . 'customize-main.php';
27 require_once $config_dir . 'customize-range.php';
28 require_once $config_dir . 'customize-background.php';
29 require_once $config_dir . 'customize-loader.php';
30 require_once $config_dir . 'customize-promo.php';
31 require_once $config_dir . 'customize-more.php';
32 require_once $config_dir . 'customize-advanced.php';
33 }
34
35 public function remove_sections() {
36 global $wp_customize;
37 foreach( $wp_customize->containers() as $id => $container ) {
38 if ( $container instanceof WP_Customize_Panel ) {
39 ( strpos( $id, 'loftloader_' ) === false ) ? $wp_customize->remove_panel( $id ) : '';
40 } else if ( $container instanceof WP_Customize_Section){
41 ( strpos( $id, 'loftloader_' ) === false ) ? $wp_customize->remove_section( $id ) : '';
42 }
43 }
44 }
45
46 public function customize_scripts() {
47 global $wp_scripts, $wp_styles;
48 $js_url = LOFTLOADER_URI . 'assets/js/customize.min.js';
49 $js_dep = array('jquery', 'wp-color-picker', 'jquery-ui-slider', 'customize-controls', 'media-editor' );
50 $ui_css = LOFTLOADER_URI . 'assets/css/jquery-ui.css';
51 $loader_css = LOFTLOADER_URI . 'assets/css/loftloader-settings.min.css';
52
53 wp_register_script( 'loftloader-lite-customize', $js_url, $js_dep, LOFTLOADER_ASSET_VERSION );
54 wp_localize_script( 'loftloader-lite-customize', 'loftloader_lite_i18n', array( 'name' => esc_html__( 'LoftLoader Lite', 'loftloader' ) ) ); // Change the site title in string "You are customizing ..."
55 wp_enqueue_script( 'loftloader-lite-customize' );
56
57 wp_enqueue_style( 'loftloader-lite-ui', $ui_css, array(), LOFTLOADER_ASSET_VERSION );
58 wp_enqueue_style( 'loftloader-lite-customize', $loader_css, array(), LOFTLOADER_ASSET_VERSION );
59
60 foreach ( $wp_scripts->registered as $h => $o ) {
61 if ( strpos( $o->src, 'wp-content/themes' ) !== false ) {
62 wp_dequeue_script( $h );
63 }
64 if ( strpos( $o->src, 'wp-content/plugins/disable-blog/' ) !== false ) {
65 wp_dequeue_script( $h );
66 }
67 };
68 foreach ( $wp_styles->registered as $h => $o ) {
69 if ( strpos($o->src, 'wp-content/themes') !== false ) {
70 wp_dequeue_style( $h );
71 }
72 };
73 }
74
75 public function preview_scripts() {
76 $js_url = LOFTLOADER_URI . 'assets/js/preview.min.js';
77 wp_register_script( 'loftloader-lite-preview', $js_url, array( 'jquery', 'customize-preview' ), LOFTLOADER_ASSET_VERSION, true );
78 wp_localize_script( 'loftloader-lite-preview', 'loftloader_lite', array( 'preview' => 'on' ) );
79 wp_enqueue_script( 'loftloader-lite-preview' );
80 }
81 }
82
83 new LoftLoader_Customize();
84 }
85
86 if ( class_exists( 'WP_Customize_Setting' ) ) {
87 /**
88 * LoftLoader related customization api classes
89 *
90 * @since 2.0.0
91 */
92
93 // LoftLoader base section class, changed the json function to modify the customize action text
94 class LoftLoader_Customize_Section extends WP_Customize_Section {
95 public function json() {
96 $array = parent::json();
97 $array['customizeAction'] = esc_html__( 'Setting', 'loftloader' );
98 return $array;
99 }
100 /**
101 * render function for LoftLoader Switch section
102 */
103 protected function render() {
104 if ( 'loftloader_switch' === $this->type ) :
105 $switch = $this->manager->get_setting('loftloader_main_switch')->value();
106 $classes = 'accordion-section control-section control-section-' . $this->type; ?>
107
108 <li
109 id="accordion-section-<?php echo esc_attr( $this->id ); ?>"
110 class="accordion-section control-section control-section-<?php echo esc_attr( $this->type ); ?>"
111 >
112 <h3 class="accordion-section-title" tabindex="0">
113 <?php echo esc_html( $this->title ); ?>
114 <span class="screen-reader-text"><?php esc_html_e( 'Press return or enter to open this section', 'loftloader' ); ?></span>
115 <input type="checkbox" name="loftloader-main-switch" value="on" <?php checked( $switch, 'on' ); ?> />
116 </h3>
117 <ul class="accordion-section-content">
118 <li class="customize-section-description-container">
119 <div class="customize-section-title">
120 <button class="customize-section-back" tabindex="-1">
121 <span class="screen-reader-text"><?php esc_html_e( 'Back', 'loftloader' ); ?></span>
122 </button>
123 <h3>
124 <span class="customize-action"><?php esc_html_e( 'Setting', 'loftloader' ); ?></span>
125 <?php echo wp_kses_post( $this->title ); ?>
126 </h3>
127 </div> <?php
128 if ( ! empty( $this->description ) ) : ?>
129 <div class="description customize-section-description"><?php echo wp_kses_post( $this->description ); ?></div> <?php
130 endif; ?>
131 </li>
132 </ul>
133 </li> <?php
134 else :
135 parent::render();
136 endif;
137 }
138 }
139
140 // LoftLoader base customize control class: add class properties as displaying dependency.
141 class LoftLoader_Customize_Control extends WP_Customize_Control {
142 public $filter = false;
143 public $text = '';
144 public $parent_setting_id = '';
145 public $show_filter = array();
146 public $img = '';
147 public $href = '';
148 public $note_below = '';
149 public function active_callback() {
150 if ( $this->filter && ( $this->manager->get_setting($this->parent_setting_id ) instanceof WP_Customize_Setting ) && ! empty( $this->show_filter ) ) {
151 $parent_setting_value = $this->manager->get_setting( $this->parent_setting_id )->value();
152 return in_array( $parent_setting_value, $this->show_filter ) ? true : false;
153 }
154 return true;
155 }
156 public function render_content() {
157 switch ( $this->type ) {
158 case 'loftloader-ad':
159 if ( ! empty( $this->label ) ) : ?>
160 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <?php
161 endif;
162 if ( ! empty( $this->img ) ) : ?>
163 <a href="<?php echo esc_url( $this->href ); ?>" target="_blank">
164 <img src="<?php echo esc_url( $this->img ); ?>" >
165 </a> <?php
166 endif; ?>
167 <div class="customize-control-notifications-container"></div> <?php
168 break;
169 case 'loftloader-any-page':
170 if ( ! empty( $this->label ) ) : ?>
171 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <?php
172 endif;
173 if ( ! empty( $this->description ) ) : ?>
174 <span class="description customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span> <?php
175 endif; ?>
176 <input
177 type="button"
178 <?php $this->link(); ?>
179 class="button button-primary loftloader-any-page-generate"
180 value="<?php esc_attr_e( 'Generate', 'loftloader' ); ?>"
181 /><br/><br/>
182 <textarea class="loftloader-any-page-shortcode" cols="30" rows="4"></textarea>
183 <div class="customize-control-notifications-container"></div> <?php
184 break;
185 case 'check': ?>
186 <label> <?php
187 if ( ! empty( $this->label ) ) : ?>
188 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <?php
189 endif; ?>
190 <input class="loftlader-checkbox" type="checkbox" value="on" name="<?php echo esc_attr( $this->id ); ?>" <?php checked( 'on', $this->value() ); ?> />
191 <input style="display:none;" type="checkbox" value="on" <?php $this->link(); ?> <?php checked( 'on', $this->value() ); ?> />
192 </label> <?php
193 if ( ! empty( $this->description ) ) : ?>
194 <span class="description customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span> <?php
195 endif;
196 break;
197 default:
198 parent::render_content();
199 if ( ! empty( $this->text ) ) {
200 echo esc_html( $this->text ) . '<br/>';
201 }
202 if ( ! empty( $this->note_below ) ) : ?>
203 <span class="description"><?php echo esc_html( $this->note_below ); ?></span><?php
204 endif;
205 }
206 }
207 }
208 // Modify the color control class to add the display dependency logic.
209 class LoftLoader_Customize_Color_Control extends WP_Customize_Color_Control {
210 public $filter = false;
211 public $parent_setting_id = '';
212 public $show_filter = array();
213 public function active_callback() {
214 if ( $this->filter && ( $this->manager->get_setting( $this->parent_setting_id ) instanceof WP_Customize_Setting ) && ! empty( $this->show_filter ) ) {
215 $parent_setting_value = $this->manager->get_setting( $this->parent_setting_id )->value();
216 return in_array( $parent_setting_value, $this->show_filter ) ? true : false;
217 }
218 return true;
219 }
220 }
221 // Modify the image control class to add the display dependency logic.
222 class LoftLoader_Customize_Image_Control extends WP_Customize_Image_Control {
223 public $filter = false;
224 public $parent_setting_id = '';
225 public $show_filter = array();
226 public function active_callback() {
227 if ( $this->filter && ( $this->manager->get_setting($this->parent_setting_id ) instanceof WP_Customize_Setting ) && ! empty( $this->show_filter ) ) {
228 $parent_setting_value = $this->manager->get_setting( $this->parent_setting_id )->value();
229 return in_array( $parent_setting_value, $this->show_filter ) ? true : false;
230 }
231 return true;
232 }
233 }
234 // Add new slider control class with jqueryui slider function
235 class LoftLoader_Customize_Slider_Control extends LoftLoader_Customize_Control {
236 public $input_class = '';
237 public $after_text = '%';
238 public function render_content() {
239 if ( empty( $this->input_attrs ) ) {
240 return;
241 } ?>
242
243 <label class="amount opacity"> <?php
244 if ( ! empty( $this->label ) ) : ?>
245 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <?php
246 endif; ?>
247 <span class="<?php echo esc_attr( $this->input_class ); ?>">
248 <input readonly="readonly" type="text" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>" >
249 <?php echo wp_kses_post( $this->after_text ); ?>
250 </span>
251 </label>
252 <div
253 class="ui-slider loader-ui-slider"
254 data-value="<?php echo esc_attr( $this->manager->get_setting($this->id)->value() ); ?>"
255 <?php $this->input_attrs(); ?>
256 >
257 </div>
258 <div class="customize-control-notifications-container"></div> <?php
259 }
260 }
261 // Add new radio type control class for loader animation choices.
262 class LoftLoader_Customize_Animation_Types_Control extends WP_Customize_Control {
263 public function render_content() {
264 if ( empty( $this->choices ) )
265 return;
266
267 if ( ! empty( $this->label ) ) : ?>
268 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
269 <?php endif; ?>
270 <button class="customize-more-toggle" aria-expanded="false">
271 <span class="screen-reader-text"><?php esc_html_e('More info', 'loftloader'); ?></span>
272 </button> <?php
273 if ( ! empty( $this->description ) ) : ?>
274 <span class="description customize-control-description" style="display: none;"><?php echo wp_kses_post( $this->description ); ?></span>
275 <?php endif; ?>
276
277 <div id="loftloader_option_animation">
278 <?php
279 $name = '_customize-radio-' . $this->id;
280 foreach ( $this->choices as $value => $attrs ) :
281 $attr = '';
282 if ( ! empty( $attrs['attr'] ) ) {
283 foreach ( (array)$attrs['attr'] as $attr_name => $attr_value ) {
284 $attr .= ' ' . $attr_name . '="' . $attr_value . '"';
285 }
286 }
287 $item_id = sanitize_title( $this->id . '-' . $value );
288 ?>
289 <label for="<?php echo esc_attr( $item_id ); ?>" title="<?php echo esc_attr($attrs['label']); ?>">
290 <input
291 id="<?php echo esc_attr( $item_id ); ?>"
292 class="loftloader-radiobtn <?php echo esc_attr( $value ); ?>"
293 type="radio"
294 value="<?php echo esc_attr( $value ); ?>"
295 name="<?php echo esc_attr( $name ); ?>"
296 <?php $this->link(); ?>
297 <?php checked( $this->value(), $value ); ?>
298 <?php echo wp_kses_post( $attr ); ?>
299 />
300 <span></span>
301 </label>
302 <?php endforeach; ?>
303 </div>
304 <?php
305 }
306 }
307 // Add new number type control class with text after the element.
308 class LoftLoader_Customize_Number_Text_Control extends LoftLoader_Customize_Control {
309 public $after_text = '';
310 public $input_class = '';
311 public $input_wrap_class = '';
312 public function render_content() { ?>
313 <label>
314 <?php if ( ! empty( $this->label ) ) : ?>
315 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
316 <?php endif;
317 if ( ! empty( $this->description ) ) : ?>
318 <span class="description customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span>
319 <?php endif; ?>
320 <span class="<?php echo esc_attr($this->input_wrap_class); ?>">
321 <input
322 class="<?php echo esc_attr( $this->input_class ); ?>"
323 type="<?php echo esc_attr( $this->type ); ?>"
324 <?php $this->input_attrs(); ?>
325 value="<?php echo esc_attr( $this->value() ); ?>"
326 <?php $this->link(); ?>
327 />
328 <?php echo esc_attr( $this->after_text ); ?>
329 </span>
330 </label>
331 <?php
332 }
333 }
334
335 if ( ! function_exists( 'loftloader_sanitize_checkbox' ) ) {
336 /**
337 * Check the switch checkbox value
338 *
339 * @param string the value from user
340 * @return mix if set return string 'on', otherwise return false
341 */
342 function loftloader_sanitize_checkbox( $input ) {
343 return empty( $input ) ? 'off' : 'on';
344 }
345 }
346
347 if ( ! function_exists( 'loftloader_sanitize_choice' ) ) {
348 /**
349 * Check the value is one of the choices from customize control
350 *
351 * @param string the value from user
352 * @param object customize setting object
353 * @return string the value from user or the default setting value
354 */
355
356 function loftloader_sanitize_choice( $input, $setting ) {
357 $choices = $setting->manager->get_control( $setting->id )->choices;
358 $choices = array_keys( $choices );
359 return in_array( $input, $choices ) ? $input : $setting->default;
360 }
361 }
362
363 if ( ! function_exists( 'loftloader_sanitize_number' ) ) {
364 /**
365 * Check the value is float with 1 decimal
366 *
367 * @param string the value from user
368 * @param object customize setting object
369 * @return string the value from user or the default setting value
370 */
371
372 function loftloader_sanitize_number( $value) {
373 if ( ! empty( $value ) ) {
374 $value = floatval( $value );
375 return number_format( $value, 1, '.', '' );
376 }
377 return 0;
378 }
379 }
380 }
381