Customify – A Theme Customizer Booster - Version 1.5.2

Version Description

  • Fixed Background field output
  • Fixed Font's preview in wp-editor
  • Added Reset Theme Mods tool
Download this release

Release Info

Developer euthelup
Plugin Icon Customify – A Theme Customizer Booster
Version 1.5.2
Comparing to
See all releases

Code changes from version 1.5.1 to 1.5.2

class-pixcustomify.php CHANGED
@@ -231,9 +231,12 @@ class PixCustomifyPlugin {
231
  /*
232
  * Jetpack Related
233
  */
 
234
  add_filter( 'default_option_jetpack_active_modules', array( $this, 'default_jetpack_active_modules' ), 10, 1 );
235
  add_filter( 'jetpack_get_available_modules', array( $this, 'jetpack_hide_blocked_modules' ), 10, 1 );
236
  add_filter( 'default_option_sharing-options', array( $this, 'default_jetpack_sharing_options' ), 10, 1 );
 
 
237
  }
238
 
239
  /**
@@ -275,6 +278,11 @@ class PixCustomifyPlugin {
275
  $this->localized['theme_fonts'] = $this->theme_fonts = Customify_Font_Selector::instance()->get_theme_fonts();
276
  }
277
 
 
 
 
 
 
278
  /**
279
  * Control the default modules that are activated in Jetpack.
280
  * Use the `customify_filter_jetpack_default_modules` to set your's.
@@ -456,18 +464,65 @@ class PixCustomifyPlugin {
456
  $screen = get_current_screen();
457
  if ( $screen->id == $this->plugin_screen_hook_suffix ) {
458
  wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'js/admin.js', $this->file ), array( 'jquery' ), $this->_version );
459
- wp_localize_script( $this->plugin_slug . '-admin-script', 'locals', array(
460
- 'ajax_url' => admin_url( 'admin-ajax.php' )
 
 
 
 
 
461
  ) );
462
  }
463
 
464
-
465
  wp_localize_script( $this->plugin_slug . '-customizer-scripts', 'WP_API_Settings', array(
466
  'root' => esc_url_raw( rest_url() ),
467
  'nonce' => wp_create_nonce( 'wp_rest' )
468
  ) );
469
  }
470
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
  /**
472
  * Public style generated by customizer
473
  */
@@ -482,6 +537,7 @@ class PixCustomifyPlugin {
482
  }
483
 
484
  if ( $option['type'] === 'custom_background' ) {
 
485
  $custom_css .= $this->process_custom_background_field_output( $option_id, $option );
486
  }
487
  }
@@ -929,7 +985,7 @@ class PixCustomifyPlugin {
929
  }
930
 
931
  protected function process_custom_background_field_output( $option_id, $options ) {
932
- $selector = '';
933
 
934
  if ( ! isset( $options['value'] ) ) {
935
  return false;
@@ -943,33 +999,33 @@ class PixCustomifyPlugin {
943
  } elseif ( is_array( $options['output'] ) ) {
944
  $selector = implode( ' ', $options['output'] );
945
  }
946
- ob_start();
947
 
948
- echo $selector . " {";
 
949
  if ( isset( $value['background-image'] ) && ! empty( $value['background-image'] ) ) {
950
- echo "background-image: url( " . $value['background-image'] . ");";
951
  } else {
952
- echo "background-image: none;";
953
  }
954
 
955
  if ( isset( $value['background-repeat'] ) && ! empty( $value['background-repeat'] ) ) {
956
- echo "background-repeat:" . $value['background-repeat'] . ";";
957
  }
958
 
959
  if ( isset( $value['background-position'] ) && ! empty( $value['background-position'] ) ) {
960
- echo "background-position:" . $value['background-position'] . ";";
961
  }
962
 
963
  if ( isset( $value['background-size'] ) && ! empty( $value['background-size'] ) ) {
964
- echo "background-size:" . $value['background-size'] . ";";
965
  }
966
 
967
  if ( isset( $value['background-attachment'] ) && ! empty( $value['background-attachment'] ) ) {
968
- echo "background-attachment:" . $value['background-attachment'] . ";";
969
  }
970
- echo "}\n";
971
 
972
- return ob_get_clean();
973
  }
974
 
975
  /**
231
  /*
232
  * Jetpack Related
233
  */
234
+ add_action( 'init', array( $this, 'set_jetpack_sharing_config') );
235
  add_filter( 'default_option_jetpack_active_modules', array( $this, 'default_jetpack_active_modules' ), 10, 1 );
236
  add_filter( 'jetpack_get_available_modules', array( $this, 'jetpack_hide_blocked_modules' ), 10, 1 );
237
  add_filter( 'default_option_sharing-options', array( $this, 'default_jetpack_sharing_options' ), 10, 1 );
238
+
239
+ add_action( 'rest_api_init', array( $this, 'add_rest_routes_api' ) );
240
  }
