Styles - Version 1.0.13

Version Description

  • New: Allow notices to be disabled with a filter: add_filter( 'styles_disable_notices', '__return_true' );
  • New: Don't display install notices for default themes if a plugin is installed and then renamed.
  • Fix: Don't display install notices for non-default themes. Resolves a regression introduced in 1.0.12.
Download this release

Release Info

Developer pdclark
Plugin Icon Styles
Version 1.0.13
Comparing to
See all releases

Code changes from version 1.0.12 to 1.0.13

classes/styles-admin.php CHANGED
@@ -12,6 +12,9 @@ class Styles_Admin {
12
  */
13
  var $notices = array();
14
 
 
 
 
15
  var $default_themes = array(
16
  'twentyten',
17
  'twentyeleven',
@@ -36,7 +39,6 @@ class Styles_Admin {
36
  // Scripts
37
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
38
 
39
-
40
  // Plugin Meta
41
  add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
42
 
@@ -46,11 +48,18 @@ class Styles_Admin {
46
 
47
  /**
48
  * Enqueue admin stylesheet
 
49
  */
50
  public function admin_enqueue_scripts() {
51
  wp_enqueue_style( 'storm-styles-admin', plugins_url('css/styles-admin.css', STYLES_BASENAME), array(), $this->plugin->version, 'all' );
52
  }
53
 
 
 
 
 
 
 
54
  public function plugin_row_meta( $meta, $basename ) {
55
  if ( STYLES_BASENAME == $basename ) {
56
  $meta[2] = str_replace( 'Visit plugin site', 'Get More Themes', $meta[2] );
@@ -59,30 +68,65 @@ class Styles_Admin {
59
  return $meta;
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  public function install_default_themes_notice() {
63
- if ( $this->is_plugin_update_or_delete() ) {
 
 
 
 
64
  return false;
65
  }
66
 
67
- $slug = 'styles-' . get_template();
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- if ( !is_dir( WP_PLUGIN_DIR . '/' . $slug ) ) {
70
- // Plugin not installed
71
  $theme = wp_get_theme();
72
- $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug), 'install-plugin_' . $slug );
 
73
  $this->notices[] = "<p>Styles is almost ready! To add theme options for <strong>{$theme->name}</strong>, please <a href='$url'>install Styles: {$theme->name}</a>.</p>";
74
  return true;
75
  }
76
  }
77
 
78
  /**
79
- * If plugin for this theme is installed, but not activated, display notice.
 
 
 
 
 
 
 
80
  */
81
  public function activate_notice() {
82
- if ( $this->is_plugin_update_or_delete() ) {
83
- return false;
84
- }
85
- if ( !is_a( $this->plugin->child, 'Styles_Child' ) ) {
 
86
  return false;
87
  }
88
 
@@ -97,6 +141,10 @@ class Styles_Admin {
97
 
98
  }
99
 
 
 
 
 
100
  public function is_plugin_update_or_delete() {
101
  if ( 'update.php' == basename( $_SERVER['PHP_SELF'] )
102
  || ( isset( $_GET['action'] ) && 'delete-selected' == $_GET['action'] )
@@ -108,6 +156,9 @@ class Styles_Admin {
108
  }
109
  }
110
 
 
 
 
111
  public function admin_notices() {
112
  foreach( $this->notices as $key => $message ) {
113
  echo "<div class='updated fade' id='styles-$key'>$message</div>";
@@ -115,12 +166,19 @@ class Styles_Admin {
115
  }
116
 
117
  /**
118
- * Pass notices to styles-customize-controls.js
 
 
119
  */
120
  public function customize_notices() {
121
  wp_localize_script( 'styles-customize-controls', 'wp_styles_notices', $this->notices );
122
  }
123
 
 
 
 
 
 
124
  function license_menu() {
125
  $plugins = apply_filters( 'styles_license_form_plugins', array() );
126
 
@@ -129,9 +187,14 @@ class Styles_Admin {
129
  }
130
  }
131
 
132
- function license_page() {
133
- require_once STYLES_DIR . '/views/licenses.php';
134
- exit;
135
- }
 
 
 
 
 
136
 
137
  }
12
  */
13
  var $notices = array();
14
 
15
+ /**
16
+ * List of theme slugs we know have styles plugins on wordpress.org
17
+ */
18
  var $default_themes = array(
19
  'twentyten',
20
  'twentyeleven',
39
  // Scripts
40
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
41
 
 
42
  // Plugin Meta
43
  add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
44
 
48
 
49
  /**
50
  * Enqueue admin stylesheet
51
+ * Adds the blue "Customize" button to the plugin row.
52
  */
53
  public function admin_enqueue_scripts() {
54
  wp_enqueue_style( 'storm-styles-admin', plugins_url('css/styles-admin.css', STYLES_BASENAME), array(), $this->plugin->version, 'all' );
55
  }
56
 
57
+ /**
58
+ * Add additional links to the plugin row
59
+ * For example, "Customize"
60
+ *
61
+ * Change the title of "Visit plugin site"
62
+ */
63
  public function plugin_row_meta( $meta, $basename ) {
64
  if ( STYLES_BASENAME == $basename ) {
65
  $meta[2] = str_replace( 'Visit plugin site', 'Get More Themes', $meta[2] );
68
  return $meta;
69
  }
70
 
71
+ /**
72
+ * Notice for novice users.
73
+ *
74
+ * If a default theme is active, but no Styles add-on is active,
75
+ * display a prompt with a link to install the add-on from wordpress.org
76
+ *
77
+ * Does not run if:
78
+ * Active template is not in $this->default_themes
79
+ * Any active or inactive plugin declares support for the current theme
80
+ * `styles_disable_notices` filter returns true
81
+ * Example: <code>add_filter( 'styles_disable_notices', '__return_true' );</code>
82
+ */
83
  public function install_default_themes_notice() {
84
+ if (
85
+ apply_filters( 'styles_disable_notices', false )
86
+ || $this->is_plugin_update_or_delete()
87
+ || !in_array( get_template(), $this->default_themes ) // Active theme is a parent and default
88
+ ) {
89
  return false;
90
  }
91
 
92
+ $plugin_installed = false;
93
+ if ( is_a( $this->plugin->child, 'Styles_Child' ) ) {
94
+
95
+ $all_styles_plugins = array_merge( (array) $this->plugin->child->plugins, (array) $this->plugin->child->inactive_plugins );
96
+
97
+ foreach ( $all_styles_plugins as $plugin ) {
98
+ if ( $plugin->is_target_theme_active() ) {
99
+ // This plugin is for the active theme, but is inactive
100
+ $plugin_installed = true;
101
+ }
102
+ }
103
+ }
104
 
105
+ if ( !$plugin_installed ) {
 
106
  $theme = wp_get_theme();
107
+ $slug = 'styles-' . get_template();
108
+ $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
109
  $this->notices[] = "<p>Styles is almost ready! To add theme options for <strong>{$theme->name}</strong>, please <a href='$url'>install Styles: {$theme->name}</a>.</p>";
110
  return true;
111
  }
112
  }
113
 
114
  /**
115
+ * Notice for novice users.
116
+ *
117
+ * If an inactive plugin declares support for the currently active theme,
118
+ * display a notice with a link to active the plugin.
119
+ *
120
+ * Does not run if:
121
+ * `styles_disable_notices` filter returns true
122
+ * Example: <code>add_filter( 'styles_disable_notices', '__return_true' );</code>
123
  */
124
  public function activate_notice() {
125
+ if (
126
+ apply_filters( 'styles_disable_notices', false )
127
+ || $this->is_plugin_update_or_delete()
128
+ || !is_a( $this->plugin->child, 'Styles_Child' ) // No child plugins installed
129
+ ) {
130
  return false;
131
  }
132
 
141
 
142
  }
143
 
144
+ /**
145
+ * Check whether we're on a screen for updating or deleting plugins.
146
+ * If we are, return false to disable notices.
147
+ */
148
  public function is_plugin_update_or_delete() {
149
  if ( 'update.php' == basename( $_SERVER['PHP_SELF'] )
150
  || ( isset( $_GET['action'] ) && 'delete-selected' == $_GET['action'] )
156
  }
157
  }
158
 
159
+ /**
160
+ * Output all notices that have been added to the $this->notices array
161
+ */
162
  public function admin_notices() {
163
  foreach( $this->notices as $key => $message ) {
164
  echo "<div class='updated fade' id='styles-$key'>$message</div>";
166
  }
167
 
168
  /**
169
+ * Allows notices to display in the customize.php sidebar
170
+ *
171
+ * @return null Passes $this->notices array to styles-customize-controls.js
172
  */
173
  public function customize_notices() {
174
  wp_localize_script( 'styles-customize-controls', 'wp_styles_notices', $this->notices );
175
  }
176
 
177
+ /**
178
+ * Add the Styles Licenses page if any plugins require license keys for updating.
179
+ *
180
+ * @return null
181
+ */
182
  function license_menu() {
183
  $plugins = apply_filters( 'styles_license_form_plugins', array() );
184
 
187
  }
188
  }
189
 
190
+ /**
191
+ * Output the Styles License page view.
192
+ *
193
+ * @return null Outputs views/licenses.php and exits.
194
+ */
195
+ function license_page() {
196
+ require_once STYLES_DIR . '/views/licenses.php';
197
+ exit;
198
+ }
199
 
200
  }
classes/styles-child-theme.php CHANGED
@@ -66,7 +66,13 @@ class Styles_Child_Theme extends Styles_Child_Updatable {
66
  */
67
  public function theme_name_equals_plugin_item_name( $theme ) {
68
  if ( !is_a( $theme, 'WP_Theme') ) { return false; }
69
- if ( 0 === strcasecmp( $this->item_name, $theme->get('Name') ) ) { return true; }
 
 
 
 
 
 
70
  return false;
71
  }
72
 
@@ -85,7 +91,13 @@ class Styles_Child_Theme extends Styles_Child_Updatable {
85
  */
86
  public function theme_name_equals_plugin_name( $theme ) {
87
  if ( !is_a( $theme, 'WP_Theme') ) { return false; }
88
- if ( 0 === strcasecmp( $this->plugin_theme_name, $theme->get('Name') ) ) { return true; }
 
 
 
 
 
 
89
  return false;
90
  }
91
 
@@ -119,6 +131,10 @@ class Styles_Child_Theme extends Styles_Child_Updatable {
119
  return $this->plugin_directory_name;
120
  }
121
 
 
 
 
 
122
  public function get_json_path() {
123
  if ( $this->is_target_parent_or_child_theme_active() ) {
124
  $json_file = dirname( $this->plugin_file ) . '/customize.json';
@@ -126,7 +142,6 @@ class Styles_Child_Theme extends Styles_Child_Updatable {
126
  }else {
127
  return false;
128
  }
129
-
130
  }
131
 
132
  /**
66
  */
67
  public function theme_name_equals_plugin_item_name( $theme ) {
68
  if ( !is_a( $theme, 'WP_Theme') ) { return false; }
69
+
70
+ // Strip spacing and special characters in theme names
71
+ // Allows "Twenty Twelve" to match "TwentyTwelve"
72
+ $santatized_item_name = $this->sanatize_name( $this->item_name );
73
+ $santatized_theme_name = $this->sanatize_name( $theme->get('Name') );
74
+
75
+ if ( 0 === strcasecmp( $santatized_item_name, $santatized_theme_name ) ) { return true; }
76
  return false;
77
  }
78
 
91
  */
92
  public function theme_name_equals_plugin_name( $theme ) {
93
  if ( !is_a( $theme, 'WP_Theme') ) { return false; }
94
+
95
+ // Strip spacing and special characters in theme names
96
+ // Allows "Twenty Twelve" to match "TwentyTwelve"
97
+ $santatized_plugin_name = $this->sanatize_name( $this->plugin_theme_name );
98
+ $santatized_theme_name = $this->sanatize_name( $theme->get('Name') );
99
+
100
+ if ( 0 === strcasecmp( $santatized_plugin_name, $santatized_theme_name ) ) { return true; }
101
  return false;
102
  }
103
 
131
  return $this->plugin_directory_name;
132
  }
133
 
134
+ public function sanatize_name( $name ) {
135
+ return preg_replace( '/[^a-zA-Z0-9]/', '', $name );
136
+ }
137
+
138
  public function get_json_path() {
139
  if ( $this->is_target_parent_or_child_theme_active() ) {
140
  $json_file = dirname( $this->plugin_file ) . '/customize.json';
142
  }else {
143
  return false;
144
  }
 
145
  }
146
 
147
  /**
classes/styles-plugin.php CHANGED
@@ -12,7 +12,7 @@ class Styles_Plugin {
12
  *
13
  * @var string
14
  **/
15
- var $version = '1.0.12';
16
 
17
  /**
18
  * Plugin DB version
12
  *
13
  * @var string
14
  **/
15
+ var $version = '1.0.13';
16
 
17
  /**
18
  * Plugin DB version
readme.txt CHANGED
@@ -5,7 +5,7 @@ Author URI: http://brainstormmedia.com
5
  Tags: css, stylesheet, appearance, customize, customizer, colors, color picker, background, fonts, google fonts, user interface, twenty ten, twenty eleven, twenty twelve, twenty thirteen
6
  Requires at least: 3.4
7
  Tested up to: 3.6
8
- Stable tag: 1.0.12
9
 
10
  Be creative with colors and fonts. Styles changes everything.
11
 
@@ -90,6 +90,12 @@ No! Styles is very careful about only loading what is needed to get its job done
90
 
91
  == Changelog ==
92
 
 
 
 
 
 
 
93
  = 1.0.12 =
94
 
95
  <ul>
@@ -195,6 +201,12 @@ No! Styles is very careful about only loading what is needed to get its job done
195
 
196
  == Upgrade Notice ==
197
 
 
 
 
 
 
 
198
  **1.0.12**
199
 
200
  <ul>
5
  Tags: css, stylesheet, appearance, customize, customizer, colors, color picker, background, fonts, google fonts, user interface, twenty ten, twenty eleven, twenty twelve, twenty thirteen
6
  Requires at least: 3.4
7
  Tested up to: 3.6
8
+ Stable tag: 1.0.13
9
 
10
  Be creative with colors and fonts. Styles changes everything.
11
 
90
 
91
  == Changelog ==
92
 
93
+ = 1.0.13 =
94
+
95
+ * New: Allow notices to be disabled with a filter: <code>add_filter( 'styles_disable_notices', '__return_true' );</code>
96
+ * New: Don't display install notices for default themes if a plugin is installed and then renamed.
97
+ * Fix: Don't display install notices for non-default themes. Resolves a regression introduced in 1.0.12.
98
+
99
  = 1.0.12 =
100
 
101
  <ul>
201
 
202
  == Upgrade Notice ==
203
 
204
+ **1.0.13**
205
+
206
+ * New: Allow notices to be disabled with a filter: <code>add_filter( 'styles_disable_notices', '__return_true' );</code>
207
+ * New: Don't display install notices for default themes if a plugin is installed and then renamed.
208
+ * Fix: Don't display install notices for non-default themes. Resolves a regression introduced in 1.0.12.
209
+
210
  **1.0.12**
211
 
212
  <ul>
styles.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Styles
4
  Plugin URI: http://stylesplugin.com
5
  Description: Change the appearance of your theme using the <a href="customize.php">WordPress Customizer</a>. Styles changes everything.
6
- Version: 1.0.12
7
  Author: Brainstorm Media
8
  Author URI: http://brainstormmedia.com
9
  */
3
  Plugin Name: Styles
4
  Plugin URI: http://stylesplugin.com
5
  Description: Change the appearance of your theme using the <a href="customize.php">WordPress Customizer</a>. Styles changes everything.
6
+ Version: 1.0.13
7
  Author: Brainstorm Media
8
  Author URI: http://brainstormmedia.com
9
  */