Styles - Version 1.0.12

Version Description

  • Fix: Improve detection of plugins adding support for themes
    • Add support if `Plugin Name: Styles: NAME` matches `Theme Name: NAME`
    • Add support if directory names `styles-NAME` and `theme/NAME` match
    • Make theme check case-insensitive. Resolves issues for themes with capitalized folder names, like iThemes child themes.
    • Thanks [@JiveDig](http://twitter.com/jivedig) for pointing some of these issues out.
  • Fix: Improve activation notices for child themes
    • Add theme options for a parent theme if they're activated, but don't show a notice requiring them.
    • Detect and display which theme a plugin is trying to add support for.
    • Correctly display the plugin name requesting activation in cases where the plugin doesn't follow the recommended naming convention.
Download this release

Release Info

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

Code changes from version 1.0.11 to 1.0.12

classes/styles-admin.php CHANGED
@@ -60,10 +60,7 @@ class Styles_Admin {
60
  }
61
 
62
  public function install_default_themes_notice() {
63
- if ( !in_array( get_template(), $this->default_themes )
64
- || 'update.php' == basename( $_SERVER['PHP_SELF'] )
65
- || !current_user_can('install_plugins')
66
- ) {
67
  return false;
68
  }
69
 
@@ -82,16 +79,33 @@ class Styles_Admin {
82
  * If plugin for this theme is installed, but not activated, display notice.
83
  */
84
  public function activate_notice() {
85
- $slug = 'styles-' . get_template();
86
- $plugin_file = $slug . '/' . 'plugin.php';
 
 
 
 
87
 
88
- if ( is_dir( WP_PLUGIN_DIR . '/' . $slug ) ) {
89
- if ( is_plugin_inactive( $plugin_file ) ) {
90
- $theme = wp_get_theme();
91
- $url = wp_nonce_url(self_admin_url('plugins.php?action=activate&plugin=' . $plugin_file ), 'activate-plugin_' . $plugin_file );
92
- $this->notices[] = "<p><strong>Styles: {$theme->name}</strong> is installed, but not active. Please <a href='$url'>activate Styles: {$theme->name}</a>.</p>";
 
93
  }
94
  }
 
 
 
 
 
 
 
 
 
 
 
 
95
  }
96
 
97
  public function admin_notices() {
60
  }
61
 
62
  public function install_default_themes_notice() {
63
+ if ( $this->is_plugin_update_or_delete() ) {
 
 
 
64
  return false;
65
  }
66
 
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
 
89
+ foreach ( (array) $this->plugin->child->inactive_plugins as $plugin ) {
90
+ if ( $plugin->is_target_theme_active() ) {
91
+ // This plugin is for the active theme, but is inactive
92
+ $theme_name = $plugin->theme->get('Name');
93
+ $url = wp_nonce_url(self_admin_url('plugins.php?action=activate&plugin=' . $plugin->plugin_basename ), 'activate-plugin_' . $plugin->plugin_basename );
94
+ $this->notices[] = "<p><strong>{$plugin->name}</strong> is installed, but not active. To add Styles support for $theme_name, please <a href='$url'>activate {$plugin->name}</a>.</p>";
95
  }
96
  }
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'] )
103
+ || !current_user_can('install_plugins')
104
+ ){
105
+ return true;
106
+ }else {
107
+ return false;
108
+ }
109
  }
110
 
111
  public function admin_notices() {
classes/styles-child-theme.php CHANGED
@@ -10,23 +10,117 @@ class Styles_Child_Theme extends Styles_Child_Updatable {
10
 
11
  $this->template = str_replace( ' ', '-', strtolower( $this->item_name ) );
12
  $this->styles_css = dirname( $this->plugin_file ) . '/style.css';
 
 
 
13
 
14
  add_filter( 'styles_css_output', array( $this, 'styles_css_output' ) );
15
  }
16
 
17
- public function is_active() {
18
- if (
19
- $this->template == Styles_Helpers::get_template()
20
- || $this->template == get_stylesheet()
21
- ) {
22
- return true;
23
- }else {
24
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
 
 
 
 
 
 
 
 
 
 
26
  }
27
 
28
  public function get_json_path() {
29
- if ( $this->is_active() ) {
30
  $json_file = dirname( $this->plugin_file ) . '/customize.json';
31
  return $json_file;
32
  }else {
@@ -39,7 +133,7 @@ class Styles_Child_Theme extends Styles_Child_Updatable {
39
  * If styles.css exists in the plugin folder, prepend it to final CSS output
40
  */
41
  public function styles_css_output( $css ) {
42
- if ( $this->is_active() && file_exists( $this->styles_css ) ) {
43
  $css = file_get_contents( $this->styles_css ) . $css;
44
  }
45
 
10
 
11
  $this->template = str_replace( ' ', '-', strtolower( $this->item_name ) );
12
  $this->styles_css = dirname( $this->plugin_file ) . '/style.css';
13
+ $this->plugin_theme_name = trim( str_replace( 'Styles:', '', $this->name ) );
14
+
15
+ $this->theme = wp_get_theme();
16
 
17
  add_filter( 'styles_css_output', array( $this, 'styles_css_output' ) );
18
  }
19
 
20
+ public function is_target_parent_or_child_theme_active() {
21
+ return ( $this->is_target_theme_active() || $this->is_target_parent_theme_active() );
22
+ }
23
+
24
+ public function is_target_parent_theme_active() {
25
+ if ( !is_a( $this->theme->parent() , 'WP_Theme') ) { return false; }
26
+
27
+ // Do parent or child theme header name == Styles plugin "Style Item" header?
28
+ // WARNING: Don't use this option. It's likely to change.
29
+ if ( $this->theme_name_equals_plugin_item_name( $this->theme->parent() ) ) { return true; }
30
+
31
+ // Do parent or child theme header name == Styles plugin header name?
32
+ if ( $this->theme_name_equals_plugin_name( $this->theme->parent() ) ) { return true; }
33
+
34
+ // Does the parent or child directory name == Styles directory name?
35
+ if ( $this->theme_directory_name_equals_plugin_directory_name( $this->theme->parent() ) ) { return true; }
36
+
37
+ return false;
38
+ }
39
+
40
+ public function is_target_theme_active() {
41
+ // Do parent or child theme header name == Styles plugin "Style Item" header?
42
+ // WARNING: Don't use this option. It's likely to change.
43
+ if ( $this->theme_name_equals_plugin_item_name( $this->theme ) ) { return true; }
44
+
45
+ // Do parent or child theme header name == Styles plugin header name?
46
+ if ( $this->theme_name_equals_plugin_name( $this->theme ) ) { return true; }
47
+
48
+ // Does the parent or child directory name == Styles directory name?
49
+ if ( $this->theme_directory_name_equals_plugin_directory_name( $this->theme ) ) { return true; }
50
+
51
+ return false;
52
+ }
53
+
54
+ /**
55
+ * Do parent or child theme header name == Styles plugin "Style Item" header?
56
+ * (Case insensitive)
57
+ *
58
+ * For example:
59
+ * Theme Name: Some Parent or Child Theme
60
+ * Styles Item: Some Parent or Child Theme
61
+ *
62
+ * This is an override for **weird edge cases** where the Styles plugin name
63
+ * or folder name can't match the theme name or folder name.
64
+ *
65
+ * Warning: Don't use this. It's likely to change.
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
+
73
+ /**
74
+ * Do parent or child theme header name == Styles plugin header name?
75
+ * (Case insensitive)
76
+ *
77
+ * For example:
78
+ * Theme Name: Some Parent or Child Theme
79
+ * Plugin Name: Styles: Some Parent or Child Theme
80
+ *
81
+ * ...would return true.
82
+ *
83
+ * "Theme Name" is in the theme header.
84
+ * "Plugin Name" is in the Styles plugin header.
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
+
92
+ /**
93
+ * Does the parent or child directory name == Styles directory name?
94
+ * (Case insensitive)
95
+ *
96
+ * For example:
97
+ * Theme directory: some-parent-or-child-theme
98
+ * Plugin directory: styles-some-parent-or-child-theme
99
+ */
100
+ public function theme_directory_name_equals_plugin_directory_name( $theme ) {
101
+ if ( !is_a( $theme, 'WP_Theme') ) { return false; }
102
+ if ( 0 === strcasecmp( $this->get_plugin_directory_name(), $theme->stylesheet ) ) { return true; }
103
+ return false;
104
+ }
105
+
106
+ public function get_plugin_directory_name() {
107
+ if ( isset( $this->plugin_directory_name ) ) {
108
+ return $this->plugin_directory_name;
109
  }
110
+ $plugin_directory_name = basename( dirname( $this->plugin_file ) );
111
+
112
+ // Strip 'styles-' from the plugin directory name
113
+ $remove = 'styles-';
114
+ if ( $remove == strtolower( substr($plugin_directory_name, 0, strlen( $remove ) ) ) ) {
115
+ $plugin_directory_name = substr($plugin_directory_name, strlen( $remove ) );
116
+ }
117
+
118
+ $this->plugin_directory_name = $plugin_directory_name;
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';
125
  return $json_file;
126
  }else {
133
  * If styles.css exists in the plugin folder, prepend it to final CSS output
134
  */
135
  public function styles_css_output( $css ) {
136
+ if ( $this->is_target_parent_or_child_theme_active() && file_exists( $this->styles_css ) ) {
137
  $css = file_get_contents( $this->styles_css ) . $css;
138
  }
139
 
classes/styles-child.php CHANGED
@@ -17,6 +17,12 @@ class Styles_Child {
17
  */
18
  var $plugins = array();
19
 
 
 
 
 
 
 
20
  public function __construct( $plugin ) {
21
  $this->plugin = $plugin;
22
 
@@ -56,10 +62,14 @@ class Styles_Child {
56
 
57
  $class = $meta['styles class'];
58
 
59
- if ( class_exists( $class ) && is_plugin_active( $meta['slug'] ) ) {
60
  // For example,
61
  // new Styles_Child_Theme( $meta )
62
- $this->plugins[] = new $class( $meta );
 
 
 
 
63
  }
64
  }
65
  }
17
  */
18
  var $plugins = array();
19
 
20
+ /**
21
+ * Array of inactive plugin objects
22
+ * @var array
23
+ */
24
+ var $inactive_plugins = array();
25
+
26
  public function __construct( $plugin ) {
27
  $this->plugin = $plugin;
28
 
62
 
63
  $class = $meta['styles class'];
64
 
65
+ if ( class_exists( $class ) ) {
66
  // For example,
67
  // new Styles_Child_Theme( $meta )
68
+ if ( is_plugin_active( $meta['slug'] ) ) {
69
+ $this->plugins[] = new $class( $meta );
70
+ }else {
71
+ $this->inactive_plugins[] = new $class( $meta );
72
+ }
73
  }
74
  }
75
  }
classes/styles-plugin.php CHANGED
@@ -12,7 +12,7 @@ class Styles_Plugin {
12
  *
13
  * @var string
14
  **/
15
- var $version = '1.0.10';
16
 
17
  /**
18
  * Plugin DB version
12
  *
13
  * @var string
14
  **/
15
+ var $version = '1.0.12';
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.11
9
 
10
  Be creative with colors and fonts. Styles changes everything.
11
 
@@ -90,6 +90,26 @@ No! Styles is very careful about only loading what is needed to get its job done
90
 
91
  == Changelog ==
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  = 1.0.11 =
94
 
95
  * [This release goes to 11](http://www.youtube.com/watch?v=NrVCjnRdB_k).
@@ -175,6 +195,26 @@ No! Styles is very careful about only loading what is needed to get its job done
175
 
176
  == Upgrade Notice ==
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  **1.0.11**
179
 
180
  * [This release goes to 11](http://www.youtube.com/watch?v=NrVCjnRdB_k).
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
 
91
  == Changelog ==
92
 
93
+ = 1.0.12 =
94
+
95
+ <ul>
96
+ <li>Fix: Improve detection of plugins adding support for themes
97
+ <ul>
98
+ <li>Add support if `Plugin Name: Styles: NAME` matches `Theme Name: NAME`</li>
99
+ <li>Add support if directory names `styles-NAME` and `theme/NAME` match</li>
100
+ <li>Make theme check case-insensitive. Resolves issues for themes with capitalized folder names, like iThemes child themes.</li>
101
+ <li>Thanks [@JiveDig](http://twitter.com/jivedig) for pointing some of these issues out.</li>
102
+ </ul>
103
+ </li>
104
+ <li>Fix: Improve activation notices for child themes
105
+ <ul>
106
+ <li>Add theme options for a parent theme if they're activated, but don't show a notice requiring them.</li>
107
+ <li>Detect and display which theme a plugin is trying to add support for.</li>
108
+ <li>Correctly display the plugin name requesting activation in cases where the plugin doesn't follow the recommended naming convention.</li>
109
+ </ul>
110
+ </li>
111
+ </ul>
112
+
113
  = 1.0.11 =
114
 
115
  * [This release goes to 11](http://www.youtube.com/watch?v=NrVCjnRdB_k).
195
 
196
  == Upgrade Notice ==
197
 
198
+ **1.0.12**
199
+
200
+ <ul>
201
+ <li>Fix: Improve detection of plugins adding support for themes
202
+ <ul>
203
+ <li>Add support if `Plugin Name: Styles: NAME` matches `Theme Name: NAME`</li>
204
+ <li>Add support if directory names `styles-NAME` and `theme/NAME` match</li>
205
+ <li>Make theme check case-insensitive. Resolves issues for themes with capitalized folder names, like iThemes child themes.</li>
206
+ <li>Thanks [@JiveDig](http://twitter.com/jivedig) for pointing some of these issues out.</li>
207
+ </ul>
208
+ </li>
209
+ <li>Fix: Improve activation notices for child themes
210
+ <ul>
211
+ <li>Add theme options for a parent theme if they're activated, but don't show a notice requiring them.</li>
212
+ <li>Detect and display which theme a plugin is trying to add support for.</li>
213
+ <li>Correctly display the plugin name requesting activation in cases where the plugin doesn't follow the recommended naming convention.</li>
214
+ </ul>
215
+ </li>
216
+ </ul>
217
+
218
  **1.0.11**
219
 
220
  * [This release goes to 11](http://www.youtube.com/watch?v=NrVCjnRdB_k).
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.11
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.12
7
  Author: Brainstorm Media
8
  Author URI: http://brainstormmedia.com
9
  */