Skip to content

Commit

Permalink
make the classes directory name customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele Tessore committed Aug 1, 2014
1 parent ba9d724 commit 5665b80
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions ThemeUtils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,39 @@ public static function get_instance(){
return self::$instance;
}

public static function include_once_file_if_exists($file){
if(file_exists($file))
include_once $file;
}

/**
* Initializes the autoloader subsystem
*/
public static function enable_autoload_system(){
if(!class_exists('ClassAutoloader')){
include_once WORDPRESS_THEME_UTILS_PATH . WORDPRESS_THEME_UTILS_AUTOLOADER_RELATIVE_PATH;
ClassAutoloader::get_instance();
} else {
if(!class_exists('ClassAutoloader')) {
self::include_once_file_if_exists(WORDPRESS_THEME_UTILS_PATH . WORDPRESS_THEME_UTILS_AUTOLOADER_RELATIVE_PATH);
}

var_dump(get_stylesheet_directory().'/'
.WORDPRESS_THEME_UTILS_DIRNAME
.'/%classname%.class.php');

if(class_exists('ClassAutoloader')) {
ClassAutoloader::get_instance()
// First search in the child theme dir
->add_loading_template(
get_stylesheet_directory().'/'
.self::WORDPRESS_THEME_UTILS_CLASS_DIR
.WORDPRESS_THEME_UTILS_DIRNAME
.'/%classname%.class.php'
)
// then search into the parent theme dir
->add_loading_template(
get_template_directory().'/'
.self::WORDPRESS_THEME_UTILS_CLASS_DIR
.WORDPRESS_THEME_UTILS_DIRNAME
.'/%classname%.class.php'
);
}

}

/**
Expand Down Expand Up @@ -131,11 +142,17 @@ public static function default_constants(){
if(defined('WORDPRESS_THEME_UTILS_PATH')) return;

/**
* The base path for Wordpress Theme Utils
* The absolute base path for Wordpress Theme Utils
*/
if(!defined('WORDPRESS_THEME_UTILS_PATH'))
define('WORDPRESS_THEME_UTILS_PATH', dirname(dirname(__FILE__)));

/**
* The main directory name for Wordpress Theme Utils
*/
if(!defined('WORDPRESS_THEME_UTILS_DIRNAME'))
define('WORDPRESS_THEME_UTILS_DIRNAME', trim(str_replace(WORDPRESS_THEME_UTILS_PATH,'', dirname(__FILE__)),'/\\'));

/**
* Set to false to disable registration of Top Menu
*/
Expand Down Expand Up @@ -167,7 +184,7 @@ public static function default_constants(){
* Relative path for autoloader class
*/
if(!defined('WORDPRESS_THEME_UTILS_AUTOLOADER_RELATIVE_PATH'))
define('WORDPRESS_THEME_UTILS_AUTOLOADER_RELATIVE_PATH', '/classes/ClassAutoloader.class.php');
define('WORDPRESS_THEME_UTILS_AUTOLOADER_RELATIVE_PATH', '/'.WORDPRESS_THEME_UTILS_DIRNAME.'/ClassAutoloader.class.php');
}

/**
Expand Down

0 comments on commit 5665b80

Please sign in to comment.