-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
551 lines (434 loc) · 17.9 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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
<?php
/**
* @package foodica
*/
/**
* Define Constants
*/
define( 'FOODICA_THEME_VERSION', '1.3.1' );
define( 'FOODICA_THEME_DIR', trailingslashit( get_template_directory() ) );
define( 'FOODICA_THEME_URI', trailingslashit( esc_url( get_template_directory_uri() ) ) );
define( 'FOODICA_THEME_ASSETS_URI', FOODICA_THEME_URI . 'dist' );
/* Customizer */
require get_template_directory() . '/inc/customizer/bootstrap.php';
require_once( trailingslashit( get_template_directory() ) . '/inc/customizer/trt-customize-pro/upgrade-pro/class-customize.php' );
/**
* Customizer additions.
*/
require FOODICA_THEME_DIR . 'inc/classes/class-foodica-font-family-manager.php';
require FOODICA_THEME_DIR . 'inc/classes/class-foodica-fonts-manager.php';
require FOODICA_THEME_DIR . 'inc/customizer-functions.php';
require FOODICA_THEME_DIR . 'inc/customizer/class-foodica-customizer-control-base.php';
require FOODICA_THEME_DIR . 'inc/customizer/class-foodica-customizer.php';
/**
* Load Jetpack plugin enhancement file to display admin notices.
*/
require get_template_directory() . '/inc/jetpack/plugin-enhancements.php';
/**
* Theme Setup
*/
function foodica_setup() {
// This theme styles the visual editor to resemble the theme style.
add_editor_style( array( 'assets/css/editor-style.css' ) );
// Custom Background
add_theme_support( 'custom-background' );
// Custom Menus
register_nav_menus( array(
'secondary' => __( 'Top Menu', 'foodica' ),
'primary' => __( 'Main Menu', 'foodica' ),
'mobile' => __( 'Mobile Menu', 'foodica' ),
'tertiary' => __( 'Footer Menu', 'foodica' )
) );
/*
* 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',
) );
// Featured Image
add_theme_support( 'post-thumbnails' );
add_image_size( 'foodica-featured-posts-widget', 75, 50, true ); /* Recent Posts with Thumbnail widget */
add_image_size( 'foodica-loop-sticky', 750, 500, true ); /* Sticky Posts and Single Post large Image */
add_image_size( 'foodica-loop-full', 1140, 500, true ); /* Post with full-width layout */
add_image_size( 'foodica-loop-portrait', 360, 540, true ); /* Regular post thumbnail (portrait ratio) */
add_image_size( 'foodica-loop-portrait@2x', 720, 1080, true ); /* Regular post thumbnail (portrait ratio) */
add_image_size( 'foodica-prevnext-small', 100, 100, true ); /* Previous/Next Post navigation */
add_image_size( 'foodica-prevnext-small@2x', 200, 200, true ); /* Previous/Next Post navigation */
// Title Tag
add_theme_support( 'title-tag' );
// Feed Links
add_theme_support( 'automatic-feed-links' );
/*
* JetPack Infinite Scroll
*/
add_theme_support( 'infinite-scroll', array(
'container' => 'recent-posts',
'wrapper' => false,
'footer' => false
) );
/**
* Add support for Jetpack's Featured Content
*/
add_theme_support( 'featured-content', array(
'featured_content_filter' => 'foodica_featured_content',
'max_posts' => 5,
) );
/**
* Theme Logo
*/
add_theme_support( 'custom-logo', array(
'height' => 150,
'width' => 650,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-description' ),
) );
load_theme_textdomain( 'foodica', get_template_directory() . '/languages' );
// Set the default content width.
$GLOBALS['content_width'] = 750;
/**
* Gutenberg Wide Images
*/
add_theme_support( 'align-wide' );
// Add support for default block styles.
add_theme_support( 'wp-block-styles' );
// Add support for editor styles.
add_theme_support( 'editor-styles' );
// Enqueue editor styles.
add_editor_style( 'assets/css/gutenberg-editor-style.css' );
}
add_action( 'after_setup_theme', 'foodica_setup' );
/**
* Add Custom Body Classes
*
* @since 1.0.12
*
* @param {array} $classes An array of body class names.
*/
function foodica_add_custom_body_classes( $classes ) {
$front_page_layout = get_theme_mod( 'front-page-layout', 'right-sidebar' );
$archives_page_layout = get_theme_mod( 'archives-layout', 'full-width' );
$single_posts_layout = get_theme_mod( 'single-post-layout', 'right-sidebar' );
$single_pages_layout = get_theme_mod( 'single-page-layout', 'right-sidebar' );
if ( is_front_page() ) {
$classes[] = "front-page-layout-{$front_page_layout}";
}
if ( is_category() || is_archive() ) {
$classes[] = "front-page-layout-{$archives_page_layout}";
}
if ( is_single() ) {
$classes[] = "front-page-layout-{$single_posts_layout}";
}
if ( is_page() ) {
$classes[] = "front-page-layout-{$single_pages_layout}";
}
return $classes;
}
add_filter( 'body_class', 'foodica_add_custom_body_classes' );
/**
* Get Jetpack Featured Content posts
*/
function foodica_get_featured_content() {
return apply_filters( 'foodica_featured_content', array() );
}
/**
* Show custom logo or blog title and description (backward compatibility)
*
*/
function foodica_custom_logo() {
has_custom_logo() ? the_custom_logo() : printf('<h2><a href="%s" title="%s">%s</a></h2>', esc_url(home_url()), get_bloginfo('description'), get_bloginfo('name'));
}
/*
* Fetch Theme Data & Options for About Page
*/
$foodica_data = wp_get_theme('foodica');
$foodica_version = $foodica_data['Version'];
$foodica_options = get_option('foodica_options');
/**
* Enqueues scripts and styles
*/
function foodica_enqueue_scripts() {
wp_enqueue_style( 'foodica-style', get_stylesheet_uri(), '', wp_get_theme()->get( 'Version' ) );
wp_enqueue_style( 'foodica-style-mobile', get_template_directory_uri() . '/assets/css/media-queries.css', array( 'foodica-style' ), wp_get_theme()->get( 'Version' ) );
// Add custom fonts, used in the main stylesheet.
Foodica_Fonts_Manager::render_fonts();
wp_enqueue_style( 'dashicons' );
wp_enqueue_script( 'slicknav', get_template_directory_uri() . '/assets/js/foodica-slicknav.min.js', array( 'jquery' ), '1.2.0', true );
wp_enqueue_script( 'flickity', get_template_directory_uri() . '/assets/js/flickity.pkgd.min.js', array(), '1.2.0', true );
wp_enqueue_script( 'fitvids', get_template_directory_uri() . '/assets/js/foodica-jquery.fitvids.js', array( 'jquery' ), '1.0.0', true );
wp_enqueue_script( 'superfish', get_template_directory_uri() . '/assets/js/superfish.min.js', array( 'jquery' ), '1.2.0', true );
wp_enqueue_script( 'foodica-search_button', get_template_directory_uri() . '/assets/js/foodica-search_button.js', array(), wp_get_theme()->get( 'Version' ), true );
wp_enqueue_script( 'foodica-script', get_template_directory_uri() . '/assets/js/foodica-functions.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
// Localize the script with new data
$foodica_translation_array = array(
'index_infinite_load_txt' => __( 'Load More...', 'foodica' ),
'index_infinite_loading_txt' => __( 'Loading...', 'foodica' )
);
wp_localize_script( 'foodica-script', 'zoomOptions', $foodica_translation_array );
$theme_css_data = apply_filters( 'foodica/dynamic_theme_css', '' );
wp_add_inline_style( 'foodica-style', $theme_css_data );
}
add_action( 'wp_enqueue_scripts', 'foodica_enqueue_scripts' );
/**
* Initializes Widgetized Areas (Sidebars)
*/
function foodica_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'foodica' ),
'id' => 'sidebar-1',
'before_widget' => '<div class="widget %2$s" id="%1$s">',
'after_widget' => '<div class="clear"></div></div>',
'before_title' => '<h3 class="title">',
'after_title' => '</h3>',
) );
/*----------------------------------*/
/* Footer widgetized areas */
/*----------------------------------*/
register_sidebar( array(
'name' => __('Footer: Column 1', 'foodica' ),
'id' => 'footer_1',
'before_widget' => '<div class="widget %2$s" id="%1$s">',
'after_widget' => '<div class="clear"></div></div>',
'before_title' => '<h3 class="title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __('Footer: Column 2', 'foodica' ),
'id' => 'footer_2',
'before_widget' => '<div class="widget %2$s" id="%1$s">',
'after_widget' => '<div class="clear"></div></div>',
'before_title' => '<h3 class="title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __('Footer: Column 3', 'foodica' ),
'id' => 'footer_3',
'before_widget' => '<div class="widget %2$s" id="%1$s">',
'after_widget' => '<div class="clear"></div></div>',
'before_title' => '<h3 class="title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __('Footer: Column 4', 'foodica' ),
'id' => 'footer_4',
'before_widget' => '<div class="widget %2$s" id="%1$s">',
'after_widget' => '<div class="clear"></div></div>',
'before_title' => '<h3 class="title">',
'after_title' => '</h3>',
) );
/* Header - for social icons
===============================*/
register_sidebar(array(
'name'=>__('Header Social Icons', 'foodica' ),
'id' => 'header_social',
'description' => 'Widget area in the header. Install the "Social Icons Widget by WPZOOM" plugin and add the widget here.',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="title"><span>',
'after_title' => '</span></h3>',
));
// Custom Theme Widget
require_once get_template_directory() . '/inc/widgets.php';
// require_once get_template_directory() . '/inc/wpzoom-widgets.php';
}
add_action( 'widgets_init', 'foodica_widgets_init' );
/* Tag Cloud Mods */
function foodica_tagcloud_postcount_filter ($variable) {
$variable = str_replace('<span class="tag-link-count"> (', ' <span class="post_count"> ', $variable);
$variable = str_replace(')</span>', '</span>', $variable);
return $variable;
}
add_filter('wp_tag_cloud','foodica_tagcloud_postcount_filter');
/**
* Adds the post layout meta box
*/
function foodica_add_meta_box() {
add_meta_box( 'foodica_post_layout', __( 'Post Layout', 'foodica' ), 'foodica_meta_box_post_layout', 'post', 'side', 'low' );
}
add_action( 'add_meta_boxes', 'foodica_add_meta_box' );
/**
* Displays the post layout dropdown field
*/
function foodica_meta_box_post_layout() {
global $post;
$selected = get_post_meta( $post->ID, '_foodica_post_layout', true );
wp_nonce_field( 'foodica_post_layout', 'foodica_post_layout_nonce' ); ?>
<p>
<label for="foodica_post_layout"><?php esc_html_e( 'Choose the layout for this post:', 'foodica' ); ?>
</label><br /> <select name="foodica_post_layout"
id="foodica_post_layout">
<option value="">
<?php esc_html_e( 'Default', 'foodica' ); ?>
</option>
<option value="column-full"
<?php selected( $selected, 'column-full' ); ?>>
<?php esc_html_e( 'Full Width (no sidebar)', 'foodica' ); ?>
</option>
</select>
</p>
<?php
}
/**
* Updates or deletes post meta with the post layout selection
*
* @param int $post_id
* @return int
*/
function foodica_save_post( $post_id ){
if ( ( ! defined( 'DOING_AUTOSAVE' ) || ! DOING_AUTOSAVE )
&& current_user_can( 'edit_post', $post_id )
&& isset( $_POST['foodica_post_layout'] )
&& check_admin_referer( 'foodica_post_layout', 'foodica_post_layout_nonce' ) ) {
$sanitized_post_layout = sanitize_title_with_dashes($_POST['foodica_post_layout']);
if ( in_array( $sanitized_post_layout, array( 'column-full' ) ) )
update_post_meta( $post_id, '_foodica_post_layout', $sanitized_post_layout );
else
delete_post_meta( $post_id, '_foodica_post_layout' );
}
return $post_id;
}
add_action( 'save_post', 'foodica_save_post' );
/**
* Include the TGM_Plugin_Activation class.
*/
require_once get_template_directory() . '/inc/class-tgm-plugin-activation.php';
add_action( 'tgmpa_register', 'foodica_register_required_plugins' );
/**
* Register the required plugins for this theme.
*
* The variable passed to tgmpa_register_plugins() should be an array of plugin
* arrays.
*
* This function is hooked into tgmpa_init, which is fired within the
* TGM_Plugin_Activation class constructor.
*/
function foodica_register_required_plugins() {
$recipe_card_plugin = array(
'name' => 'Recipe Card Blocks',
'slug' => 'recipe-card-blocks-by-wpzoom',
'required' => false
);
if ( class_exists( 'WPZOOM_Recipe_Card_Block_Gutenberg' ) ) {
if ( WPZOOM_Recipe_Card_Block_Gutenberg::has_pro() ) {
$recipe_card_plugin = array(
'name' => 'Recipe Card Blocks PRO',
'slug' => 'recipe-card-blocks-by-wpzoom-pro',
'required' => false
);
}
}
/*
* Array of plugin arrays. Required keys are name and slug.
* If the source is NOT from the .org repo, then source is also required.
*/
$plugins = array(
// Recommended plugins from the WordPress Plugin Repository.
array(
'name' => 'Social Icons Widget by WPZOOM',
'slug' => 'social-icons-widget-by-wpzoom',
'required' => false,
),
array(
'name' => 'Instagram Widget by WPZOOM',
'slug' => 'instagram-widget-by-wpzoom',
'required' => false,
),
array(
'name' => 'WPZOOM Forms',
'slug' => 'wpzoom-forms',
'required' => false,
),
array(
'name' => 'Block Patterns for Food Bloggers',
'slug' => 'block-patterns-for-food-bloggers',
'required' => false,
),
$recipe_card_plugin
);
/*
* Array of configuration settings. Amend each line as needed.
*
* TGMPA will start providing localized text strings soon. If you already have translations of our standard
* strings available, please help us make TGMPA even better by giving us access to these translations or by
* sending in a pull-request with .po file(s) with the translations.
*
* Only uncomment the strings in the config array if you want to customize the strings.
*/
$config = array(
'id' => 'foodica', // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => '', // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'has_notices' => true, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
);
tgmpa( $plugins, $config );
}
/**
* Enqueues scripts and styles
*/
require FOODICA_THEME_DIR . 'inc/classes/class-foodica-enqueue-scripts.php';
/**
* Theme admin notices and info page
*/
if ( is_admin() ) {
require FOODICA_THEME_DIR . 'inc/admin-notice.php';
require FOODICA_THEME_DIR . 'inc/theme-info-page.php';
if ( current_user_can( 'manage_options' ) ) {
require FOODICA_THEME_DIR . 'inc/classes/class-foodica-notices.php';
require FOODICA_THEME_DIR . 'inc/classes/class-foodica-notice-review.php';
}
}
/**
* WooCommerce compatibility.
*/
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
if ( ! is_array( $active_plugins ) ) {
$active_plugins = array( $active_plugins );
}
if ( in_array( 'woocommerce/woocommerce.php', $active_plugins ) ) {
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' );
}
/*
* Custom Archives titles.
*/
if ( ! function_exists( 'foodica_get_the_archive_title' ) ) :
function foodica_get_the_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
}
return $title;
}
endif;
add_filter( 'get_the_archive_title', 'foodica_get_the_archive_title' );
/**
* Inline theme css generated dynamically
*/
require FOODICA_THEME_DIR . 'inc/dynamic-css/body.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/site-title.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/site-description.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/top-menu.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/main-nav.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/main-nav-mobile.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/slider.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/slider-button.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/widget.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/blog-post-title.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/post-content.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/post-title.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/single-post-content.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/page-title.php';
require FOODICA_THEME_DIR . 'inc/dynamic-css/footer-nav.php';