-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
410 lines (351 loc) · 13.8 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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?php
/**
* Suffice functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package ThemeGrill
* @subpackage Suffice
* @since Suffice 1.0.0
*/
if ( ! function_exists( 'suffice_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function suffice_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on suffice, use a find and replace
* to change 'suffice' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'suffice', 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.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
/**
* Image sizes
*
* Make sure height and width are double to make sure it comes in srcset
*/
add_image_size( 'suffice-thumbnail-grid', 750, 420, true );
// Image size for featured posts.
add_image_size( 'suffice-thumbnail-featured-one', 295, 525, true );
add_image_size( 'suffice-thumbnail-featured-two', 1140, 504, true );
// Image size for portfolio.
add_image_size( 'suffice-thumbnail-portfolio', 572, 552, true );
add_image_size( 'suffice-thumbnail-portfolio-masonry', 572, 652, true );
// This theme uses wp_nav_menu() in one location.
register_nav_menus(
array(
'primary' => esc_html__( 'Primary', 'suffice' ),
'social' => esc_html__( 'Social', 'suffice' ),
'footer' => esc_html__( 'Footer', 'suffice' ),
)
);
/*
* 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',
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Add theme support for woocommerce.
add_theme_support( 'woocommerce' );
// Add theme support for woocommerce product gallery added in WooCommerce 3.0.
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-slider' );
// Add theme support for custom logo.
add_theme_support( 'custom-logo' );
// Add theme support for SiteOrigin Page Builder.
add_theme_support(
'siteorigin-panels',
array(
'margin-bottom' => 30,
'recommended-widgets' => false,
)
);
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, and column width.
*/
add_editor_style( array( 'editor-style.css', suffice_fonts_url() ) );
// 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' );
}
endif;
add_action( 'after_setup_theme', 'suffice_setup' );
if ( ! function_exists( 'suffice_content_width' ) ) :
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function suffice_content_width() {
$content_width = 760;
if ( 'full-width' === suffice_get_current_layout() ) {
$content_width = 1140;
}
$GLOBALS['content_width'] = apply_filters( 'suffice_content_width', $content_width );
}
endif;
add_action( 'template_redirect', 'suffice_content_width', 0 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function suffice_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar Left', 'suffice' ),
'id' => 'sidebar-left',
'description' => esc_html__( 'Add widgets here.', 'suffice' ),
'before_widget' => '<section id="%1$s" class="widget ' . suffice_get_widget_class() . ' %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Sidebar Right', 'suffice' ),
'id' => 'sidebar-right',
'description' => esc_html__( 'Add widgets here.', 'suffice' ),
'before_widget' => '<section id="%1$s" class="widget ' . suffice_get_widget_class() . ' %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer Sidebar 1', 'suffice' ),
'id' => 'footer-sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'suffice' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer Sidebar 2', 'suffice' ),
'id' => 'footer-sidebar-2',
'description' => esc_html__( 'Add widgets here.', 'suffice' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer Sidebar 3', 'suffice' ),
'id' => 'footer-sidebar-3',
'description' => esc_html__( 'Add widgets here.', 'suffice' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer Sidebar 4', 'suffice' ),
'id' => 'footer-sidebar-4',
'description' => esc_html__( 'Add widgets here.', 'suffice' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'suffice_widgets_init' );
/**
* Registers google fonts.
*/
if ( ! function_exists( 'suffice_fonts_url' ) ) :
function suffice_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/**
* Translators: If there are characters in your language that are not
* supported by Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'suffice' ) ) {
$fonts[] = 'Open Sans:400,400i,700,700i';
}
/**
* Translators: If there are characters in your language that are not
* supported by Poppins, translate this to 'off'. Do not translate
* into your own language.
*/
if ( 'off' !== _x( 'on', 'Poppins font: on or off', 'suffice' ) ) {
$fonts[] = 'Poppins:400,500,600,700';
}
if ( $fonts ) {
$fonts_url = add_query_arg(
array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
'display' => 'swap',
),
'https://fonts.googleapis.com/css'
);
}
return $fonts_url;
}
endif;
/**
* Enqueue scripts and styles.
*/
function suffice_scripts() {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
/* Google fonts */
wp_enqueue_style( 'suffice-fonts', suffice_fonts_url(), array(), null );
/* Stylesheets */
wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/assets/css/font-awesome' . $suffix . '.css', array(), '4.7' );
wp_enqueue_style( 'swiper', get_template_directory_uri() . '/assets/css/swiper' . $suffix . '.css', array(), '3.4.0' );
wp_enqueue_style( 'perfect-scrollbar', get_template_directory_uri() . '/assets/css/perfect-scrollbar' . $suffix . '.css', array(), '0.6.16' );
wp_enqueue_style( 'suffice-style', get_stylesheet_uri() );
/* Scripts */
wp_enqueue_script( 'suffice-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
wp_enqueue_script( 'swiper', get_template_directory_uri() . '/assets/js/swiper.jquery' . $suffix . '.js', array( 'jquery' ), '3.4.0', true );
wp_enqueue_script( 'waypoints', get_template_directory_uri() . '/assets/js/jquery.waypoints' . $suffix . '.js', array( 'jquery' ), '4.0.1', true );
wp_enqueue_script( 'visible', get_template_directory_uri() . '/assets/js/jquery.visible' . $suffix . '.js', array( 'jquery' ), '1.0.0', true );
if ( true == suffice_get_option( 'suffice_sticky_header', true ) ) {
wp_enqueue_script( 'headroom', get_template_directory_uri() . '/assets/js/headroom' . $suffix . '.js', array( 'jquery' ), '0.9', true );
wp_enqueue_script( 'headroom-jquery', get_template_directory_uri() . '/assets/js/jQuery.headroom' . $suffix . '.js', array( 'jquery' ), '0.9', true );
}
wp_enqueue_script( 'perfect-scrollbar', get_template_directory_uri() . '/assets/js/perfect-scrollbar.jquery' . $suffix . '.js', array( 'jquery' ), '0.6.16', true );
wp_enqueue_script( 'isotope', get_template_directory_uri() . '/assets/js/isotope.pkgd' . $suffix . '.js', array( 'jquery' ), '3.0.2', true );
wp_enqueue_script( 'countup', get_template_directory_uri() . '/assets/js/countUp' . $suffix . '.js', array( 'jquery' ), '1.8.3', true );
wp_enqueue_script( 'smooth-scroll', get_template_directory_uri() . '/assets/js/smooth-scroll' . $suffix . '.js', array( 'jquery' ), '10.2.1', true );
wp_enqueue_script( 'gumshoe', get_template_directory_uri() . '/assets/js/gumshoe' . $suffix . '.js', array( 'jquery' ), '3.3.3', true );
/* Loads sticky sidebar js if enabled */
if ( true == suffice_get_option( 'suffice_sticky_sidebar', false ) ) {
wp_enqueue_script( 'theia-sticky-sidebar', get_template_directory_uri() . '/assets/js/theia-sticky-sidebar' . $suffix . '.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'ResizeSensor', get_template_directory_uri() . '/assets/js/ResizeSensor' . $suffix . '.js', array( 'jquery' ), false, true );
}
// Include Google Maps Js.
$googlemapapi = suffice_get_option( 'suffice_google_map_api', '' );
if ( ! empty( $googlemapapi ) ) {
wp_register_script( 'googlemap', 'https://maps.googleapis.com/maps/api/js?key=' . $googlemapapi . '', false, '3.0.0', true );
}
wp_enqueue_script( 'suffice-custom', get_template_directory_uri() . '/assets/js/suffice-custom' . $suffix . '.js', array( 'jquery' ), '1.0', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'suffice_scripts' );
function suffice_block_editor_styles() {
wp_enqueue_style( 'suffice-editor-googlefonts', '//fonts.googleapis.com/css?family=Open+Sans:400,700' );
wp_enqueue_style( 'suffice-block-editor-styles', get_template_directory_uri() . '/style-editor-block.css' );
}
add_action( 'enqueue_block_editor_assets', 'suffice_block_editor_styles', 1, 1 );
/**
* Adds css style for customizer ui
*/
function suffice_customizer_controls_styles() {
$theme_version = wp_get_theme()->get( 'version' );
wp_enqueue_style( 'customizer', get_template_directory_uri() . '/assets/css/customizer.css', array(), $theme_version );
}
add_action( 'customize_controls_enqueue_scripts', 'suffice_customizer_controls_styles' );
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* CSS class handling function.
*/
require get_template_directory() . '/inc/template-css-class.php';
/**
* Custom template functions.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Custom meta boxes
*/
if ( true == suffice_get_option( 'suffice_sticky_header', true ) ) {
require get_template_directory() . '/inc/meta-boxes.php';
}
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* If woocommerce is active, load compatibility file
*/
if ( suffice_is_woocommerce_active() ) {
require get_template_directory() . '/inc/woocommerce.php';
}
/**
* Kirki Customizer
*/
require get_template_directory() . '/inc/kirki/kirki.php';
require get_template_directory() . '/inc/kirki-translation.php';
require get_template_directory() . '/inc/kirki-customizer.php';
/**
* Assign the Suffice version to a variable.
*/
$suffice_theme = wp_get_theme( 'suffice' );
define( 'SUFFICE_THEME_VERSION', $suffice_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 get_template_directory() . '/inc/admin/class-suffice-admin.php';
require get_template_directory() . '/inc/admin/class-suffice-notice.php';
require get_template_directory() . '/inc/admin/class-suffice-welcome-notice.php';
require get_template_directory() . '/inc/admin/class-suffice-upgrade-notice.php';
require get_template_directory() . '/inc/admin/class-suffice-theme-review-notice.php';
}