forked from setola/Wordpress-Theme-Utils-Classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThemeUtils.class.php
232 lines (200 loc) · 6.19 KB
/
ThemeUtils.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
/**
* Stores the code for the parent theme setting initialization and management
*/
/**
* Initializes and manages the parent theme config and constants
* @author etessore
* @version 1.0.0
* @package classes
*/
class ThemeUtils{
/**
* Stores the unique instance
* @var ThemeUtils
*/
private static $instance = null;
/**
* Stores the dir name of PHP classes
* @var string
*/
const WORDPRESS_THEME_UTILS_CLASS_DIR = 'classes';
/**
* Initializes default settings
* Singleton private constructor
*/
private function __construct(){
self::default_constants();
//self::enable_autoload_system();
//self::disable_debug();
//self::register_main_menu();
//self::register_bottom_menu();
self::register_text_domain();
self::$instance = $this;
}
/**
* Register the wtu-framework text domain to WordPress
*/
public static function register_text_domain(){
load_theme_textdomain('wtu_framework', WORDPRESS_THEME_UTILS_PATH.'/languages');
}
/**
* Gets the instance with the current options set
* @return ThemeUtils current instance
*/
public static function get_instance(){
if(is_null(self::$instance)){
self::$instance = new self();
}
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')) {
self::include_once_file_if_exists(WORDPRESS_THEME_UTILS_PATH . WORDPRESS_THEME_UTILS_AUTOLOADER_RELATIVE_PATH);
}
if(class_exists('ClassAutoloader')) {
ClassAutoloader::get_instance()
// First search in the child theme dir
->add_loading_template(
get_stylesheet_directory().'/'
.WORDPRESS_THEME_UTILS_DIRNAME
.'/%classname%.class.php'
)
// then search into the parent theme dir
->add_loading_template(
get_template_directory().'/'
.WORDPRESS_THEME_UTILS_DIRNAME
.'/%classname%.class.php'
);
}
}
/**
* Registers the Primary Menu to WordPress
* @param string $label the label for the menu
*/
public static function register_main_menu($label=''){
register_nav_menu('primary', (empty($label)) ? __('Primary Menu', 'theme') : $label);
}
/**
* Register the Secondary Menu to WordPress
* @param string $label the label for the menu
*/
public static function register_bottom_menu($label=''){
register_nav_menu('secondary', (empty($label)) ? __('Secondary Menu', 'theme'): $label);
}
/**
* Enables vd()\vc()\v() functions output,
* This is generically good for development environments.
*/
public static function enable_debug(){
$debug = DebugUtils::get_instance();
$debug->status = true;
}
/**
* Disable vd()\vc()\v() functions output,
* This is default status, generically good for production environments.
*/
public static function disable_debug(){
$debug = DebugUtils::get_instance();
$debug->status = false;
}
/**
* Enable the Lorem Ipsum body text on empty pages
*/
public static function dummy_content(){
$dummy_content = new LipsumGenerator();
$dummy_content->init()->save()->hook();
}
/**
* Register some constants
*/
public static function default_constants(){
// initialize constants only once
if(defined('WORDPRESS_THEME_UTILS_PATH')) return;
/**
* 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
*/
if(!defined('WORDPRESS_THEME_UTILS_REGISTER_TOP_MENU'))
define('WORDPRESS_THEME_UTILS_REGISTER_TOP_MENU', true);
/**
* Set to false to disable registration of Bottom Menu
*/
if(!defined('WORDPRESS_THEME_UTILS_REGISTER_BOTTOM_MENU'))
define('WORDPRESS_THEME_UTILS_REGISTER_BOTTOM_MENU', true);
/**
* Relative path for template parts
*/
if(!defined('WORDPRESS_THEME_UTILS_PARTIALS_RELATIVE_PATH'))
define('WORDPRESS_THEME_UTILS_PARTIALS_RELATIVE_PATH', 'partials/');
/**
* Path for libraries
*/
if(!defined('WORDPRESS_THEME_UTILS_LIBRARIES_RELATIVE_PATH'))
define('WORDPRESS_THEME_UTILS_LIBRARIES_RELATIVE_PATH', 'libraries/');
if(!defined('WORDPRESS_THEME_UTILS_LIBRARIES_ABSOLUTE_PATH'))
define('WORDPRESS_THEME_UTILS_LIBRARIES_ABSOLUTE_PATH', WORDPRESS_THEME_UTILS_PATH.'/libraries/');
/**
* Relative path for autoloader class
*/
if(!defined('WORDPRESS_THEME_UTILS_AUTOLOADER_RELATIVE_PATH'))
define('WORDPRESS_THEME_UTILS_AUTOLOADER_RELATIVE_PATH', '/'.WORDPRESS_THEME_UTILS_DIRNAME.'/ClassAutoloader.class.php');
}
/**
* Enables the Custom Links feature
*/
public static function enable_links_manager(){
LinksManager::getInstance();
}
/**
* Disables the loading of javascripts and csses from a template part
*/
public static function disable_automatic_assets_manager(){
global $assets;
$assets->disable_automatic_manager();
}
}
/**
* Initializes the WordPress Theme Utils.
* Use this in your child theme functions.php
*/
function wtu_init(){
ThemeUtils::get_instance();
/**
* Register some standard assets
*
* overload the global $assets variable in your child theme functions.php if you need customization on this.
* @see DefaultAssets for adding or remove assets
*/
/*global $assets;
if(empty($assets)){
$assets = new DefaultAssetsCDN();
}*/
/**
* Register runtime infos, useful for javascript
*
* Overload the global $runtime_infos in your child theme functions.php if you need customization on this.
* @see RuntimeInfos for more details
*/
/*global $runtime_infos;
if(empty($runtime_infos)){
$runtime_infos = new RuntimeInfos();
$runtime_infos->hook();
}*/
}