-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
360 lines (288 loc) · 12.7 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
/**
* Businessx Functions
* ------
* If you want to add/edit functions please use a child theme
* http://codex.wordpress.org/Child_Themes
* ------
*/
/* ------------------------------------ *
* Define some constants
/* ------------------------------------ */
if( ! defined( 'BUSINESSX_VERSION' ) ) {
define( 'BUSINESSX_VERSION', '1.0.5.7' ); }
if( ! defined( 'BUSINESSX_AC_URL' ) ) {
define( 'BUSINESSX_AC_URL', '//www.acosmin.com/' ); }
if( ! defined( 'BUSINESSX_AC_DOCS_URL' ) && defined( 'BUSINESSX_AC_URL' ) ) {
define( 'BUSINESSX_AC_DOCS_URL', BUSINESSX_AC_URL . 'documentation/businessx/' ); }
if( ! defined( 'BUSINESSX_CUSTOMIZER_PATH' ) ) {
define( 'BUSINESSX_CUSTOMIZER_PATH', trailingslashit( get_template_directory() ) . 'acosmin/customizer/' ); }
if( ! defined( 'BUSINESSX_FUNCTIONS_PATH' ) ) {
define( 'BUSINESSX_FUNCTIONS_PATH', trailingslashit( get_template_directory() ) . 'acosmin/functions/' ); }
if( ! defined( 'BUSINESSX_PARTIALS_PATH' ) ) {
define( 'BUSINESSX_PARTIALS_PATH', trailingslashit( get_template_directory() ) . 'partials/' ); }
/* ------------------------------------------------------------------------- *
* Required Files
/* ------------------------------------------------------------------------- */
require_once ( BUSINESSX_CUSTOMIZER_PATH . 'customizer.php' );
require_once ( BUSINESSX_FUNCTIONS_PATH . 'tgmpa.php' );
require_once ( BUSINESSX_FUNCTIONS_PATH . 'sanitization.php' );
require_once ( BUSINESSX_FUNCTIONS_PATH . 'helpers.php' );
require_once ( BUSINESSX_FUNCTIONS_PATH . 'preloader.php' );
require_once ( BUSINESSX_FUNCTIONS_PATH . 'post-options.php' );
require_once ( BUSINESSX_FUNCTIONS_PATH . 'page-options.php' );
require_once ( BUSINESSX_FUNCTIONS_PATH . 'product-options.php' );
require_once ( BUSINESSX_FUNCTIONS_PATH . 'portfolio-options.php' );
require_once ( BUSINESSX_PARTIALS_PATH . 'partial-template-css-classes.php' );
require_once ( BUSINESSX_PARTIALS_PATH . 'partial-template-functions.php' );
require_once ( BUSINESSX_PARTIALS_PATH . 'partial-template-helpers.php' );
require_once ( BUSINESSX_PARTIALS_PATH . 'partial-template-hooks.php' );
/* Theme setup
/* ------------------------------------ */
if ( ! function_exists( 'businessx_setup' ) ) {
function businessx_setup() {
// Make Businessx available for translation.
load_theme_textdomain( 'businessx', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Let WordPress manage the document title.
add_theme_support( 'title-tag' );
// Enable support for Post Thumbnails on posts and pages.
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1200, 0, true );
add_image_size( 'businessx-tmb-portfolio', 630, 415, true );
add_image_size( 'businessx-tmb-blog-wide', 594 );
add_image_size( 'businessx-tmb-blog-normal', 250, 250, true );
// Register locations for your menus
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'businessx' ),
'actions' => __( 'Actions Menu', 'businessx' ),
'footer' => __( 'Footer Menu', 'businessx' )
) );
// Switch default core markup for search form, comment form, and comments to output valid HTML5.
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Custom logo
add_theme_support( 'custom-logo', apply_filters( 'businessx_custom_logo___options', array(
'height' => 100,
'width' => 200,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-title' ),
) ) );
// Enable support for Custom_Headers
add_theme_support( 'custom-header', apply_filters( 'businessx_custom_header___options', array(
'width' => 1900,
'height' => 800,
'flex-height' => true,
'flex-width' => true,
'header-text' => false
)));
// This theme uses its own gallery styles.
add_filter( 'use_default_gallery_style', '__return_false' );
// Globals
global $businessx_sections;
// Add front-page sections positions
// This part is deprecated by Businessx Extensions v1.0.6, the plugin will handle this
// Keeping it for backwards compatibility with older versions of Businessx Extensions
$sections_position = get_theme_mod( 'businessx_sections_position' );
$businessx_sections = apply_filters( 'businessx_sections_filter', array() );
if( empty( $sections_position ) && ! empty( $businessx_sections ) ) {
$sections = array();
foreach( $businessx_sections as $key => $value ) {
$sections[] = 'businessx_section__' . sanitize_key( $value );
}
set_theme_mod( 'businessx_sections_position', $sections );
}
// Widgets selective refresh
add_theme_support( 'customize-selective-refresh-widgets' );
// WooCommerce theme support
add_theme_support( 'woocommerce' );
}
}
add_action( 'after_setup_theme', 'businessx_setup' );
/* Handles JavaScript detection.
/* ------------------------------------ */
if ( ! function_exists( 'businessx_javascript_detection' ) ) {
function businessx_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
}
add_action( 'wp_head', 'businessx_javascript_detection', 0 );
/* Set the content width in pixels
/* ------------------------------------ */
if ( ! function_exists( 'businessx_content_width' ) ) {
function businessx_content_width() {
$GLOBALS['content_width'] = apply_filters( 'businessx_content_width', 840 );
}
}
add_action( 'after_setup_theme', 'businessx_content_width', 0 );
/* Enqueues scripts and styles.
/* ------------------------------------ */
if ( ! function_exists( 'businessx_scripts' ) ) {
function businessx_scripts() {
// Google Fonts
wp_enqueue_style( 'businessx-fonts', businessx_fonts_setup(), array(), null );
// Theme stylesheet
wp_enqueue_style( 'businessx-style', get_stylesheet_uri(), array(), BUSINESSX_VERSION );
// Font Awesome
wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/assets/icons/css/font-awesome.min.css', array(), '4.7.0', 'all' );
// Javascript
wp_enqueue_script( 'businessx-scripts', get_template_directory_uri() . '/assets/js/scripts.js', array( 'jquery' ), '20160412', true );
// Masonry
if( is_page_template( 'template-frontpage.php') || businessx_jetpack_check( 'custom-content-types' ) ) {
wp_enqueue_script( 'jquery-masonry' ); };
// Comments Script
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); }
// Some variables
wp_localize_script(
'businessx-scripts',
'businessx_scripts_data',
apply_filters( 'businessx_frontend_js_data_filter', array(
/* Search form placeholder */
'search_placeholder' => esc_attr_x( 'Type the keywords you are searching for', 'search overlay placeholder', 'businessx' ),
'home_url' => esc_url( home_url() ),
) )
);
}
}
add_action( 'wp_enqueue_scripts', 'businessx_scripts' );
/* Widgets and Sidebars Setup
/* ------------------------------------ */
if ( ! function_exists( 'businessx_sidebars_and_widgets' ) ) {
function businessx_sidebars_and_widgets() {
// Normal sidebars
register_sidebar( array( // Index sidebar
'name' => __( 'Index Sidebar', 'businessx' ),
'id' => 'sidebar-index',
'description' => __( 'This sidebar appears where the index/arhives views are shown.', 'businessx' ),
'before_widget' => '<aside id="%1$s" class="%2$s widget clearfix">',
'after_widget' => '</aside><!-- END .widget -->',
'before_title' => '<h3 class="widget-title hs-secondary-smallest ls-min"><span>',
'after_title' => '</span></h3>',
) );
register_sidebar( array( // Posts sidebar
'name' => __( 'Posts Sidebar', 'businessx' ),
'id' => 'sidebar-single',
'description' => __( 'This sidebar appears when you view a post', 'businessx' ),
'before_widget' => '<aside id="%1$s" class="%2$s widget clearfix">',
'after_widget' => '</aside><!-- END .widget -->',
'before_title' => '<h3 class="widget-title hs-secondary-smallest ls-min"><span>',
'after_title' => '</span></h3>',
) );
register_sidebar( array( // Page sidebar
'name' => __( 'Page Sidebar', 'businessx' ),
'id' => 'sidebar-page',
'description' => __( 'This sidebar appears when you view a page', 'businessx' ),
'before_widget' => '<aside id="%1$s" class="%2$s widget clearfix">',
'after_widget' => '</aside><!-- END .widget -->',
'before_title' => '<h3 class="widget-title hs-secondary-smallest ls-min"><span>',
'after_title' => '</span></h3>',
) );
if( businessx_jetpack_check( 'custom-content-types' ) ) {
register_sidebar( array( // Portfolio sidebar
'name' => __( 'Portfolio Sidebar', 'businessx' ),
'id' => 'sidebar-portfolio',
'description' => __( 'This sidebar appears when you view a Jetpack Portfolio item', 'businessx' ),
'before_widget' => '<aside id="%1$s" class="%2$s widget clearfix">',
'after_widget' => '</aside><!-- END .widget -->',
'before_title' => '<h3 class="widget-title hs-secondary-smallest ls-min"><span>',
'after_title' => '</span></h3>',
) ); }
// Footer sidebars
register_sidebar( array( // Footer #1 sidebar
'name' => __( 'Footer #1 Sidebar', 'businessx' ),
'id' => 'sidebar-footer-1',
'description' => __( 'First footer sidebar', 'businessx' ),
'before_widget' => '<aside id="%1$s" class="%2$s widget clearfix">',
'after_widget' => '</aside><!-- END .widget -->',
'before_title' => '<h3 class="widget-title hs-secondary-smallest ls-min"><span>',
'after_title' => '</span></h3>',
) );
register_sidebar( array( // Footer #2 sidebar
'name' => __( 'Footer #2 Sidebar', 'businessx' ),
'id' => 'sidebar-footer-2',
'description' => __( 'Second footer sidebar', 'businessx' ),
'before_widget' => '<aside id="%1$s" class="%2$s widget clearfix">',
'after_widget' => '</aside><!-- END .widget -->',
'before_title' => '<h3 class="widget-title hs-secondary-smallest ls-min"><span>',
'after_title' => '</span></h3>',
) );
register_sidebar( array( // Footer #3 sidebar
'name' => __( 'Footer #3 Sidebar', 'businessx' ),
'id' => 'sidebar-footer-3',
'description' => __( 'Third footer sidebar', 'businessx' ),
'before_widget' => '<aside id="%1$s" class="%2$s widget clearfix">',
'after_widget' => '</aside><!-- END .widget -->',
'before_title' => '<h3 class="widget-title hs-secondary-smallest ls-min"><span>',
'after_title' => '</span></h3>',
) );
if( businessx_wco_is_activated() ) {
register_sidebar( array( // Shop sidebar
'name' => __( 'Shop Sidebar', 'businessx' ),
'id' => 'sidebar-shop',
'description' => __( 'Shop sidebar - index/archive view', 'businessx' ),
'before_widget' => '<aside id="%1$s" class="%2$s widget clearfix">',
'after_widget' => '</aside><!-- END .widget -->',
'before_title' => '<h3 class="widget-title hs-secondary-smallest ls-min"><span>',
'after_title' => '</span></h3>',
) );
}
}
}
add_action( 'widgets_init', 'businessx_sidebars_and_widgets', 20 );
/* Google fonts
/* ------------------------------------ */
if ( ! function_exists( 'businessx_fonts_setup' ) ) {
function businessx_fonts_setup() {
$fonts_url = '';
$fonts = array();
$subsets = apply_filters( 'businessx_fonts___subsets', $subsets = 'latin,latin-ext' );
// Default fonts
$fonts[] = 'Poppins:400,700,300';
$fonts[] = 'Roboto:400,300,700,900,300italic,400italic,700italic';
$fonts = apply_filters( 'businessx_fonts___family', $fonts );
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urlencode( implode( '|', array_map( 'esc_attr', $fonts ) ) ),
'subset' => urlencode( esc_attr( $subsets ) ),
), 'https://fonts.googleapis.com/css' );
}
return $fonts_url;
}
}
/* TGM - Recommended plugins
/* ------------------------------------ */
if ( ! function_exists( 'businessx_register_required_plugins' ) ) {
function businessx_register_required_plugins() {
$plugins = array(
array(
'name' => 'Businessx Extensions',
'slug' => 'businessx-extensions',
'required' => false,
),
array(
'name' => 'Jetpack by WordPress.com',
'slug' => 'jetpack',
'required' => false,
),
);
$config = array(
'id' => 'businessx',
'default_path' => '',
'menu' => 'tgmpa-install-plugins',
'has_notices' => true,
'dismissable' => true,
'dismiss_msg' => '',
'is_automatic' => false,
'message' => '',
);
tgmpa( $plugins, $config );
}
}
add_action( 'tgmpa_register', 'businessx_register_required_plugins' );