241
 
242
  /**
278
  $this->localized['theme_fonts'] = $this->theme_fonts = Customify_Font_Selector::instance()->get_theme_fonts();
279
  }
280
 
281
+ function set_jetpack_sharing_config() {
282
+ // Allow others to change the sharing config here
283
+ $this->jetpack_sharing_default_options = apply_filters ( 'customify_filter_jetpack_sharing_default_options', array() );
284
+ }
285
+
286
  /**
287
  * Control the default modules that are activated in Jetpack.
288
  * Use the `customify_filter_jetpack_default_modules` to set your's.
464
  $screen = get_current_screen();
465
  if ( $screen->id == $this->plugin_screen_hook_suffix ) {
466
  wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'js/admin.js', $this->file ), array( 'jquery' ), $this->_version );
467
+ wp_localize_script( $this->plugin_slug . '-admin-script', 'customify_settings', array(
468
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
469
+ 'wp_rest' => array(
470
+ 'root' => esc_url_raw( rest_url() ),
471
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
472
+ 'customify_settings_nonce' => wp_create_nonce( 'customify_settings_nonce' )
473
+ ),
474
  ) );
475
  }
476
 
 
477
  wp_localize_script( $this->plugin_slug . '-customizer-scripts', 'WP_API_Settings', array(
478
  'root' => esc_url_raw( rest_url() ),
479
  'nonce' => wp_create_nonce( 'wp_rest' )
480
  ) );
481
  }
482
 
483
+ function add_rest_routes_api(){
484
+ register_rest_route( 'customfiy/v1', '/delete_theme_mod', array(
485
+ 'methods' => 'POST',
486
+ 'callback' => array( $this, 'delete_theme_mod' ),
487
+ 'permission_callback' => array( $this, 'permission_nonce_callback' ),
488
+ ) );
489
+ }
490
+
491
+ function delete_theme_mod(){
492
+ $user = wp_get_current_user();
493
+ if ( ! $user->caps['administrator'] ) {
494
+ wp_send_json_error('no admin');
495
+ }
496
+
497
+ $config = apply_filters('customify_filter_fields', array() );
498
+
499
+ if ( empty( $config['opt-name'] ) ) {
500
+ wp_send_json_error('no option key');
501
+ }
502
+
503
+ $key = $config['opt-name'];
504
+
505
+ remove_theme_mod( $key );
506
+
507
+ wp_send_json_success('Bby ' . $key . '!');
508
+ }
509
+
510
+ function permission_nonce_callback() {
511
+ return wp_verify_nonce( $this->get_nonce(), 'customify_settings_nonce' );
512
+ }
513
+
514
+ private function get_nonce() {
515
+ $nonce = null;
516
+
517
+ if ( isset( $_REQUEST['customify_settings_nonce'] ) ) {
518
+ $nonce = wp_unslash( $_REQUEST['customify_settings_nonce'] );
519
+ } elseif ( isset( $_POST['customify_settings_nonce'] ) ) {
520
+ $nonce = wp_unslash( $_POST['customify_settings_nonce'] );
521
+ }
522
+
523
+ return $nonce;
524
+ }
525
+
526
  /**
527
  * Public style generated by customizer
528
  */
537
  }
538
 
539
  if ( $option['type'] === 'custom_background' ) {
540
+ $option['value'] = $this->get_option( $option_id );
541
  $custom_css .= $this->process_custom_background_field_output( $option_id, $option );
542
  }
543
  }
985
  }
986
 
