Skip to content

Commit

Permalink
Proper file path using WP Functions when possible. Also allows for sy…
Browse files Browse the repository at this point in the history
…mbolic links in the plugins directory.
  • Loading branch information
dovy committed Aug 15, 2014
1 parent 1289ba8 commit 93a4277
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ Send me an email at ghost1227@reduxframework.com so I can add you to our user sp

### Master ###

= 3.3.6.3 =
* Modified: How Redux paths are run. Should cover all use cases now. Child themes can also embed Redux properly now.

= 3.3.6.2 =
* Modified: How we declare the uploads directory and URL. Using core WP functions now.

Expand Down
59 changes: 37 additions & 22 deletions ReduxCore/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ReduxFramework {
// ATTENTION DEVS
// Please update the build number with each push, no matter how small.
// This will make for easier support when we ask users what version they are using.
public static $_version = '3.3.6.2';
public static $_version = '3.3.6.3';
public static $_dir;
public static $_url;
public static $_upload_dir;
Expand All @@ -75,33 +75,48 @@ class ReduxFramework {
public static $_as_plugin = false;

public static function init() {

$dir = Redux_Helpers::cleanFilePath( dirname( __FILE__ ) );
// Windows-proof constants: replace backward by forward slashes. Thanks to: @peterbouwmeester
self::$_dir = trailingslashit( Redux_Helpers::cleanFilePath( dirname( __FILE__ ) ) );
// Check if plugin is a symbolic link, see if it's a plugin. If embedded, we can't do a thing.
if ( strpos( self::$_dir, ABSPATH ) === false ) {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
foreach ( get_plugins() as $key => $value ) {
if ( strpos( $key, 'redux-framework.php' ) !== false ) {
self::$_dir = trailingslashit( Redux_Helpers::cleanFilePath( WP_CONTENT_DIR . '/plugins/' . plugin_dir_path( $key ) . 'ReduxCore/' ) );
}
}
}

$wp_content_dir = trailingslashit( Redux_Helpers::cleanFilePath( WP_CONTENT_DIR ) );
$wp_content_dir = trailingslashit( str_replace( '//', '/', $wp_content_dir ) );
$relative_url = str_replace( $wp_content_dir, '', self::$_dir );
self::$_dir = trailingslashit( $dir );
self::$wp_content_url = trailingslashit( Redux_Helpers::cleanFilePath( ( is_ssl() ? str_replace( 'http://', 'https://', WP_CONTENT_URL ) : WP_CONTENT_URL ) ) );
self::$_url = self::$wp_content_url . $relative_url;

// See if Redux is a plugin or not
if ( strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( get_stylesheet_directory() ) ) !== false ) {
if ( strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( get_stylesheet_directory() ) ) !== false || strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( get_template_directory_uri() ) ) !== false ) {
self::$_is_plugin = false;
} else {
// Check if plugin is a symbolic link, see if it's a plugin. If embedded, we can't do a thing.
if ( strpos( self::$_dir, ABSPATH ) === false ) {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$is_plugin = false;
foreach ( get_plugins() as $key => $value ) {
if ( strpos( $key, 'redux-framework.php' ) !== false ) {
self::$_dir = trailingslashit( Redux_Helpers::cleanFilePath( WP_CONTENT_DIR . '/plugins/' . plugin_dir_path( $key ) . 'ReduxCore/' ) );
$is_plugin = true;
}
}
if ( ! $is_plugin ) {
self::$_is_plugin = false;
}
}
}
if ( self::$_is_plugin == true || self::$_as_plugin == true ) {
self::$_url = plugin_dir_url( __FILE__ );
} else {
if ( strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( get_template_directory_uri() ) ) !== false ) {
$relative_url = str_replace( get_template_directory_uri(), '', self::$_dir );
self::$_url = get_stylesheet_directory_uri() . $relative_url;
} else if ( strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( get_stylesheet_directory() ) ) !== false ) {
$relative_url = str_replace( get_stylesheet_directory(), '', self::$_dir );
self::$_url = get_stylesheet_directory_uri() . $relative_url;
} else {
$wp_content_dir = trailingslashit( Redux_Helpers::cleanFilePath( WP_CONTENT_DIR ) );
$wp_content_dir = trailingslashit( str_replace( '//', '/', $wp_content_dir ) );
$relative_url = str_replace( $wp_content_dir, '', self::$_dir );
self::$_url = self::$wp_content_url . $relative_url;
}
}
}

// ::init()

public $framework_url = 'http://www.reduxframework.com/';
Expand Down
2 changes: 1 addition & 1 deletion redux-framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Description: Redux is a simple, truly extensible options framework for WordPress themes and plugins.
* Author: Team Redux
* Author URI: http://reduxframework.com
* Version: 3.3.6.2
* Version: 3.3.6.3
* Text Domain: redux-framework
* License: GPL3+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
Expand Down

0 comments on commit 93a4277

Please sign in to comment.