-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
324 lines (265 loc) · 9.35 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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?php
/**
* Esteem functions related to defining constants, adding files and WordPress core functionality.
*
* Defining some constants, loading all the required files and Adding some core functionality.
*
* @uses add_theme_support() To add support for post thumbnails and automatic feed links.
* @uses register_nav_menu() To add support for navigation menu.
* @uses set_post_thumbnail_size() To set a custom post thumbnail size.
*
* @package ThemeGrill
* @subpackage Esteem
* @since Esteem 1.0
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 642;
}
/**
* $content_width global variable adjustment as per layout option.
*/
function esteem_content_width() {
global $post;
global $content_width;
if ( $post ) {
$layout_meta = get_post_meta( $post->ID, '_esteem_layout', true );
}
if ( empty( $layout_meta ) || is_archive() || is_search() ) {
$layout_meta = 'default_layout';
}
$esteem_default_layout = get_theme_mod( 'esteem_default_layout', 'right_sidebar' );
if ( $layout_meta == 'default_layout' ) {
if ( $esteem_default_layout == 'no_sidebar_full_width' ) {
$content_width = 978; /* pixels */
} else {
$content_width = 642; /* pixels */
}
} elseif ( $layout_meta == 'no_sidebar_full_width' ) {
$content_width = 978; /* pixels */
} else {
$content_width = 642; /* pixels */
}
}
add_action( 'template_redirect', 'esteem_content_width' );
add_action( 'after_setup_theme', 'esteem_setup' );
/**
* Enqueue block editor styles.
*
* @since Esteem 1.4.5
*/
function esteem_block_editor_styles() {
wp_enqueue_style( 'esteem-block-editor-styles', get_template_directory_uri() . '/style-editor-block.css' );
}
add_action( 'enqueue_block_editor_assets', 'esteem_block_editor_styles', 1, 1 );
if ( ! function_exists( 'esteem_setup' ) ) :
/**
* Adding the core functionality of WordPress.
*
* @since 1.0
*/
function esteem_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
*/
load_theme_textdomain( 'esteem', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// This theme uses Featured Images (also known as post thumbnails) for per-post/per-page.
add_theme_support( 'post-thumbnails' );
// Supporting title tag via add_theme_support (since WordPress 4.1)
add_theme_support( 'title-tag' );
// Gutenberg layout support.
add_theme_support( 'align-wide' );
// Add support for Block Styles.
add_theme_support( 'wp-block-styles' );
// Responsive embeds support.
add_theme_support( 'responsive-embeds' );
// Adds the support for the Custom Logo introduced in WordPress 4.5
add_theme_support(
'custom-logo',
array(
'flex-width' => true,
'flex-height' => true,
)
);
// Added WooCommerce support.
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
// Switches default core markup for comment form, and comments
// to output valid HTML5.
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
// Registering navigation menus.
register_nav_menu( 'primary', 'Primary Menu' );
// Cropping images to different sizes to be used in the theme
add_image_size( 'blog-large', 642, 300, true ); // used on blog large template
add_image_size( 'blog-medium', 306, 205, true ); // used on blog medium template
add_image_size( 'recent-thumb', 350, 316, true );
add_image_size( 'service-featured', 600, 330, true );
// Setup the WordPress core custom background feature.
add_theme_support(
'custom-background',
apply_filters(
'esteem_custom_background_args',
array(
'default-color' => 'eaeaea',
)
)
);
// Adding excerpt option box for pages as well
add_post_type_support( 'page', 'excerpt' );
}
endif;
add_action( 'after_setup_theme', 'esteem_options_migrate', 12 );
if ( ! function_exists( 'esteem_options_migrate' ) ) :
/**
* Migrate Options Framework data to Customizer
*
*/
function esteem_options_migrate() {
// Shifting Users data from Theme Option to Customizer
if ( get_option( 'esteem_customizer_transfer' ) ) {
return;
}
// Set transfer
update_option( 'esteem_customizer_transfer', 1 );
$esteem_themename = get_option( 'stylesheet' );
$esteem_themename_preg = preg_replace( '/\W/', '_', strtolower( $esteem_themename ) );
if ( false === ( $mods = get_option( $esteem_themename_preg ) ) ) {
return;
}
$esteem_theme_options = array();
$esteem_theme_mods = array();
// When child theme is active.
if ( is_child_theme() ) {
$esteem_theme_options = get_option( $esteem_themename_preg );
$esteem_theme_mods = get_theme_mods();
foreach ( $esteem_theme_options as $key => $value ) {
$esteem_theme_mods[ $key ] = $value;
}
update_option( 'theme_mods_' . $esteem_themename, $esteem_theme_mods );
}
// For parent theme data Transfer
if ( false !== ( $mods = get_option( 'esteem' ) ) ) {
$esteem_theme_options = get_option( 'esteem' );
$esteem_theme_mods = get_option( 'theme_mods_esteem' );
foreach ( $esteem_theme_options as $key => $value ) {
$esteem_theme_mods[ $key ] = $value;
}
update_option( 'theme_mods_esteem', $esteem_theme_mods );
}
}
endif;
/**
* esteem_init hook
*
* Hooking some functions of functions.php file to this action hook.
*/
add_action( 'esteem_init', 'esteem_constants', 10 );
if ( ! function_exists( 'esteem_constants' ) ) {
/**
* This function defines the Esteem theme constants
*
* @since 1.0
*/
function esteem_constants() {
/**
* Define Directory Location Constants
*/
define( 'ESTEEM_PARENT_DIR', get_template_directory() );
define( 'ESTEEM_CHILD_DIR', get_stylesheet_directory() );
define( 'ESTEEM_IMAGES_DIR', ESTEEM_PARENT_DIR . '/images' );
define( 'ESTEEM_INCLUDES_DIR', ESTEEM_PARENT_DIR . '/inc' );
define( 'ESTEEM_CSS_DIR', ESTEEM_PARENT_DIR . '/css' );
define( 'ESTEEM_JS_DIR', ESTEEM_PARENT_DIR . '/js' );
define( 'ESTEEM_LANGUAGES_DIR', ESTEEM_PARENT_DIR . '/languages' );
define( 'ESTEEM_ADMIN_DIR', ESTEEM_INCLUDES_DIR . '/admin' );
define( 'ESTEEM_EXTENSIONS_DIR', ESTEEM_INCLUDES_DIR . '/extensions' );
define( 'ESTEEM_SHORTCODES_DIR', ESTEEM_INCLUDES_DIR . '/shortcodes' );
define( 'ESTEEM_WIDGETS_DIR', ESTEEM_INCLUDES_DIR . '/widgets' );
define( 'ESTEEM_ADMIN_IMAGES_DIR', ESTEEM_ADMIN_DIR . '/images' );
define( 'ESTEEM_ADMIN_JS_DIR', ESTEEM_ADMIN_DIR . '/js' );
define( 'ESTEEM_ADMIN_CSS_DIR', ESTEEM_ADMIN_DIR . '/css' );
define( 'ESTEEM_FONTAWESOME_DIR', ESTEEM_PARENT_DIR . '/fontawesome' );
/**
* Define URL Location Constants
*/
define( 'ESTEEM_PARENT_URL', get_template_directory_uri() );
define( 'ESTEEM_CHILD_URL', get_stylesheet_directory_uri() );
define( 'ESTEEM_IMAGES_URL', ESTEEM_PARENT_URL . '/images' );
define( 'ESTEEM_INCLUDES_URL', ESTEEM_PARENT_URL . '/inc' );
define( 'ESTEEM_CSS_URL', ESTEEM_PARENT_URL . '/css' );
define( 'ESTEEM_JS_URL', ESTEEM_PARENT_URL . '/js' );
define( 'ESTEEM_LANGUAGES_URL', ESTEEM_PARENT_URL . '/languages' );
define( 'ESTEEM_ADMIN_URL', ESTEEM_INCLUDES_URL . '/admin' );
define( 'ESTEEM_EXTENSIONS_URL', ESTEEM_INCLUDES_URL . '/extensions' );
define( 'ESTEEM_SHORTCODES_URL', ESTEEM_INCLUDES_URL . '/shortcodes' );
define( 'ESTEEM_WIDGETS_URL', ESTEEM_INCLUDES_URL . '/widgets' );
define( 'ESTEEM_ADMIN_IMAGES_URL', ESTEEM_ADMIN_URL . '/images' );
define( 'ESTEEM_ADMIN_JS_URL', ESTEEM_ADMIN_URL . '/js' );
define( 'ESTEEM_ADMIN_CSS_URL', ESTEEM_ADMIN_URL . '/css' );
}
}
add_action( 'esteem_init', 'esteem_include_files', 15 );
if ( ! function_exists( 'esteem_include_files' ) ) {
/**
* Including the required files.
*
* @since 1.0
*/
function esteem_include_files() {
/** Load functions */
require_once ESTEEM_INCLUDES_DIR . '/functions.php';
/**
* Admin.
*/
if ( is_admin() ) {
require_once ESTEEM_ADMIN_DIR . '/class-esteem-dashboard.php';
}
require_once ESTEEM_INCLUDES_DIR . '/custom-header.php';
require_once ESTEEM_FONTAWESOME_DIR . '/icons.php';
require_once ESTEEM_ADMIN_DIR . '/meta-boxes.php';
/** Load Extensions files */
require_once ESTEEM_INCLUDES_DIR . '/header-functions.php';
/** Load Widgets and Widgetized Area */
require_once ESTEEM_WIDGETS_DIR . '/widgets.php';
/** Customizer */
require_once ESTEEM_INCLUDES_DIR . '/customizer.php';
}
}
do_action( 'esteem_init' );
/**
* Assign the Esteem version to a variable.
*/
$esteem_theme = wp_get_theme( 'esteem' );
define( 'ESTEEM_THEME_VERSION', $esteem_theme->get( 'Version' ) );
/**
* Calling in the admin area for the Welcome Page as well as for the new theme notice too.
*/
if ( is_admin() ) {
require ESTEEM_ADMIN_DIR . '/class-esteem-admin.php';
require ESTEEM_ADMIN_DIR . '/class-esteem-notice.php';
require ESTEEM_ADMIN_DIR . '/class-esteem-welcome-notice.php';
require ESTEEM_ADMIN_DIR . '/class-esteem-upgrade-notice.php';
require ESTEEM_ADMIN_DIR . '/class-esteem-theme-review-notice.php';
}
/**
* Load Jetpack compatibility file.
*/
if ( defined( 'JETPACK__VERSION' ) ) {
require_once ESTEEM_INCLUDES_DIR . '/jetpack.php';
}