-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
496 lines (340 loc) · 16.2 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
<?php
/* ---------------------------------------------------------------------------------------------
THEME SETUP
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_setup' ) ) :
function wilson_setup() {
// Automatic feed
add_theme_support( 'automatic-feed-links' );
// Post thumbnails
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 788, 9999 );
// Post formats
add_theme_support( 'post-formats', array( 'video', 'aside', 'quote' ) );
// HTML5 semantic markup.
add_theme_support( 'html5', array( 'search-form' ) );
// Title tag function
add_theme_support( 'title-tag' );
// Add nav menu
register_nav_menu( 'primary', __( 'Primary Menu', 'wilson' ) );
// Set content width
global $content_width;
if ( ! isset( $content_width ) ) $content_width = 788;
}
add_action( 'after_setup_theme', 'wilson_setup' );
endif;
/* -----------------------------------------------------------------------------------------------
REQUIRED FILES
Include required files
--------------------------------------------------------------------------------------------------- */
// Include the Customizer class.
require get_template_directory() . '/inc/classes/class-wilson-customize.php';
/* ---------------------------------------------------------------------------------------------
ENQUEUE SCRIPTS
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_load_javascript_files' ) ) :
function wilson_load_javascript_files() {
$theme_version = wp_get_theme( 'wilson' )->get( 'Version' );
wp_enqueue_script( 'wilson_global', get_template_directory_uri() . '/assets/js/global.js', array( 'jquery' ), $theme_version );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'wilson_load_javascript_files' );
endif;
/* ---------------------------------------------------------------------------------------------
ENQUEUE STYLES
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_load_style' ) ) :
function wilson_load_style() {
$theme_version = wp_get_theme( 'wilson' )->get( 'Version' );
$dependencies = array();
wp_register_style( 'wilson_fonts', get_theme_file_uri( '/assets/css/fonts.css' ) );
$dependencies[] = 'wilson_fonts';
wp_enqueue_style( 'wilson_style', get_stylesheet_uri(), $dependencies, $theme_version, 'all' );
}
add_action( 'wp_enqueue_scripts', 'wilson_load_style' );
endif;
/* ---------------------------------------------------------------------------------------------
ADD EDITOR STYLES
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_add_editor_styles' ) ) :
function wilson_add_editor_styles() {
add_editor_style( array( 'assets/css/classic-editor-styles.css', 'assets/css/fonts.css' ) );
}
add_action( 'init', 'wilson_add_editor_styles' );
endif;
/* ---------------------------------------------------------------------------------------------
REGISTER SIDEBARS
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_sidebar_registration' ) ) :
function wilson_sidebar_registration() {
$shared_args = array(
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-content">',
'after_widget' => '</div></div>'
);
register_sidebar( array_merge( $shared_args, array(
'name' => __( 'Sidebar', 'wilson' ),
'id' => 'sidebar',
'description' => __( 'Widgets in this area will be displayed in the sidebar.', 'wilson' ),
) ) );
register_sidebar( array_merge( $shared_args, array(
'name' => __( 'Footer A', 'wilson' ),
'id' => 'footer-a',
'description' => __( 'Widgets in this area will be displayed in the left column in the footer.', 'wilson' ),
) ) );
register_sidebar( array_merge( $shared_args, array(
'name' => __( 'Footer B', 'wilson' ),
'id' => 'footer-b',
'description' => __( 'Widgets in this area will be displayed in the right column in the footer.', 'wilson' ),
) ) );
}
add_action( 'widgets_init', 'wilson_sidebar_registration' );
endif;
/* ---------------------------------------------------------------------------------------------
ADD CLASSES TO PAGINATION
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_next_posts_link_attributes' ) ) :
function wilson_next_posts_link_attributes() {
return 'class="post-nav-older"';
}
add_filter( 'next_posts_link_attributes', 'wilson_next_posts_link_attributes' );
endif;
if ( ! function_exists( 'wilson_previous_posts_link_attributes' ) ) :
function wilson_previous_posts_link_attributes() {
return 'class="post-nav-newer"';
}
add_filter( 'previous_posts_link_attributes', 'wilson_previous_posts_link_attributes' );
endif;
/* ---------------------------------------------------------------------------------------------
BODY AND POST CLASSES
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_the_content' ) ) :
function wilson_the_content( $content ) {
// On the archives template, append the content for that template.
if ( is_page_template( 'template-archives.php' ) ) {
ob_start();
include( locate_template( 'inc/template-archives-content.php' ) );
$content .= ob_get_clean();
}
return $content;
}
add_filter( 'the_content', 'wilson_the_content' );
endif;
/* ---------------------------------------------------------------------------------------------
CUSTOM MORE LINK TEXT
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_custom_more_link' ) ) :
function wilson_custom_more_link( $more_link, $more_link_text ) {
return str_replace( $more_link_text, __( 'Continue reading', 'wilson' ), $more_link );
}
add_filter( 'the_content_more_link', 'wilson_custom_more_link', 10, 2 );
endif;
/* ---------------------------------------------------------------------------------------------
POST META FUNCTION
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_meta' ) ) :
function wilson_meta() {
if ( is_page() ) return;
?>
<div class="post-meta">
<span class="post-date"><a href="<?php the_permalink(); ?>"><?php the_time( get_option( 'date_format' ) ); ?></a></span>
<span class="date-sep"> / </span>
<span class="post-author"><?php the_author_posts_link(); ?></span>
<?php if ( comments_open() ) : ?>
<span class="date-sep"> / </span>
<?php comments_popup_link( '<span class="comment">' . __( '0 Comments', 'wilson' ) . '</span>', __( '1 Comment', 'wilson' ), __( '% Comments', 'wilson' ) ); ?>
<?php endif; ?>
<?php if ( is_sticky() && ! has_post_thumbnail() ) : ?>
<span class="date-sep"> / </span>
<?php _e( 'Sticky', 'wilson' ); ?>
<?php endif; ?>
<?php if ( current_user_can( 'manage_options' ) ) : ?>
<span class="date-sep"> / </span>
<?php edit_post_link( __( 'Edit', 'wilson' ) ); ?>
<?php endif; ?>
</div><!-- .post-meta -->
<?php
}
endif;
/* ---------------------------------------------------------------------------------------------
WILSON COMMENT FUNCTION
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_comment' ) ) :
function wilson_comment( $comment, $args, $depth ) {
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<?php _e( 'Pingback:', 'wilson' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'wilson' ), '<span class="edit-link">(', ')</span>' ); ?>
</li>
<?php
break;
default :
global $post;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>" class="comment">
<div class="comment-meta comment-author vcard">
<?php echo get_avatar( $comment, 120 ); ?>
<div class="comment-meta-content">
<?php printf( '<cite class="fn">%1$s %2$s</cite>',
get_comment_author_link(),
( $comment->user_id === $post->post_author ? '<span class="post-author">' . __( '(Post author)', 'wilson' ) . '</span>' : '' )
); ?>
<p><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><?php printf( __( '%1$s at %2$s', 'wilson' ), get_comment_date(), get_comment_time() ); ?></a></p>
</div><!-- .comment-meta-content -->
</div><!-- .comment-meta -->
<div class="comment-content post-content">
<?php if ( $comment->comment_approved == '0' ) : ?>
<p class="comment-awaiting-moderation"><?php _e( 'Awaiting moderation', 'wilson' ); ?></p>
<?php endif; ?>
<?php comment_text(); ?>
<div class="comment-actions">
<?php
edit_comment_link( __( 'Edit', 'wilson' ), '', '' );
comment_reply_link( array_merge( $args, array(
'depth' => $depth,
'max_depth' => $args['max_depth'],
'reply_text' => __( 'Reply', 'wilson' )
) ) );
?>
<div class="clear"></div>
</div><!-- .comment-actions -->
</div><!-- .comment-content -->
</div><!-- #comment-## -->
</li>
<?php
break;
endswitch;
}
endif;
/* -----------------------------------------------------------------------------------------------
FILTER ARCHIVE TITLE
@param $title string The initial title
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_filter_archive_title' ) ) :
function wilson_filter_archive_title( $title ) {
$paged = get_query_var( 'paged', 1 );
$max_num_pages = get_query_var( 'max_num_pages' );
// On home, show no title
if ( is_home() && $paged <= 1 ) {
$title = '';
// On paged home, show the page count
} else if ( is_home() && $paged > 1 ) {
global $wp_query;
$title = sprintf( __( 'Page %1$s of %2$s', 'wilson' ), $paged, $wp_query->max_num_pages );
}
// On search, show the search query.
elseif ( is_search() ) {
$title = sprintf( _x( 'Search: %s', '%s = The search query', 'wilson' ), '“' . get_search_query() . '”' );
}
return $title;
}
add_filter( 'get_the_archive_title', 'wilson_filter_archive_title' );
endif;
/* -----------------------------------------------------------------------------------------------
FILTER ARCHIVE DESCRIPTION
@param $description string The initial description
--------------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_filter_archive_description' ) ) :
function wilson_filter_archive_description( $description ) {
// On search, show a string describing the results of the search.
if ( is_search() ) {
global $wp_query;
if ( $wp_query->found_posts ) {
/* Translators: %s = Number of results */
$description = sprintf( _nx( 'We found %s result for your search.', 'We found %s results for your search.', $wp_query->found_posts, '%s = Number of results', 'wilson' ), $wp_query->found_posts );
} else {
$description = __( 'We could not find any results for your search. You can give it another try through the search form below.', 'wilson' );
}
}
return $description;
}
add_filter( 'get_the_archive_description', 'wilson_filter_archive_description' );
endif;
/* ---------------------------------------------------------------------------------------------
SPECIFY BLOCK EDITOR SUPPORT
------------------------------------------------------------------------------------------------ */
if ( ! function_exists( 'wilson_add_gutenberg_features' ) ) :
function wilson_add_gutenberg_features() {
/* Block Editor Features ------------- */
add_theme_support( 'align-wide' );
/* Block Editor Palette -------------- */
$accent_color = get_theme_mod( 'accent_color', '#FF706C' );
add_theme_support( 'editor-color-palette', array(
array(
'name' => _x( 'Accent', 'Name of the accent color in the Gutenberg palette', 'wilson' ),
'slug' => 'accent',
'color' => $accent_color,
),
array(
'name' => _x( 'Black', 'Name of the black color in the Gutenberg palette', 'wilson' ),
'slug' => 'black',
'color' => '#272F38',
),
array(
'name' => _x( 'Dark Gray', 'Name of the dark gray color in the Gutenberg palette', 'wilson' ),
'slug' => 'dark-gray',
'color' => '#444',
),
array(
'name' => _x( 'Medium Gray', 'Name of the medium gray color in the Gutenberg palette', 'wilson' ),
'slug' => 'medium-gray',
'color' => '#666',
),
array(
'name' => _x( 'Light Gray', 'Name of the light gray color in the Gutenberg palette', 'wilson' ),
'slug' => 'light-gray',
'color' => '#888',
),
array(
'name' => _x( 'White', 'Name of the white color in the Gutenberg palette', 'wilson' ),
'slug' => 'white',
'color' => '#fff',
),
) );
/* Block Editor Font Sizes ----------- */
add_theme_support( 'editor-font-sizes', array(
array(
'name' => _x( 'Small', 'Name of the small font size in Gutenberg', 'wilson' ),
'shortName' => _x( 'S', 'Short name of the small font size in the Gutenberg editor.', 'wilson' ),
'size' => 16,
'slug' => 'small',
),
array(
'name' => _x( 'Regular', 'Name of the regular font size in Gutenberg', 'wilson' ),
'shortName' => _x( 'M', 'Short name of the regular font size in the Gutenberg editor.', 'wilson' ),
'size' => 18,
'slug' => 'regular',
),
array(
'name' => _x( 'Large', 'Name of the large font size in Gutenberg', 'wilson' ),
'shortName' => _x( 'L', 'Short name of the large font size in the Gutenberg editor.', 'wilson' ),
'size' => 24,
'slug' => 'large',
),
array(
'name' => _x( 'Larger', 'Name of the larger font size in Gutenberg', 'wilson' ),
'shortName' => _x( 'XL', 'Short name of the larger font size in the Gutenberg editor.', 'wilson' ),
'size' => 32,
'slug' => 'larger',
),
) );
}
add_action( 'after_setup_theme', 'wilson_add_gutenberg_features' );
endif;
/* ---------------------------------------------------------------------------------------------
BLOCK EDITOR STYLES
--------------------------------------------------------------------------------------------- */
if ( ! function_exists( 'wilson_block_editor_styles' ) ) :
function wilson_block_editor_styles() {
$theme_version = wp_get_theme( 'wilson' )->get( 'Version' );
wp_register_style( 'wilson-block-editor-styles-font', get_theme_file_uri( '/assets/css/fonts.css' ) );
wp_enqueue_style( 'wilson-block-editor-styles', get_theme_file_uri( '/assets/css/block-editor-styles.css' ), array( 'wilson-block-editor-styles-font' ), $theme_version, 'all' );
}
add_action( 'enqueue_block_editor_assets', 'wilson_block_editor_styles', 1 );
endif;