PluginProbe
LoftLoader / 2.1.10
LoftLoader v2.1.10
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 2.1.10, at inc/class-loftloader-customize.php

351 lines 13.7 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');
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 };
65 foreach ( $wp_styles->registered as $h => $o ) {
66 if ( strpos($o->src, 'wp-content/themes') !== false ) {
67 wp_dequeue_style( $h );
68 }
69 };
70 }
71
72 public function preview_scripts() {
73 $js_url = LOFTLOADER_URI . 'assets/js/preview.min.js';
74 wp_register_script( 'loftloader-lite-preview', $js_url, array( 'jquery', 'customize-preview' ), LOFTLOADER_ASSET_VERSION, true );
75 wp_localize_script( 'loftloader-lite-preview', 'loftloader_lite', array( 'preview' => 'on' ) );
76 wp_enqueue_script( 'loftloader-lite-preview' );
77 }
78 }
79
80 new LoftLoader_Customize();
81 }
82
83 if ( class_exists( 'WP_Customize_Setting' ) ) {
84 /**
85 * LoftLoader related customization api classes
86 *
87 * @since 2.0.0
88 */
89
90 // LoftLoader base section class, changed the json function to modify the customize action text
91 class LoftLoader_Customize_Section extends WP_Customize_Section {
92 public function json() {
93 $array = parent::json();
94 $array['customizeAction'] = esc_html__( 'Setting', 'loftloader' );
95 return $array;
96 }
97 /**
98 * render function for LoftLoader Switch section
99 */
100 protected function render() {
101 if ( 'loftloader_switch' === $this->type ) :
102 $switch = $this->manager->get_setting('loftloader_main_switch')->value();
103 $classes = 'accordion-section control-section control-section-' . $this->type; ?>
104
105 <li
106 id="accordion-section-<?php echo esc_attr( $this->id ); ?>"
107 class="accordion-section control-section control-section-<?php echo esc_attr( $this->type ); ?>"
108 >
109 <h3 class="accordion-section-title" tabindex="0">
110 <?php echo esc_html( $this->title ); ?>
111 <span class="screen-reader-text"><?php esc_html_e( 'Press return or enter to open this section', 'loftloader' ); ?></span>
112 <input type="checkbox" name="loftloader-main-switch" value="on" <?php checked( $switch, 'on' ); ?> />
113 </h3>
114 <ul class="accordion-section-content">
115 <li class="customize-section-description-container">
116 <div class="customize-section-title">
117 <button class="customize-section-back" tabindex="-1">
118 <span class="screen-reader-text"><?php esc_html_e( 'Back', 'loftloader' ); ?></span>
119 </button>
120 <h3>
121 <span class="customize-action"><?php esc_html_e( 'Setting', 'loftloader' ); ?></span>
122 <?php echo wp_kses_post( $this->title ); ?>
123 </h3>
124 </div> <?php
125 if ( ! empty( $this->description ) ) : ?>
126 <div class="description customize-section-description"><?php echo wp_kses_post( $this->description ); ?></div> <?php
127 endif; ?>
128 </li>
129 </ul>
130 </li> <?php
131 else :
132 parent::render();
133 endif;
134 }
135 }
136
137 // LoftLoader base customize control class: add class properties as displaying dependency.
138 class LoftLoader_Customize_Control extends WP_Customize_Control {
139 public $filter = false;
140 public $parent_setting_id = '';
141 public $show_filter = array();
142 public $img = '';
143 public $href = '';
144 public function active_callback() {
145 if ( $this->filter && ( $this->manager->get_setting($this->parent_setting_id ) instanceof WP_Customize_Setting ) && ! empty( $this->show_filter ) ) {
146 $parent_setting_value = $this->manager->get_setting( $this->parent_setting_id )->value();
147 return in_array( $parent_setting_value, $this->show_filter ) ? true : false;
148 }
149 return true;
150 }
151 public function render_content() {
152 switch ( $this->type ) {
153 case 'loftloader-ad':
154 if ( ! empty( $this->label ) ) : ?>
155 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <?php
156 endif;
157 if ( ! empty( $this->img ) ) : ?>
158 <a href="<?php echo esc_url( $this->href ); ?>" target="_blank">
159 <img src="<?php echo esc_url( $this->img ); ?>" >
160 </a> <?php
161 endif; ?>
162 <div class="customize-control-notifications-container"></div> <?php
163 break;
164 case 'loftloader-any-page':
165 if ( ! empty( $this->label ) ) : ?>
166 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <?php
167 endif;
168 if ( ! empty( $this->description ) ) : ?>
169 <span class="description customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span> <?php
170 endif; ?>
171 <input
172 type="button"
173 <?php $this->link(); ?>
174 class="button button-primary loftloader-any-page-generate"
175 value="<?php esc_attr_e( 'Generate', 'loftloader' ); ?>"
176 /><br/><br/>
177 <textarea class="loftloader-any-page-shortcode" cols="30" rows="4"></textarea>
178 <div class="customize-control-notifications-container"></div> <?php
179 break;
180 case 'check': ?>
181 <label> <?php
182 if ( ! empty( $this->label ) ) : ?>
183 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <?php
184 endif;
185 if ( ! empty( $this->description ) ) : ?>
186 <span class="description customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span> <?php
187 endif; ?>
188 <input class="loftlader-checkbox" type="checkbox" value="on" name="<?php echo esc_attr( $this->id ); ?>" <?php checked( 'on', $this->value() ); ?> />
189 <input style="display:none;" type="checkbox" value="on" <?php $this->link(); ?> <?php checked( 'on', $this->value() ); ?> />
190 </label> <?php break;
191 default:
192 parent::render_content();
193 }
194 }
195 }
196 // Modify the color control class to add the display dependency logic.
197 class LoftLoader_Customize_Color_Control extends WP_Customize_Color_Control {
198 public $filter = false;
199 public $parent_setting_id = '';
200 public $show_filter = array();
201 public function active_callback() {
202 if ( $this->filter && ( $this->manager->get_setting( $this->parent_setting_id ) instanceof WP_Customize_Setting ) && ! empty( $this->show_filter ) ) {
203 $parent_setting_value = $this->manager->get_setting( $this->parent_setting_id )->value();
204 return in_array( $parent_setting_value, $this->show_filter ) ? true : false;
205 }
206 return true;
207 }
208 }
209 // Modify the image control class to add the display dependency logic.
210 class LoftLoader_Customize_Image_Control extends WP_Customize_Image_Control {
211 public $filter = false;
212 public $parent_setting_id = '';
213 public $show_filter = array();
214 public function active_callback() {
215 if ( $this->filter && ( $this->manager->get_setting($this->parent_setting_id ) instanceof WP_Customize_Setting ) && ! empty( $this->show_filter ) ) {
216 $parent_setting_value = $this->manager->get_setting( $this->parent_setting_id )->value();
217 return in_array( $parent_setting_value, $this->show_filter ) ? true : false;
218 }
219 return true;
220 }
221 }
222 // Add new slider control class with jqueryui slider function
223 class LoftLoader_Customize_Slider_Control extends LoftLoader_Customize_Control {
224 public $input_class = '';
225 public $after_text = '%';
226 public function render_content() {
227 if ( empty( $this->input_attrs ) ) {
228 return;
229 } ?>
230
231 <label class="amount opacity"> <?php
232 if ( ! empty( $this->label ) ) : ?>
233 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <?php
234 endif; ?>
235 <span class="<?php echo esc_attr( $this->input_class ); ?>">
236 <input readonly="readonly" type="text" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>" >
237 <?php echo wp_kses_post( $this->after_text ); ?>
238 </span>
239 </label>
240 <div
241 class="ui-slider loader-ui-slider"
242 data-value="<?php echo esc_attr( $this->manager->get_setting($this->id)->value() ); ?>"
243 <?php $this->input_attrs(); ?>
244 >
245 </div>
246 <div class="customize-control-notifications-container"></div> <?php
247 }
248 }
249 // Add new radio type control class for loader animation choices.
250 class LoftLoader_Customize_Animation_Types_Control extends WP_Customize_Control {
251 public function render_content() {
252 if ( empty( $this->choices ) )
253 return;
254
255 if ( ! empty( $this->label ) ) : ?>
256 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
257 <?php endif; ?>
258 <button class="customize-more-toggle" aria-expanded="false">
259 <span class="screen-reader-text"><?php esc_html_e('More info', 'loftloader'); ?></span>
260 </button> <?php
261 if ( ! empty( $this->description ) ) : ?>
262 <span class="description customize-control-description" style="display: none;"><?php echo wp_kses_post( $this->description ); ?></span>
263 <?php endif; ?>
264
265 <div id="loftloader_option_animation">
266 <?php
267 $name = '_customize-radio-' . $this->id;
268 foreach ( $this->choices as $value => $attrs ) :
269 $attr = '';
270 if ( ! empty( $attrs['attr'] ) ) {
271 foreach ( (array)$attrs['attr'] as $attr_name => $attr_value ) {
272 $attr .= ' ' . $attr_name . '="' . $attr_value . '"';
273 }
274 }
275 $item_id = sanitize_title( $this->id . '-' . $value );
276 ?>
277 <label for="<?php echo esc_attr( $item_id ); ?>" title="<?php echo esc_attr($attrs['label']); ?>">
278 <input
279 id="<?php echo esc_attr( $item_id ); ?>"
280 class="loftloader-radiobtn <?php echo esc_attr( $value ); ?>"
281 type="radio"
282 value="<?php echo esc_attr( $value ); ?>"
283 name="<?php echo esc_attr( $name ); ?>"
284 <?php $this->link(); ?>
285 <?php checked( $this->value(), $value ); ?>
286 <?php echo wp_kses_post( $attr ); ?>
287 />
288 <span></span>
289 </label>
290 <?php endforeach; ?>
291 </div>
292 <?php
293 }
294 }
295 // Add new number type control class with text after the element.
296 class LoftLoader_Customize_Number_Text_Control extends LoftLoader_Customize_Control {
297 public $after_text = '';
298 public $input_class = '';
299 public $input_wrap_class = '';
300 public function render_content() { ?>
301 <label>
302 <?php if ( ! empty( $this->label ) ) : ?>
303 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
304 <?php endif;
305 if ( ! empty( $this->description ) ) : ?>
306 <span class="description customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span>
307 <?php endif; ?>
308 <span class="<?php echo esc_attr($this->input_wrap_class); ?>">
309 <input
310 class="<?php echo esc_attr( $this->input_class ); ?>"
311 type="<?php echo esc_attr( $this->type ); ?>"
312 <?php $this->input_attrs(); ?>
313 value="<?php echo esc_attr( $this->value() ); ?>"
314 <?php $this->link(); ?>
315 />
316 <?php echo esc_attr( $this->after_text ); ?>
317 </span>
318 </label>
319 <?php
320 }
321 }
322
323 if ( ! function_exists( 'loftloader_sanitize_checkbox' ) ) {
324 /**
325 * Check the switch checkbox value
326 *
327 * @param string the value from user
328 * @return mix if set return string 'on', otherwise return false
329 */
330 function loftloader_sanitize_checkbox( $input ) {
331 return empty( $input ) ? 'off' : 'on';
332 }
333 }
334
335 if ( ! function_exists( 'loftloader_sanitize_choice' ) ) {
336 /**
337 * Check the value is one of the choices from customize control
338 *
339 * @param string the value from user
340 * @param object customize setting object
341 * @return string the value from user or the default setting value
342 */
343
344 function loftloader_sanitize_choice( $input, $setting ) {
345 $choices = $setting->manager->get_control( $setting->id )->choices;
346 $choices = array_keys( $choices );
347 return in_array( $input, $choices ) ? $input : $setting->default;
348 }
349 }
350 }
351