/
functions.php
196 lines (188 loc) · 7.01 KB
/
functions.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
<?php
/**
* GavernWP functions and definitions
*
* This file contains core framework operations. It is always
* loaded before the index.php file no the front-end
*
* @package WordPress
* @subpackage GavernWP
* @since GavernWP 1.0
**/
if(!function_exists('gavern_file')) {
/**
*
* Function used to get the file absolute path - useful when child theme is used
*
* @return file absolute path (in the original theme or in the child theme if file exists)
*
**/
function gavern_file($path) {
if(is_child_theme()) {
if($path == false) {
return get_stylesheet_directory();
} else {
if(is_file(get_stylesheet_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path))) {
return get_stylesheet_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);
} else {
return get_template_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);
}
}
} else {
if($path == false) {
return get_template_directory();
} else {
return get_template_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);
}
}
}
}
if(!function_exists('gavern_file_uri')) {
/**
*
* Function used to get the file URI - useful when child theme is used
*
* @return file URI (in the original theme or in the child theme if file exists)
*
**/
function gavern_file_uri($path) {
if(is_child_theme()) {
if($path == false) {
return get_stylesheet_directory_uri();
} else {
if(is_file(get_stylesheet_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path))) {
return get_stylesheet_directory_uri() . '/' . $path;
} else {
return get_template_directory_uri() . '/' . $path;
}
}
} else {
if($path == false) {
return get_template_directory_uri();
} else {
return get_template_directory_uri() . '/' . $path;
}
}
}
}
//
if(!class_exists('GavernWP')) {
// include the framework base class
require(gavern_file('gavern/base.php'));
}
// load and parse template JSON file.
$config_language = 'en_US';
if(get_locale() != '' && is_dir(get_template_directory() . '/gavern/config/'. get_locale()) && is_dir(get_template_directory() . '/gavern/options/'. get_locale())) {
$config_language = get_locale();
}
$json_data = json_decode(file_get_contents(get_template_directory() . '/gavern/config/'.$config_language.'/template.json'));
$tpl_name = strtolower(preg_replace("/[^A-Za-z0-9]/", "", $json_data->template->name));
// define constant to use with all __(), _e(), _n(), _x() and _xe() usage
define('GKTPLNAME', $tpl_name);
// create the framework object
$tpl = new GavernWP();
// Including file with helper functions
require_once(gavern_file('gavern/helpers/helpers.base.php'));
// Including file with template hooks
require_once(gavern_file('gavern/hooks.php'));
// Including file with template functions
require_once(gavern_file('gavern/functions.php'));
require_once(gavern_file('gavern/user.functions.php'));
// Including file with template filters
require_once(gavern_file('gavern/filters.php'));
// Including file with template widgets
require_once(gavern_file('gavern/widgets.comments.php'));
require_once(gavern_file('gavern/widgets.nsp.php'));
require_once(gavern_file('gavern/widgets.social.php'));
require_once(gavern_file('gavern/widgets.tabs.php'));
// Including file with template admin features
require_once(gavern_file('gavern/helpers/helpers.features.php'));
// Including file with template shortcodes
require_once(gavern_file('gavern/helpers/helpers.shortcodes.php'));
// Including file with template layout functions
require_once(gavern_file('gavern/helpers/helpers.layout.php'));
// Including file with template layout functions - connected with template fragments
require_once(gavern_file('gavern/helpers/helpers.layout.fragments.php'));
// Including file with template branding functions
require_once(gavern_file('gavern/helpers/helpers.branding.php'));
// Including file with template customize functions
require_once(gavern_file('gavern/helpers/helpers.customizer.php'));
// initialize the framework
$tpl->init();
// add theme setup function
add_action('after_setup_theme', 'gavern_theme_setup');
// Theme setup function
function gavern_theme_setup(){
// access to the global template object
global $tpl;
// variable used for redirects
global $pagenow;
// check if the themes.php address with goto variable has been used
if ($pagenow == 'themes.php' && !empty($_GET['goto'])) {
/**
*
* IMPORTANT FACT: if you're using few different redirects on a lot of subpages
* we recommend to define it as themes.php?goto=X, because if you want to
* change the URL for X, then you can change it on one place below :)
*
**/
// check the goto value
switch ($_GET['goto']) {
// make proper redirect
case 'gavick-com':
wp_redirect("http://www.gavick.com");
break;
case 'wiki':
wp_redirect("http://www.gavick.com/documentation");
break;
// or use default redirect
default:
wp_safe_redirect('/wp-admin/');
break;
}
exit;
}
// if the normal page was requested do following operations:
// load and parse template JSON file.
$json_data = $tpl->get_json('config','template');
// read the configuration
$template_config = $json_data->template;
// save the lowercase non-special characters template name
$template_name = strtolower(preg_replace("/[^A-Za-z0-9]/", "", $template_config->name));
// load the template text_domain
load_theme_textdomain( $template_name, get_stylesheet_directory() . '/languages' );
}
// scripts enqueue function
function gavern_enqueue_admin_js_and_css() {
// metaboxes scripts
wp_enqueue_script('gavern.metabox.js', gavern_file_uri('js/back-end/gavern.metabox.js'));
// widget rules JS
wp_register_script('widget-rules-js', gavern_file_uri('js/back-end/widget.rules.js'), array('jquery'));
wp_enqueue_script('widget-rules-js');
// widget rules CSS
wp_register_style('widget-rules-css', gavern_file_uri('css/back-end/widget.rules.css'));
wp_enqueue_style('widget-rules-css');
// metaboxes CSS
wp_register_style('gavern-metabox-css', gavern_file_uri('css/back-end/metabox.css'));
wp_enqueue_style('gavern-metabox-css');
// GK News Show Pro Widget back-end CSS
wp_register_style('nsp-admin-css', gavern_file_uri('css/back-end/nsp.css'));
wp_enqueue_style('nsp-admin-css');
// shortcodes database
if(
get_locale() != '' &&
is_dir(get_template_directory() . '/gavern/config/'. get_locale()) &&
is_dir(get_template_directory() . '/gavern/options/'. get_locale())
) {
$language = get_locale();
} else {
$language = 'en_US';
}
wp_enqueue_script('shortcodes.js', gavern_file_uri('gavern/config/'.$language.'/shortcodes.js'));
}
// this action enqueues scripts and styles:
// http://wpdevel.wordpress.com/2011/12/12/use-wp_enqueue_scripts-not-wp_print_styles-to-enqueue-scripts-and-styles-for-the-frontend/
add_action('admin_enqueue_scripts', 'gavern_enqueue_admin_js_and_css');
// remove the generator metatag due security reasons
remove_action('wp_head', 'wp_generator');
// EOF