From 71b3021597fce3428995d7cca3b163045faeb7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Mon, 14 Dec 2015 17:19:59 +0200 Subject: [PATCH] Bugfix: make extension_url contain correct url in all cases The old code populated _extension_url with contents like https://example.org/var/www/sites/htdocs/wp-content/plugins/redux-framework/ -> ReduxCore/inc/extensions/customizer/ New implementation is does not mind if Redux is embedded in a theme or plugin, supports having WordPress installed in any directory and to avoid future bugs: the new code is clean and easy to read. For cases where wp-content is not found, fall back to old URL detection code. --- extensions/customizer/extension_customizer.php | 6 ++++++ extensions/edd/extension_edd.php | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/extensions/customizer/extension_customizer.php b/extensions/customizer/extension_customizer.php index 1b76826..e4d97e7 100644 --- a/extensions/customizer/extension_customizer.php +++ b/extensions/customizer/extension_customizer.php @@ -81,6 +81,12 @@ public function __construct( $parent ) { if ( empty( $this->extension_dir ) ) { $this->extension_dir = trailingslashit( str_replace( '\\', '/', dirname( __FILE__ ) ) ); $this->extension_url = site_url( str_replace( trailingslashit( str_replace( '\\', '/', ABSPATH ) ), '', $this->extension_dir ) ); + + // Easier to read and less buggy way to find out correct url, but applicable + // only if wp-content found. Othewise fall back to old URL detection code. + if ( preg_match("/wp-content\/(.*)/", $this->extension_dir, $match) ) { + $this->extension_url = site_url('/wp-content/'.$match[1]); + } } } diff --git a/extensions/edd/extension_edd.php b/extensions/edd/extension_edd.php index 4a9ab76..0391402 100644 --- a/extensions/edd/extension_edd.php +++ b/extensions/edd/extension_edd.php @@ -53,8 +53,14 @@ public function __construct( $parent ) { if ( empty( $this->extension_dir ) ) { $this->extension_dir = trailingslashit( str_replace( '\\', '/', dirname( __FILE__ ) ) ); $this->extension_url = site_url( str_replace( trailingslashit( str_replace( '\\', '/', ABSPATH ) ), '', $this->extension_dir ) ); + + // Easier to read and less buggy way to find out correct url, but applicable + // only if wp-content found. Othewise fall back to old URL detection code. + if ( preg_match("/wp-content\/(.*)/", $this->extension_dir, $match) ) { + $this->extension_url = site_url('/wp-content/'.$match[1]); + } } - + if ( isset( $parent->args['edd'] ) && !empty( $parent->args['edd'] ) ) { // Create defaults array