From 644930cf06047ce333df012cb494254dbf56071f Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Sat, 20 Jan 2018 11:21:04 +0200 Subject: [PATCH 1/6] Centralize plugin path ref --- class/class-widget-context.php | 17 +++++++---------- {class/debug => debug}/debug-bar.php | 0 {class/debug => debug}/debug.js | 0 3 files changed, 7 insertions(+), 10 deletions(-) rename {class/debug => debug}/debug-bar.php (100%) rename {class/debug => debug}/debug.js (100%) diff --git a/class/class-widget-context.php b/class/class-widget-context.php index bda8083..dac3e01 100644 --- a/class/class-widget-context.php +++ b/class/class-widget-context.php @@ -37,7 +37,7 @@ static function instance() { * Use widget_context::instance() instead. */ private function __construct() { - // Not used. + $this->plugin_path = dirname( dirname( __FILE__ ) ); } /** @@ -92,11 +92,8 @@ function define_widget_contexts() { ) ); - // Initialize core modules - $include_path = plugin_dir_path( __FILE__ ); - foreach ( $this->core_modules as $module ) { - $module_file = sprintf( '%smodules/%s/module.php', $include_path, $module ); + $module_file = sprintf( '%s/class/modules/%s/module.php', $this->plugin_path, $module ); if ( file_exists( $module_file ) ) { include $module_file; @@ -201,7 +198,7 @@ function set_widget_contexts_frontend() { function init_l10n() { - load_plugin_textdomain( 'widget-context', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); + load_plugin_textdomain( 'widget-context', false, basename( $this->plugin_path ) . '/languages' ); } @@ -214,14 +211,14 @@ function admin_scripts( $page ) { wp_enqueue_style( 'widget-context-css', - plugins_url( '../css/admin.css', plugin_basename( __FILE__ ) ), + plugins_url( 'css/admin.css', $this->plugin_path ), null, $this->asset_version ); wp_enqueue_script( 'widget-context-js', - plugins_url( '../js/widget-context.js', plugin_basename( __FILE__ ) ), + plugins_url( 'js/widget-context.js', $this->plugin_path ), array( 'jquery' ), $this->asset_version ); @@ -1013,7 +1010,7 @@ public function get_sidebars_widgets_copy() { function widget_context_debug_bar_init( $panels ) { - include plugin_dir_path( __FILE__ ) . 'debug/debug-bar.php'; + include $this->plugin_path . '/debug/debug-bar.php'; if ( class_exists( 'Debug_Widget_Context' ) ) $panels[] = new Debug_Widget_Context(); @@ -1027,7 +1024,7 @@ function widget_context_debug_bar_scripts() { wp_enqueue_script( 'widget-context-debug-js', - plugins_url( 'debug/debug.js', plugin_basename( __FILE__ ) ), + plugins_url( 'debug/debug.js', $this->plugin_path ), array( 'jquery' ) ); diff --git a/class/debug/debug-bar.php b/debug/debug-bar.php similarity index 100% rename from class/debug/debug-bar.php rename to debug/debug-bar.php diff --git a/class/debug/debug.js b/debug/debug.js similarity index 100% rename from class/debug/debug.js rename to debug/debug.js From 7d952f40037191217463a81a10f3c0a0bb3ba9c7 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Sat, 20 Jan 2018 11:26:23 +0200 Subject: [PATCH 2/6] Add release meta --- readme.md | 4 ++++ widget-context.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index dc3b161..1a784e4 100644 --- a/readme.md +++ b/readme.md @@ -29,6 +29,10 @@ Widget Context allows you to show or hide widgets on certain sections of your si ## Changelog +### 1.0.6 (January 20, 2018) +* Fix path to admin scripts and styles, props [@tedgeving](https://github.com/kasparsd/widget-context-wporg/pull/32). +* Mark as tested with WordPress 4.9.2. + ### 1.0.5 (May 8, 2017) * Confirm the plugin works with the latest version of WordPress. * Add support for continuous testing via [wp-dev-lib](https://github.com/xwp/wp-dev-lib). diff --git a/widget-context.php b/widget-context.php index 531194d..d3f16ae 100644 --- a/widget-context.php +++ b/widget-context.php @@ -3,7 +3,7 @@ * Plugin Name: Widget Context * Plugin URI: https://widgetcontext.com * Description: Show or hide widgets depending on the section of the site that is being viewed. - * Version: 1.0.5 + * Version: 1.0.6 * Author: Kaspars Dambis * Author URI: https://kaspars.net * Text Domain: widget-context From a4ff0339b9bc6e86a18e585579c3f13fcabcd53c Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Sat, 20 Jan 2018 11:26:33 +0200 Subject: [PATCH 3/6] Bumpt tested WP --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 1a784e4..da19438 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ Contributors: kasparsd, jamescollins Tags: widget, widget context, context, logic, widget logic, cms Requires at least: 3.0 -Tested up to: 4.9.1 +Tested up to: 4.9.2 Stable tag: trunk License: GPLv2 or later From aa711c920b5a1ef48a60cb503e8a2bdd78261f8a Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Sat, 20 Jan 2018 12:20:21 +0200 Subject: [PATCH 4/6] Adjust the asset path --- class/class-widget-context.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/class/class-widget-context.php b/class/class-widget-context.php index dac3e01..4d5f99d 100644 --- a/class/class-widget-context.php +++ b/class/class-widget-context.php @@ -206,19 +206,22 @@ function init_l10n() { function admin_scripts( $page ) { // Enqueue only on widgets and customizer view - if ( ! in_array( $page, array( 'widgets.php', 'settings_page_widget_context_settings' ) ) ) + if ( ! in_array( $page, array( 'widgets.php', 'settings_page_widget_context_settings' ), true ) ) { return; + } + + $plugin_basename = plugin_basename( $this->plugin_path ); wp_enqueue_style( 'widget-context-css', - plugins_url( 'css/admin.css', $this->plugin_path ), + plugins_url( $plugin_basename . '/css/admin.css' ), null, $this->asset_version ); wp_enqueue_script( 'widget-context-js', - plugins_url( 'js/widget-context.js', $this->plugin_path ), + plugins_url( $plugin_basename . '/js/widget-context.js' ), array( 'jquery' ), $this->asset_version ); From 82ab90b3898898acadd637e46869f2e94fa2692d Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Sat, 20 Jan 2018 12:22:59 +0200 Subject: [PATCH 5/6] Fix debug bar asset path --- class/class-widget-context.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/class-widget-context.php b/class/class-widget-context.php index 4d5f99d..a1450cf 100644 --- a/class/class-widget-context.php +++ b/class/class-widget-context.php @@ -1027,7 +1027,7 @@ function widget_context_debug_bar_scripts() { wp_enqueue_script( 'widget-context-debug-js', - plugins_url( 'debug/debug.js', $this->plugin_path ), + plugins_url( plugin_basename( $this->plugin_path ) . '/debug/debug.js' ), array( 'jquery' ) ); From b892f4d331666606bcb783af85231bebb956dea3 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Sat, 20 Jan 2018 16:59:03 +0200 Subject: [PATCH 6/6] Introduce a helper for plugin asset URLs --- class/class-widget-context.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/class/class-widget-context.php b/class/class-widget-context.php index a1450cf..a6105c3 100644 --- a/class/class-widget-context.php +++ b/class/class-widget-context.php @@ -210,18 +210,16 @@ function admin_scripts( $page ) { return; } - $plugin_basename = plugin_basename( $this->plugin_path ); - wp_enqueue_style( 'widget-context-css', - plugins_url( $plugin_basename . '/css/admin.css' ), + $this->asset_url( '/css/admin.css' ), null, $this->asset_version ); wp_enqueue_script( 'widget-context-js', - plugins_url( $plugin_basename . '/js/widget-context.js' ), + $this->asset_url( '/js/widget-context.js' ), array( 'jquery' ), $this->asset_version ); @@ -1027,11 +1025,22 @@ function widget_context_debug_bar_scripts() { wp_enqueue_script( 'widget-context-debug-js', - plugins_url( plugin_basename( $this->plugin_path ) . '/debug/debug.js' ), + $this->asset_url( '/debug/debug.js' ), array( 'jquery' ) ); } + /** + * Return the public URL of a plugin asset file. + * + * @param string $asset_relative_path Relative path to the asset file. + * + * @return string + */ + function asset_url( $asset_relative_path ) { + return plugins_url( plugin_basename( $this->plugin_path ) . $asset_relative_path ); + } + }