987
  protected function process_custom_background_field_output( $option_id, $options ) {
988
+ $selector = $output = '';
989
 
990
  if ( ! isset( $options['value'] ) ) {
991
  return false;
999
  } elseif ( is_array( $options['output'] ) ) {
1000
  $selector = implode( ' ', $options['output'] );
1001
  }
 
1002
 
1003
+
1004
+ $output .= $selector . " {";
1005
  if ( isset( $value['background-image'] ) && ! empty( $value['background-image'] ) ) {
1006
+ $output .= "background-image: url( " . $value['background-image'] . ");";
1007
  } else {
1008
+ $output .= "background-image: none;";
1009
  }
1010
 
1011
  if ( isset( $value['background-repeat'] ) && ! empty( $value['background-repeat'] ) ) {
1012
+ $output .= "background-repeat:" . $value['background-repeat'] . ";";
1013
  }
1014
 
1015
  if ( isset( $value['background-position'] ) && ! empty( $value['background-position'] ) ) {
1016
+ $output .= "background-position:" . $value['background-position'] . ";";
1017
  }
1018
 
1019
  if ( isset( $value['background-size'] ) && ! empty( $value['background-size'] ) ) {
1020
+ $output .= "background-size:" . $value['background-size'] . ";";
1021
  }
1022
 
1023
  if ( isset( $value['background-attachment'] ) && ! empty( $value['background-attachment'] ) ) {
1024
+ $output .= "background-attachment:" . $value['background-attachment'] . ";";
1025
  }
1026
+ $output .= "}\n";
1027
 
1028
+ return $output;
1029
  }
1030
 
1031
  /**
customify.php CHANGED
@@ -3,8 +3,8 @@
3
  Plugin Name: Customify
4
  Plugin URI: https://wordpress.org/plugins/customify/
5
  Description: A Theme Customizer Booster
6
- Version: 1.5.1
7
- Author: PixelGrade
8
  Author URI: https://pixelgrade.com
9
  Author Email: contact@pixelgrade.com
10
  Text Domain: customify
@@ -54,7 +54,7 @@ if ( $current_data === false ) {
54
  function PixCustomifyPlugin() {
55
 
56
  require_once( plugin_dir_path( __FILE__ ) . 'class-pixcustomify.php' );
57
- $instance = PixCustomifyPlugin::instance( __FILE__, '1.5.1' );
58
  return $instance;
59
  }
60
 
3
  Plugin Name: Customify
4
  Plugin URI: https://wordpress.org/plugins/customify/
5
  Description: A Theme Customizer Booster
6
+ Version: 1.5.2
7
+ Author: Pixelgrade
8
  Author URI: https://pixelgrade.com
9
  Author Email: contact@pixelgrade.com
10
  Text Domain: customify
54
  function PixCustomifyPlugin() {
55
 
56
  require_once( plugin_dir_path( __FILE__ ) . 'class-pixcustomify.php' );
57
+ $instance = PixCustomifyPlugin::instance( __FILE__, '1.5.2' );
58
  return $instance;
59
  }
60
 
features/class-Font_Selector.php CHANGED
@@ -21,8 +21,75 @@ class Customify_Font_Selector {
21
  $load_location = PixCustomifyPlugin()->get_plugin_setting( 'style_resources_location', 'wp_head' );
22
  add_action( $load_location, array( $this, 'output_font_dynamic_style' ), 999999999 );
23
  add_action( 'customify_font_family_before_options', array( $this, 'add_customify_theme_fonts' ), 11, 2 );
 
 
 
 
 
24
  }
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  public function get_theme_fonts() {
27
  return $this->theme_fonts;
28
  }
21
  $load_location = PixCustomifyPlugin()->get_plugin_setting( 'style_resources_location', 'wp_head' );
22
  add_action( $load_location, array( $this, 'output_font_dynamic_style' ), 999999999 );
23
  add_action( 'customify_font_family_before_options', array( $this, 'add_customify_theme_fonts' ), 11, 2 );
24
+
25
+ if ( PixCustomifyPlugin()->get_plugin_setting( 'enable_editor_style', true ) ) {
26
+ add_action( 'admin_head', array( $this, 'add_customizer_settings_into_wp_editor' ) );
27
+ }
28
+
29
  }
30
 
31
+ function add_customizer_settings_into_wp_editor() {
32
+
33
+ ob_start();
34
+ $this->output_font_dynamic_style();
35
+
36
+ $custom_css = ob_get_clean(); ?>
37
+ <script type="text/javascript">
38
+ /* <![CDATA[ */
39
+ (function ($) {
40
+ $(window).load(function () {
41
+ /**
42
+ * @param iframe_id the id of the frame you whant to append the style
43
+ * @param style_element the style element you want to append
44
+ */
45
+ var append_script_to_iframe = function (ifrm_id, scriptEl) {
46
+ var myIframe = document.getElementById(ifrm_id);
47
+
48
+ var script = myIframe.contentWindow.document.createElement("script");
49
+ script.type = "text/javascript";
50
+ script.innerHTML = scriptEl.innerHTML;
51
+
52
+ myIframe.contentWindow.document.head.appendChild(script);
53
+ };
54
+
55
+ var append_style_to_iframe = function (ifrm_id, styleElment) {
56
+ var ifrm = window.frames[ifrm_id];
57
+ ifrm = ( ifrm.contentDocument || ifrm.contentDocument || ifrm.document );
58
+ var head = ifrm.getElementsByTagName('head')[0];
59
+
60
+ if (typeof styleElment !== "undefined") {
61
+ head.appendChild(styleElment);
62
+ }
63
+ };
64
+
65
+ var xmlString = <?php echo json_encode( str_replace( "\n", "", $custom_css ) ); ?>,
66
+ parser = new DOMParser(),
67
+ doc = parser.parseFromString(xmlString, "text/html");
68
+
69
+ if (typeof window.frames['content_ifr'] !== 'undefined') {
70
+
71
+ $.each(doc.head.childNodes, function (key, el) {
72
+ if (typeof el !== "undefined" && typeof el.tagName !== "undefined") {
73
+
74
+ switch (el.tagName) {
75
+ case 'STYLE' :
76
+ append_style_to_iframe('content_ifr', el);
77
+ break;
78
+ case 'SCRIPT' :
79
+ append_script_to_iframe('content_ifr', el);
80
+ break;
81
+ default:
82
+ break;
83
+ }
84
+ }
85
+ });
86
+ }
87
+ });
88
+ })(jQuery);
89
+ /* ]]> */
90
+ </script>
91
+ <?php }
92
+
93
  public function get_theme_fonts() {
94
  return $this->theme_fonts;
95
  }
