Widget Context - Version 1.0.2

Version Description

  • Load available custom post types and taxonomies right before visibility checks to avoid PHP warnings.
  • Run visibility checks only after the main post query has run. Fixes issues with WooCommerce.
  • Load our CSS and Javascript files only on widget and customizer admin pages.
Download this release

Release Info

Developer kasparsd
Plugin Icon 128x128 Widget Context
Version 1.0.2
Comparing to
See all releases

Code changes from version 1.0.1 to 1.0.2

js/widget-context.js CHANGED
@@ -18,30 +18,10 @@ jQuery(document).ready(function($) {
18
 
19
  });
20
 
21
- $('#widgets-right, #widgets-left').on( 'change', '.wc-field-select-condition select', function(){
22
 
23
  show_hide_controls( $(this).parent().data('widget-id') );
24
 
25
  });
26
 
27
- $(document).ajaxSuccess(function(e, xhr, settings) {
28
- var widget_id = get_query_arg_val( settings.data, 'widget-id' );
29
- if ( widget_id ) {
30
- show_hide_controls( widget_id );
31
- }
32
- });
33
-
34
- var get_query_arg_val = function( query, key ) {
35
- var vars = query.split('&');
36
-
37
- for ( var i=0; i<vars.length; i++ ) {
38
- pair = vars[i].split('=');
39
- if ( pair[0] == key ) {
40
- return pair[1];
41
- }
42
- }
43
-
44
- return false;
45
- };
46
-
47
  });
18
 
19
  });
20
 
