Skip to content

Commit 71b3021

Browse files
committed
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.
1 parent bbb2d7d commit 71b3021

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

extensions/customizer/extension_customizer.php

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public function __construct( $parent ) {
8181
if ( empty( $this->extension_dir ) ) {
8282
$this->extension_dir = trailingslashit( str_replace( '\\', '/', dirname( __FILE__ ) ) );
8383
$this->extension_url = site_url( str_replace( trailingslashit( str_replace( '\\', '/', ABSPATH ) ), '', $this->extension_dir ) );
84+
85+
// Easier to read and less buggy way to find out correct url, but applicable
86+
// only if wp-content found. Othewise fall back to old URL detection code.
87+
if ( preg_match("/wp-content\/(.*)/", $this->extension_dir, $match) ) {
88+
$this->extension_url = site_url('/wp-content/'.$match[1]);
89+
}
8490
}
8591

8692
}

extensions/edd/extension_edd.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ public function __construct( $parent ) {
5353
if ( empty( $this->extension_dir ) ) {
5454
$this->extension_dir = trailingslashit( str_replace( '\\', '/', dirname( __FILE__ ) ) );
5555
$this->extension_url = site_url( str_replace( trailingslashit( str_replace( '\\', '/', ABSPATH ) ), '', $this->extension_dir ) );
56+
57+
// Easier to read and less buggy way to find out correct url, but applicable
58+
// only if wp-content found. Othewise fall back to old URL detection code.
59+
if ( preg_match("/wp-content\/(.*)/", $this->extension_dir, $match) ) {
60+
$this->extension_url = site_url('/wp-content/'.$match[1]);
61+
}
5662
}
57-
63+
5864

5965
if ( isset( $parent->args['edd'] ) && !empty( $parent->args['edd'] ) ) {
6066
// Create defaults array

0 commit comments

Comments
 (0)