languages/customify.pot CHANGED
@@ -2,7 +2,7 @@
2
  # This file is distributed under the same license as the Customify package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Customify 1.5.1\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/customify\n"
7
  "POT-Creation-Date: 2017-02-13 13:29:14+00:00\n"
8
  "MIME-Version: 1.0\n"
2
  # This file is distributed under the same license as the Customify package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Customify 1.5.2\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/customify\n"
7
  "POT-Creation-Date: 2017-02-13 13:29:14+00:00\n"
8
  "MIME-Version: 1.0\n"
plugin-config.php CHANGED
@@ -25,6 +25,7 @@ return array(
25
  'output' => include 'settings/output' . EXT,
26
  'typography' => include 'settings/typography' . EXT,
27
  'css_editor' => include 'settings/css_editor' . EXT,
 
28
  ),
29
  'processor' => array(
30
  // callback signature: (array $input, customifyProcessor $processor)
25
  'output' => include 'settings/output' . EXT,
26
  'typography' => include 'settings/typography' . EXT,
27
  'css_editor' => include 'settings/css_editor' . EXT,
28
+ 'tools' => include 'settings/tools' . EXT,
29
  ),
30
  'processor' => array(
31
  // callback signature: (array $input, customifyProcessor $processor)
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: pixelgrade, euthelup, babbardel, vlad.olaru, cristianfrumusanu, ra
3
  Tags: customizer, css, editor, live, preview, customise
4
  Requires at least: 4.5.0
5
  Tested up to: 4.7.3
6
- Stable tag: 1.5.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -37,6 +37,11 @@ With [Customify](https://github.com/pixelgrade/customify), developers can easily
37
 
38
  == Changelog ==
39
 
 
 
 
 
 
40
  = 1.5.1 =
41
  * Added support for `active_callback` argument for customizer controls
42
  * Customizer assets refactor
3
  Tags: customizer, css, editor, live, preview, customise
4
  Requires at least: 4.5.0
5
  Tested up to: 4.7.3
6
+ Stable tag: 1.5.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
37
 
38
  == Changelog ==
39
 
40
+ = 1.5.2 =
41
+ * Fixed Background field output
42
+ * Fixed Font's preview in wp-editor
43
+ * Added Reset Theme Mods tool
44
+
45
  = 1.5.1 =
46
  * Added support for `active_callback` argument for customizer controls
47
  * Customizer assets refactor
settings/tools.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //not used yet - moved them to a per gallery option
3
+
4
+ return array(
5
+ 'type' => 'postbox',
6
+ 'label' => 'Tools',
7
+ 'options' => array(
8
+ 'reset_theme_mod' => array(
9
+ 'name' => 'reset_theme_mod',
10
+ 'label' => __( 'Reset', 'customify' ),
11
+ 'type' => 'reset_theme_mod',
12
+ )
13
+ )
14
+ ); # config
views/admin.php CHANGED
@@ -46,7 +46,7 @@ $errors = $processor->errors(); ?>
46
  echo $f->field( 'general' )->render();
47
  echo $f->field( 'output' )->render();
48
  echo $f->field( 'typography' )->render();
49
- // echo $f->field( 'css_editor' )->render(); ?>
50
  <button type="submit" class="button button-primary">
51
  <?php _e( 'Save Changes', 'customify' ); ?>
52
  </button>
46
  echo $f->field( 'general' )->render();
47
  echo $f->field( 'output' )->render();
48
  echo $f->field( 'typography' )->render();
49
+ echo $f->field( 'tools' )->render(); ?>
50
  <button type="submit" class="button button-primary">
51
  <?php _e( 'Save Changes', 'customify' ); ?>
52
  </button>
views/form-partials/fields/reset_theme_mod.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php defined( 'ABSPATH' ) or die;
2
+ /* @var PixCustomifyFormField $field */
3
+ /* @var PixCustomifyForm $form */
4
+ /* @var mixed $default */
5
+ /* @var string $name */
6
+ /* @var string $idname */
7
+ /* @var string $label */
8
+ /* @var string $desc */
9
+ /* @var string $rendering */
10
+
11
+ // [!!] the counter field needs to be able to work inside other fields; if
12
+ // the field is in another field it will have a null label
13
+
14
+ $selected = $form->autovalue( $name, $default );
15
+
16
+ $config = apply_filters('customify_filter_fields', array() );
17
+
18
+ $key = $config[ 'opt-name' ];
19
+
20
+ $mods = get_theme_mods();
21
+
22
+ $option = get_option( 'pixcustomify_settings' );
23
+
24
+ $attrs = array(
25
+ 'type' => 'checkbox',
26
+ ); ?>
27
+ <div class="reset_customify_theme_mod">
28
+ <div class="button" id="reset_theme_mods"><?php esc_html_e( 'Reset theme mod', 'customify' ); ?></div>
29
+ <script>
30
+ (function ($) {
31
+ $(document).ready(function () {
32
+ $('#reset_theme_mods').on('click', function () {
33
+ var confirm = window.confirm('Are you sure?');
34
+
35
+ if ( ! confirm ) {
36
+ return false;
37
+ }
38
+
39
+ $.ajax({
40
+ url: customify_settings.wp_rest.root + 'customfiy/v1/delete_theme_mod',
41
+ method: 'POST',
42
+ beforeSend: function (xhr) {
43
+ xhr.setRequestHeader('X-WP-Nonce', customify_settings.wp_rest.nonce);
44
+ },
45
+ data: {
46
+ 'customify_settings_nonce': customify_settings.wp_rest.customify_settings_nonce
47
+ }
48
+ }).done(function (response) {
49
+ if ( response.success ) {
50
+ alert( response.data );
51
+ }
52
+ }).error(function (e) {
53
+ console.log(e);
54
+ });
55
+ });
56
+ });
57
+
58
+ })(jQuery)
59
+ </script>
60
+ </div>