21
+ $('#widgets-right, #widgets-left, #customize-theme-controls').on( 'change', '.wc-field-select-condition select', function(){
22
 
23
  show_hide_controls( $(this).parent().data('widget-id') );
24
 
25
  });
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  });
modules/custom-post-types-taxonomies/custom-cpt-tax.php CHANGED
@@ -31,9 +31,6 @@ class WidgetContextCustomCPTTax {
31
 
32
  $this->wc = widget_context::instance();
33
 
34
- // This should run really late so that all post types get registered
35
- add_action( 'wp_loaded', array( $this, 'init' ) );
36
-
37
  add_filter( 'widget_contexts', array( $this, 'add_context' ) );
38
 
39
  add_filter( 'widget_context_control-custom_post_types_taxonomies', array( $this, 'context_controls' ), 10, 2 );
@@ -43,7 +40,10 @@ class WidgetContextCustomCPTTax {
43
  }
44
 
45
 
46
- function init() {
 
 
 
47
 
48
  $this->post_types = get_post_types(
49
  array(
@@ -85,6 +85,9 @@ class WidgetContextCustomCPTTax {
85
 
86
  $status = array();
87
 
 
 
 
88
  foreach ( $this->post_types as $post_type => $post_type_settings ) {
89
 
90
  if ( isset( $settings[ 'is_singular-' . $post_type ] ) && $settings[ 'is_singular-' . $post_type ] )
@@ -117,6 +120,9 @@ class WidgetContextCustomCPTTax {
117
  $options = array();
118
  $out = array();
119
 
 
 
 
120
  foreach ( $this->post_types as $post_type => $post_type_settings ) {
121
 
122
  $options[ 'is_singular-' . $post_type ] = sprintf(
31
 
32
  $this->wc = widget_context::instance();
33
 
 
 
 
34
  add_filter( 'widget_contexts', array( $this, 'add_context' ) );
35
 
36
  add_filter( 'widget_context_control-custom_post_types_taxonomies', array( $this, 'context_controls' ), 10, 2 );
40
  }
41
 
42
 
43
+ function set_objects() {
44
+
45
+ if ( is_array( $this->post_types ) )
46
+ return;
47
 
48
  $this->post_types = get_post_types(
49
  array(
85
 
86
  $status = array();
87
 
88
+ if ( ! is_array( $this->post_types ) )
89
+ $this->set_objects();
90
+
91
  foreach ( $this->post_types as $post_type => $post_type_settings ) {
92
 
93
  if ( isset( $settings[ 'is_singular-' . $post_type ] ) && $settings[ 'is_singular-' . $post_type ] )
120
  $options = array();
121
  $out = array();
122
 
123
+ if ( ! is_array( $this->post_types ) )
124
+ $this->set_objects();
125
+
126
  foreach ( $this->post_types as $post_type => $post_type_settings ) {
127
 
128
  $options[ 'is_singular-' . $post_type ] = sprintf(
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: kasparsd, jamescollins
4
  Tags: widget, widget context, context, logic, widget logic, cms
5
  Requires at least: 3.0
6
  Tested up to: 3.9.1
7
- Stable tag: 1.0.1
8
  License: GPLv2 or later
9
 
10
  Show or hide widgets on specific posts, pages or sections of your site.
@@ -30,6 +30,11 @@ Widget Context allows you to show or hide widgets on certain sections of your si
30
 
31
  == Changelog ==
32
 
 
 
 
 
 
33
  = 1.0.1 =
34
  * Fix PHP warning in custom post type and taxonomy module.
35
 
@@ -97,6 +102,9 @@ Widget Context allows you to show or hide widgets on certain sections of your si
97
 
98
  == Upgrade Notice ==
99
 
 
 
 
100
  = 1.0.1 =
101
 
102
  Fix PHP warning in custom post type and taxonomy module.
4
  Tags: widget, widget context, context, logic, widget logic, cms
5
  Requires at least: 3.0
6
  Tested up to: 3.9.1
7
+ Stable tag: 1.0.2
8
  License: GPLv2 or later
9
 
10
  Show or hide widgets on specific posts, pages or sections of your site.
30
 
31
  == Changelog ==
32
 
33
+ = 1.0.2 =
34
+ * Load available custom post types and taxonomies right before visibility checks to avoid PHP warnings.
35
+ * Run visibility checks only after the main post query has run. Fixes issues with WooCommerce.
36
+ * Load our CSS and Javascript files only on widget and customizer admin pages.
37
+
38
  = 1.0.1 =
39
  * Fix PHP warning in custom post type and taxonomy module.
40
 
102
 
103
  == Upgrade Notice ==
104
 
105
+ = 1.0.2 =
106
+ Load available custom post types and taxonomies right before visibility checks to avoid PHP warnings. Run visibility checks only after the main post query has run. Fixes issues with WooCommerce.
107
+
108
  = 1.0.1 =
109
 
110
  Fix PHP warning in custom post type and taxonomy module.
widget-context.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Widget Context
4
  Plugin URI: http://wordpress.org/extend/plugins/widget-context/
5
  Description: Show or hide widgets depending on the section of the site that is being viewed.
6
- Version: 1.0.1
7
  Author: Kaspars Dambis
8
  Author URI: http://kaspars.net
9
  Text Domain: widget-context
@@ -54,7 +54,7 @@ class widget_context {
54
 
55
  // Append Widget Context settings to widget controls
56
  add_action( 'in_widget_form', array( $this, 'widget_context_controls' ), 10, 3 );
57
-
58
  // Add admin menu for config
59
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
60
 
@@ -167,8 +167,12 @@ class widget_context {
167
  }
168
 
169
 
170
- function admin_scripts() {
171
-
 
 
 
 
172
  wp_enqueue_style(
173
  'widget-context-css',
174
  plugins_url( 'css/admin.css', plugin_basename( __FILE__ ) )
@@ -242,8 +246,9 @@ class widget_context {
242
 
243
  function maybe_unset_widgets_by_context( $sidebars_widgets ) {
244
 
245
- // Don't run this on the backend
246
- if ( is_admin() )
 
247
  return $sidebars_widgets;
248
 
249
  // Return from cache if we have done the context checks already
3
  Plugin Name: Widget Context
4
  Plugin URI: http://wordpress.org/extend/plugins/widget-context/
5
  Description: Show or hide widgets depending on the section of the site that is being viewed.
6
+ Version: 1.0.2
7
  Author: Kaspars Dambis
8
  Author URI: http://kaspars.net
9
  Text Domain: widget-context
54
 
55
  // Append Widget Context settings to widget controls
56
  add_action( 'in_widget_form', array( $this, 'widget_context_controls' ), 10, 3 );
57
+
58
  // Add admin menu for config
59
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
60
 
167
  }
168
 
169
 
170
+ function admin_scripts( $page ) {
171
+
172
+ // Enqueue only on widgets and customizer view
173
+ if ( ! in_array( $page, array( 'widgets.php', 'settings_page_widget_context_settings' ) ) )
174
+ return;
175
+
176
  wp_enqueue_style(
177
  'widget-context-css',
178
  plugins_url( 'css/admin.css', plugin_basename( __FILE__ ) )
246
 
247
  function maybe_unset_widgets_by_context( $sidebars_widgets ) {
248
 
249
+ // Don't run this at the backend or before
250
+ // post query has been run
251
+ if ( is_admin() || ! did_action( 'parse_query' ) )
252
  return $sidebars_widgets;
253
 
254
  // Return from cache if we have done the context checks already