PluginProbe
Customify / 2.9.0
Customify v2.9.0
2.10.9 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.7.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.0.1 1.6.5 1.7.0 1.7.1 All 77 releases
customify / includes / extras.php

extras.php in Customify 2.9.0, at includes/extras.php

474 lines 14.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Extra functionality.
4 */
5
6 if ( ! function_exists('add_customify_base_options') ) {
7 /**
8 * This filter is used to change the Customizer Options
9 * You can also copy this function inside your functions.php
10 * file but DO NOT FORGET TO CHANGE ITS NAME
11 *
12 * @param $config array This holds required keys for the plugin config like 'opt-name', 'panels', 'settings'
13 * @return $config
14 */
15 function add_customify_base_options( $config ) {
16
17 $config['opt-name'] = 'customify_defaults';
18
19 $config['sections'] = array(
20 /**
21 * Presets - This section will handle other options
22 */
23 'presets_section' => array(
24 'title' => esc_html__( 'Style Presets', 'customify' ),
25 'options' => array(
26 'theme_style' => array(
27 'type' => 'preset',
28 'label' => esc_html__( 'Select a style:', 'customify' ),
29 'desc' => esc_html__( 'Conveniently change the design of your site with built-in style presets. Easy as pie.', 'customify' ),
30 'default' => 'royal',
31 'choices_type' => 'awesome',
32 'choices' => array(
33 'royal' => array(
34 'label' => esc_html__( 'Royal', 'customify' ),
35 'preview' => array(
36 'color-text' => '#ffffff',
37 'background-card' => '#615375',
38 'background-label' => '#46414c',
39 'font-main' => 'Abril Fatface',
40 'font-alt' => 'PT Serif',
41 ),
42 'options' => array(
43 'links_color' => '#8eb2c5',
44 'headings_color' => '#725c92',
45 'body_color' => '#6f8089',
46 'page_background' => '#615375',
47 'headings_font' => 'Abril Fatface',
48 'body_font' => 'PT Serif',
49 )
50 ),
51 'lovely' => array(
52 'label' => esc_html__( 'Lovely', 'customify' ),
53 'preview' => array(
54 'color-text' => '#ffffff',
55 'background-card' => '#d15c57',
56 'background-label' => '#5c374b',
57 'font-main' => 'Playfair Display',
58 'font-alt' => 'Playfair Display',
59 ),
60 'options' => array(
61 'links_color' => '#cc3747',
62 'headings_color' => '#d15c57',
63 'body_color' => '#5c374b',
64 'page_background' => '#d15c57',
65 'headings_font' => 'Playfair Display',
66 'body_font' => 'Playfair Display',
67 )
68 ),
69 'queen' => array(
70 'label' => esc_html__( 'Queen', 'customify' ),
71 'preview' => array(
72 'color-text' => '#fbedec',
73 'background-card' => '#773347',
74 'background-label' => '#41212a',
75 'font-main' => 'Cinzel Decorative',
76 'font-alt' => 'Gentium Basic',
77 ),
78 'options' => array(
79 'links_color' => '#cd8085',
80 'headings_color' => '#54323c',
81 'body_color' => '#cd8085',
82 'page_background' => '#fff',
83 'headings_font' => 'Cinzel Decorative',
84 'body_font' => 'Gentium Basic',
85 )
86 ),
87 'carrot' => array(
88 'label' => esc_html__( 'Carrot', 'customify' ),
89 'preview' => array(
90 'color-text' => '#ffffff',
91 'background-card' => '#df421d',
92 'background-label' => '#85210a',
93 'font-main' => 'Oswald',
94 'font-alt' => 'PT Sans Narrow',
95 ),
96 'options' => array(
97 'links_color' => '#df421d',
98 'headings_color' => '#df421d',
99 'body_color' => '#7e7e7e',
100 'page_background' => '#fff',
101 'headings_font' => 'Oswald',
102 'body_font' => 'PT Sans Narrow',
103 )
104 ),
105
106
107
108 'adler' => array(
109 'label' => esc_html__( 'Adler', 'customify' ),
110 'preview' => array(
111 'color-text' => '#fff',
112 'background-card' => '#0e364f',
113 'background-label' => '#000000',
114 'font-main' => 'Permanent Marker',
115 'font-alt' => 'Droid Sans Mono',
116 ),
117 'options' => array(
118 'links_color' => '#68f3c8',
119 'headings_color' => '#0e364f',
120 'body_color' => '#45525a',
121 'page_background' => '#ffffff',
122 'headings_font' => 'Permanent Marker',
123 'body_font' => 'Droid Sans Mono'
124 )
125 ),
126 'velvet' => array(
127 'label' => esc_html__( 'Velvet', 'customify' ),
128 'preview' => array(
129 'color-text' => '#ffffff',
130 'background-card' => '#282828',
131 'background-label' => '#000000',
132 'font-main' => 'Pinyon Script',
133 'font-alt' => 'Josefin Sans',
134 ),
135 'options' => array(
136 'links_color' => '#000000',
137 'headings_color' => '#000000',
138 'body_color' => '#000000',
139 'page_background' => '#000000',
140 'headings_font' => 'Pinyon Script',
141 'body_font' => 'Josefin Sans',
142 )
143 ),
144
145 )
146 ),
147 )
148 ),
149
150 /**
151 * COLORS - This section will handle different elements colors (eg. links, headings)
152 */
153 'colors_section' => array(
154 'title' => esc_html__( 'Colors', 'customify' ),
155 'options' => array(
156 'links_color' => array(
157 'type' => 'color',
158 'label' => esc_html__( 'Links Color', 'customify' ),
159 'live' => true,
160 'default' => '#6c6e70',
161 'css' => array(
162 array(
163 'property' => 'color',
164 'selector' => 'a, .entry-meta a',
165 ),
166 )
167 ),
168 'headings_color' => array(
169 'type' => 'color',
170 'label' => esc_html__( 'Headings Color', 'customify' ),
171 'live' => true,
172 'default' => '#0aa0d9',
173 'css' => array(
174 array(
175 'property' => 'color',
176 'selector' => '.site-title a, h1, h2, h3, h4, h5, h6,
177 h1 a, h2 a, h3 a, h4 a, h5 a, h6 a,
178 .widget-title,
179 a:hover, .entry-meta a:hover'
180 )
181 )
182 ),
183 'body_color' => array(
184 'type' => 'color',
185 'label' => esc_html__( 'Body Color', 'customify' ),
186 'live' => true,
187 'default' => '#2d3033',
188 'css' => array(
189 array(
190 'selector' => 'body',
191 'property' => 'color'
192 )
193 )
194 )
195 )
196 ),
197
198 /**
199 * FONTS - This section will handle different elements fonts (eg. headings, body)
200 */
201 'typography_section' => array(
202 'title' => esc_html__( 'Fonts', 'customify' ),
203 'options' => array(
204 'headings_font' => array(
205 'type' => 'font',
206 'label' => esc_html__( 'Headings', 'customify' ),
207 'default' => 'Playfair Display',
208 'selector' => '.site-title a, h1, h2, h3, h4, h5, h6,
209 h1 a, h2 a, h3 a, h4 a, h5 a, h6 a,
210 .widget-title',
211 'font_weight' => true,
212 'recommended' => array(
213 'Playfair Display',
214 'Oswald',
215 'Lato',
216 'Open Sans',
217 'Exo',
218 'PT Sans',
219 'Ubuntu',
220 'Vollkorn',
221 'Lora',
222 'Arvo',
223 'Josefin Slab',
224 'Crete Round',
225 'Kreon',
226 'Bubblegum Sans',
227 'The Girl Next Door',
228 'Pacifico',
229 'Handlee',
230 'Satify',
231 'Pompiere'
232 )
233 ),
234 'body_font' => array(
235 'type' => 'font',
236 'label' => esc_html__( 'Body Text', 'customify' ),
237 'default' => 'Lato',
238 'selector' => 'html body',
239 'recommended' => array(
240 'Lato',
241 'Open Sans',
242 'PT Sans',
243 'Cabin',
244 'Gentium Book Basic',
245 'PT Serif',
246 'Droid Serif'
247 )
248 )
249 )
250 ),
251
252 /**
253 * BACKGROUNDS - This section will handle different elements colors (eg. links, headings)
254 */
255 'backgrounds_section' => array(
256 'title' => esc_html__( 'Backgrounds', 'customify' ),
257 'options' => array(
258 'page_background' => array(
259 'type' => 'color',
260 'label' => esc_html__( 'Page Background', 'customify' ),
261 'live' => true,
262 'default' => '#ffffff',
263 'css' => array(
264 array(
265 'property' => 'background',
266 'selector' => 'body, .site',
267 )
268 )
269 ),
270 )
271 ),
272 /**
273 * LAYOUTS - This section will handle different elements colors (eg. links, headings)
274 */
275 'layout_options' => array(
276 'title' => esc_html__( 'Layout', 'customify' ),
277 'options' => array(
278 'site_title_size' => array(
279 'type' => 'range',
280 'label' => esc_html__( 'Site Title Size', 'customify' ),
281 'live' => true,
282 'input_attrs' => array(
283 'min' => 24,
284 'max' => 100,
285 'step' => 1,
286 'data-preview' => true
287 ),
288 'default' => 24,
289 'css' => array(
290 array(
291 'property' => 'font-size',
292 'selector' => '.site-title',
293 'media' => 'screen and (min-width: 1000px)',
294 'unit' => 'px',
295 )
296 )
297 ),
298 'page_content_spacing' => array(
299 'type' => 'range',
300 'label' => 'Page Content Spacing',
301 'live' => true,
302 'input_attrs' => array(
303 'min' => 0,
304 'max' => 100,
305 'step' => 1,
306 ),
307 'default' => 18,
308 'css' => array(
309 array(
310 'property' => 'padding',
311 'selector' => '.site-content',
312 'media' => 'screen and (min-width: 1000px)',
313 'unit' => 'px',
314 )
315 )
316 )
317 )
318 )
319 );
320
321 return $config;
322 }
323 }
324 add_filter( 'customify_filter_fields', 'add_customify_base_options', 5, 1 );
325
326 add_action( 'after_switch_theme', function( $old_theme_name, $old_theme ) {
327 $current_theme = wp_get_theme();
328 // If the current theme is a child theme, show a notice.
329 if ( $current_theme->exists()
330 && $old_theme->exists()
331 && $current_theme->get_template() === $old_theme->get_stylesheet() ) {
332 add_action( 'admin_notices', 'customify_child_theme_migrate_theme_mods_notice' );
333 }
334 }, 100, 2 );
335
336 /**
337 * Provide a notice allowing for theme mods migration from the parent theme to the current child theme.
338 */
339 function customify_child_theme_migrate_theme_mods_notice() {
340 global $pagenow;
341
342 // We only show the notice on the themes dashboard, and if we are allowed to.
343 if ( 'themes.php' !== $pagenow
344 || ! is_child_theme()
345 || true !== apply_filters( 'customify_allow_child_theme_mod_migrate_notice', true )
346 || ! current_user_can( 'manage_options' ) ) {
347
348 return;
349 }
350
351 $parent_theme = wp_get_theme( get_template() );
352 if ( ! $parent_theme->exists() ) {
353 return;
354 }
355
356 ob_start(); ?>
357 <div class="customify-notice__container updated notice fade is-dismissible">
358 <h3><?php echo sprintf( __( 'You have activated a child theme for "%s". Good for you!', 'customify' ), $parent_theme->get('Name') ); ?></h3>
359 <p>
360 <?php echo wp_kses_post( __( 'If you have already <strong>set up things in the Customizer,</strong> you may want to <strong>keep those customizations</strong> so you don\'t start over.', 'customify' ) ); ?>
361 </p>
362 <p>
363 <?php echo wp_kses_post( __( 'So, the question is simple: <strong>would you like to migrate all theme-specific options (theme mods) from the parent theme to the child one?</strong>', 'customify' ) ); ?>
364 </p>
365 <p>
366 <?php echo wp_kses_post( __( 'All parent theme customizations will remain in place, while those of the active child theme will be overwritten, if any.', 'customify' ) ); ?>
367 </p>
368 <form class="customify-notice-form" method="post">
369 <noscript><input type="hidden" name="customify-notice-no-js" value="1"/></noscript>
370
371 <p>
372 <button class="customify-notice-button button button-primary js-handle-customify">
373 <span class="customify-notice-button__text"><?php esc_html_e( 'Yes, migrate customizations', 'customify' ); ?></span>
374 </button>
375 <button type="submit" class="customify-dismiss-button button button-secondary js-dismiss-customify"><?php esc_html_e( 'No, thank you', 'customify' ); ?></button>
376 &nbsp;<span class="message js-plugin-message" style="font-style:italic"></span>
377 </p>
378
379 <?php wp_nonce_field( 'customify_migrate_customizations_from_parent_to_child_theme', 'nonce-customify_theme_mods_migrate' ); ?>
380 </form>
381 </div>
382 <script>
383 (function ($) {
384 $(function () {
385 let $noticeContainer = $('.customify-notice__container'),
386 $button = $noticeContainer.find('.js-handle-customify'),
387 $buttonText = $noticeContainer.find('.customify-notice-button__text'),
388 $dismissButton = $noticeContainer.find('.js-dismiss-customify'),
389 $statusMessage = $noticeContainer.find('.js-plugin-message')
390
391 $button.on('click', function (e) {
392 e.preventDefault();
393
394 $buttonText.html("<?php esc_html_e( 'Migrating customizations..' ,'customify'); ?>")
395 $button.attr('disabled', true)
396 $dismissButton.hide()
397
398 // Do an AJAX call to migrate the theme_mods.
399 $.ajax({
400 url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
401 type: 'post',
402 data: {
403 action: 'customify_migrate_customizations_from_parent_to_child_theme',
404 nonce_migrate: $noticeContainer.find('#nonce-customify_theme_mods_migrate').val()
405 }
406 })
407 .done(function(response) {
408 if (typeof response.success !== 'undefined' && response.success) {
409 $statusMessage.html("<?php esc_html_e( 'Successfully migrated the parent customizations! Enjoy crafting your site!', 'customify' ); ?>")
410 $buttonText.html("<?php esc_html_e( 'Finished migration', 'customify' ); ?>")
411 } else {
412 $statusMessage.html("<?php esc_html_e( 'Something went wrong and we couldn\'t migrate the customizations.' ,'customify'); ?>")
413 $buttonText.html("<?php esc_html_e( 'Migration error' ,'customify'); ?>")
414 }
415 })
416 .fail(function() {
417 $statusMessage.html("<?php esc_html_e( 'Something went wrong and we couldn\'t migrate the customizations.' ,'customify'); ?>")
418 $buttonText.html("<?php esc_html_e( 'Migration error' ,'customify'); ?>")
419 })
420 })
421
422 // Dismiss the notice.
423 $dismissButton.on('click', function (e) {
424 e.preventDefault();
425
426 $noticeContainer.slideUp();
427 })
428 })
429 })(jQuery)
430 </script>
431 <?php
432 echo ob_get_clean();
433 }
434
435 /**
436 * Process ajax call to migrate customizations from parent to current child theme.
437 */
438 function customify_migrate_customizations_from_parent_to_child_theme() {
439 // Check nonce.
440 check_ajax_referer( 'customify_migrate_customizations_from_parent_to_child_theme', 'nonce_migrate' );
441
442 $parent_theme = wp_get_theme( get_template() );
443 if ( ! $parent_theme->exists() ) {
444 wp_send_json_error();
445 }
446
447 // Migrate theme mods
448 $parent_theme_mods = get_option( "theme_mods_" . $parent_theme->get_stylesheet() );
449 // We need to exclude certain theme_mods since they are not needed by the child theme.
450 $excluded = [
451 'pixcare_license',
452 'pixcare_new_theme_version',
453 'pixcare_install_notice_dismissed',
454 ];
455 foreach ( $excluded as $exclude ) {
456 unset( $parent_theme_mods[ $exclude ] );
457 }
458 // Finally, write the new theme mods for the active child theme.
459 if ( ! update_option( "theme_mods_" . get_option( 'stylesheet' ), $parent_theme_mods ) ) {
460 wp_send_json_error( esc_html__( 'Could not update the child theme theme_mods.', 'customify' ) );
461 }
462
463 // Redirect if this is not an ajax request.
464 if ( isset( $_POST['pixcare-notice-no-js'] ) ) {
465
466 // Go back to where we came from.
467 wp_safe_redirect( wp_get_referer() );
468 exit();
469 }
470
471 wp_send_json_success();
472 }
473 add_action( 'wp_ajax_customify_migrate_customizations_from_parent_to_child_theme', 'customify_migrate_customizations_from_parent_to_child_theme' );
474