Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
430 lines (356 loc) · 14.5 KB
/
Copy pathfunctions.php
File metadata and controls
430 lines (356 loc) · 14.5 KB
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
<?php
if( !defined('POWERPRESS_NO_REMOVE_WP_HEAD') ) {
define( 'POWERPRESS_NO_REMOVE_WP_HEAD', true );
}
/* remove parent script that inserts ellipsis icon on mobile */
function dequeue_priority_menu() {
wp_dequeue_script( 'twentynineteen-priority-menu' );
}
add_action( 'wp_enqueue_scripts', 'dequeue_priority_menu', 100 );
function c4aa_enqueue_assets() {
$build_dir = get_stylesheet_directory() . '/build/';
$build_uri = get_stylesheet_directory_uri() . '/build/';
// Versioned by mtime so a rebuild busts the cache; '1.0' only if build/ is missing
$style_version = file_exists( $build_dir . 'main.css' ) ? filemtime( $build_dir . 'main.css' ) : '1.0';
$script_version = file_exists( $build_dir . 'main.js' ) ? filemtime( $build_dir . 'main.js' ) : '1.0';
wp_enqueue_style('twentynineteen-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('c4aa-style', $build_uri . 'main.css', [], $style_version);
// One bundle (esbuild, see package.json) of the js/ front-end files. Deferred
// from the head: downloads early, runs after parsing, before DOMContentLoaded.
wp_enqueue_script('c4aa-js', $build_uri . 'main.js', [], $script_version, ['strategy' => 'defer', 'in_footer' => false]);
}
add_action( 'wp_enqueue_scripts', 'c4aa_enqueue_assets' );
/**
* Preload the two font files every page needs above the fold, so the browser
* fetches them alongside the CSS instead of after parsing it. Work Sans is a
* variable font split by script; the Latin piece covers every weight and the
* Latin Extended piece loads on demand. Zilla Slab 700 (Latin piece) is the
* heading face; the other Zilla Slab weights keep loading on demand. The URLs
* must match the @font-face sources theme.json generates, or the browser
* fetches the file twice.
*/
function c4aa_preload_fonts( $resources ) {
$dir = get_stylesheet_directory_uri() . '/fonts/';
foreach ( array( 'WorkSans-VariableFont_wght-latin.woff2', 'zilla-slab-v12-700-latin.woff2' ) as $file ) {
$resources[] = array(
'href' => $dir . $file,
'as' => 'font',
'type' => 'font/woff2',
'crossorigin' => 'anonymous',
);
}
return $resources;
}
add_filter( 'wp_preload_resources', 'c4aa_preload_fonts' );
/**
* Gutenberg scripts and styles
* link https://www.billerickson.net/block-styles-in-gutenberg/
*/
function c4aa_gutenberg_scripts() {
wp_enqueue_script(
'be-editor',
get_stylesheet_directory_uri() . '/js/editor.js',
array( 'wp-blocks', 'wp-dom-ready' ),
filemtime( get_stylesheet_directory() . '/js/editor.js' ),
true
);
}
add_action( 'enqueue_block_editor_assets', 'c4aa_gutenberg_scripts' );
add_action( 'admin_init', 'wpdocs_add_editor_styles' );
function wpdocs_add_editor_styles() {
add_theme_support( 'editor-styles' );
add_editor_style( '/build/editor.css' );
}
// The front end sets html { font-size: 18px } (_02-elements), so rem is 18px there.
// add_editor_style() CSS gets rescoped to .editor-styles-wrapper, which can't change
// rem, so the editor sat at 16px and everything sized in rem came out ~11% small.
// enqueue_block_assets styles reach the editor iframe unchanged. The :has() keeps
// it to the iframe's own <html>, whose body is the .editor-styles-wrapper.
function c4aa_editor_root_font_size() {
if ( ! is_admin() ) {
return;
}
wp_register_style( 'c4aa-editor-root', false );
wp_enqueue_style( 'c4aa-editor-root' );
wp_add_inline_style( 'c4aa-editor-root', 'html:has(> body.editor-styles-wrapper) { font-size: 18px; }' );
}
add_action( 'enqueue_block_assets', 'c4aa_editor_root_font_size' );
// WordPress prints a 3KB script on every page that checks whether the browser
// can draw a few recent emoji and swaps in images if it can't. Every current
// browser can, so skip the script and its inline styles on the front end.
// Core still hooks the deprecated print_emoji_styles() to wp_print_styles for
// back-compat and relies on wp_enqueue_emoji_styles() to unhook it, so once
// that is gone the old one has to go too or it fires a deprecation notice.
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
// This filter allows emoji to be added to the post content
// https://stackoverflow.com/questions/63100373/wordpress-unable-to-save-or-update-posts-with-emoji
add_filter( 'wp_insert_post_data', function( $data, $postarr ) {
if ( ! empty( $data['post_content'] ) ) {
$data['post_content'] = wp_encode_emoji( $data['post_content'] );
}
return $data;
}, 99, 2 );
// Add Social Link Icons for Bluesky
// Directly modify the TwentyNineteen SVG Icons class to add Bluesky support
function c4aa_add_bluesky_icon() {
// Add Bluesky to the social icons map
TwentyNineteen_SVG_Icons::$social_icons_map['bluesky'] = array('bsky.app');
// Add the Bluesky SVG icon
TwentyNineteen_SVG_Icons::$social_icons['bluesky'] = '
<svg viewBox="0 0 600 530" version="1.1" xmlns="http://www.w3.org/2000/svg">
<path d="m135.72 44.03c66.496 49.921 138.02 151.14 164.28 205.46 26.262-54.316 97.782-155.54 164.28-205.46 47.98-36.021 125.72-63.892 125.72 24.795 0 17.712-10.155 148.79-16.111 170.07-20.703 73.984-96.144 92.854-163.25 81.433 117.3 19.964 147.14 86.092 82.697 152.22-122.39 125.59-175.91-31.511-189.63-71.766-2.514-7.3797-3.6904-10.832-3.7077-7.8964-0.0174-2.9357-1.1937 0.51669-3.7077 7.8964-13.714 40.255-67.233 197.36-189.63 71.766-64.444-66.128-34.605-132.26 82.697-152.22-67.108 11.421-142.55-7.4491-163.25-81.433-5.9562-21.282-16.111-152.36-16.111-170.07 0-88.687 77.742-60.816 125.72-24.795z" />
</svg>';
}
add_action( 'after_setup_theme', 'c4aa_add_bluesky_icon' );
/**
* ACF Body Class Options
*
* Add a body_class according to ACF options to
* provide hooks for CSS.
*/
function c4aa_add_body_class_from_acf_options_on_single_or_page( $classes ) {
if ( ! function_exists( 'get_field' ) ) {
return $classes;
}
// Only single posts and pages carry these fields, so don't ask ACF on
// archives, search and the front page.
if ( ! is_single() && ! is_page() ) {
return $classes;
}
$image_filter = get_field( 'c4aa_image_filter' );
$title_effect = get_field( 'c4aa_title_effect' );
if ( ! empty( $image_filter ) ) {
$classes[] = "$image_filter";
}
if ( ! empty( $title_effect ) ) {
$classes[] = "$title_effect";
}
return $classes;
}
add_filter( 'body_class', 'c4aa_add_body_class_from_acf_options_on_single_or_page' );
// Adds a search form to the search results page.
// so if you search for something and don't find it, you can search again!
/**
* Setup a custom hook before the second post on the search page.
* Hooked up from template_redirect so the_post only carries it on search
* requests instead of every loop on the site.
*/
add_action( 'template_redirect', function()
{
if ( ! is_search() ) {
return;
}
add_action( 'the_post', function( $post, \WP_Query $q )
{
if( $q->is_main_query() && ! $q->is_feed() && 0 === $q->current_post )
{
do_action( 'wpse_before_second_post_in_search' );
}
}, 10, 2 );
} );
/**
* Inject a Div after the first post on the search page
*/
add_action( 'wpse_before_second_post_in_search', function()
{
// get_search_form() only knows about 'echo' and 'aria_label', so the custom
// label and placeholder never showed up. Write the form out directly instead.
?>
<article class="entry search-results-search-form"><div class="entry-content"><div class="wp-block-group"><div class="wp-block-group__inner-container search-form-in-results">
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label for="search-again" class="search-again-label"><?php esc_html_e( "Didn't find what you're looking for?", 'c4aa-org' ); ?></label>
<input type="search" id="search-again" class="search-field" placeholder="<?php esc_attr_e( 'Search again…', 'c4aa-org' ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
<input type="submit" class="search-submit" value="<?php esc_attr_e( 'Search', 'c4aa-org' ); ?>" />
</form>
</div></div></div></article>
<?php
} );
// Initialize Duotone on all post-thumbnails on archives. The specific color
// scheme is set by filtering the post class below, and overriding the
// defaults via the cascade.
function c4aa_add_archive_body_class( $classes ) {
if ( is_archive() || is_search() ) {
$classes[] = "c4aa-excerpt-grid";
}
return $classes;
}
add_filter( 'body_class', 'c4aa_add_archive_body_class' );
function c4aa_add_post_class_from_acf_options( $classes ) {
if ( ! function_exists( 'get_field' ) ) {
return $classes;
}
$image_filter = get_field( 'c4aa_image_filter', get_the_ID() );
if ( ! empty( $image_filter ) ) {
$classes[] = $image_filter;
}
return $classes;
}
add_filter( 'post_class', 'c4aa_add_post_class_from_acf_options' );
/**
* Add Dashboard Widget
*
* A place for specific reference info & instructions about the theme
* for users of the site.
*/
function c4aa_custom_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget('custom_help_widget', __( 'C4AA Theme Notes', 'c4aa-org' ), 'c4aa_custom_dashboard_help');
}
add_action('wp_dashboard_setup', 'c4aa_custom_dashboard_widgets');
function c4aa_custom_dashboard_help() {
?>
<h3 id="welcometothenewc4aatheme"><?php esc_html_e( 'Welcome to the new Center for Artistic Activism theme!', 'c4aa-org' ); ?></h3>
<p><?php esc_html_e( 'The new theme uses Gutenberg Blocks.', 'c4aa-org' ); ?> <a href="https://wordpress.org/gutenberg/"><?php esc_html_e( 'Get an introduction and experiment with it here.', 'c4aa-org' ); ?></a></p>
<p><strong><?php esc_html_e( 'Good ideas:', 'c4aa-org' ); ?></strong></p>
<ul>
<li>➡ <?php esc_html_e( 'upload images at 1400px wide where possible', 'c4aa-org' ); ?></li>
<li>➡ <?php esc_html_e( 'use colors from the color picker', 'c4aa-org' ); ?></li>
<li>➡ <?php esc_html_e( 'If you have questions, ask Steve Lambert.', 'c4aa-org' ); ?></li>
</ul>
<p><strong><?php esc_html_e( 'Advanced Settings:', 'c4aa-org' ); ?></strong></p>
<ul>
<li><?php
/* translators: %s: the CSS class name no-hyphens, wrapped in a <code> tag */
printf( esc_html__( '%s will turn off auto-hyphenating on everything in the block.', 'c4aa-org' ), '<code>no-hyphens</code>' );
?></li>
</ul>
<?php
}
/**
* Theme support.
*
*/
function c4aa_setup_theme_supported_features() {
// There is a bug with jetpack responsive videos, and they are
// already supported in core.
// @see https://github.com/Automattic/jetpack/issues/17170
remove_theme_support( 'jetpack-responsive-videos' );
} // end c4aa_setup_theme_supported_features
add_action( 'after_setup_theme', 'c4aa_setup_theme_supported_features', 11 );
/**
* Filter to disable post thumbnail display for 'people' custom post type.
*
* @param bool $can_show Whether the post thumbnail can be displayed.
* @return bool Modified value for post thumbnail display.
*/
function my_child_theme_disable_people_post_thumbnail( $can_show ) {
if ( is_singular( 'people' ) ) {
return false;
}
return $can_show;
}
add_filter( 'twentynineteen_can_show_post_thumbnail', 'my_child_theme_disable_people_post_thumbnail', 20 );
/**
* Override default 2019 post thumbnail.
* Only change is adding the class for the image
* filter CSS algorithm, a-filter-child-img
*/
function twentynineteen_post_thumbnail() {
if ( ! twentynineteen_can_show_post_thumbnail() ) {
return;
}
if ( is_singular() ) :
?>
<figure class="post-thumbnail a-filter-child-img">
<?php the_post_thumbnail(); ?>
</figure><!-- .post-thumbnail -->
<?php
else :
?>
<figure class="post-thumbnail a-filter-child-img">
<a class="post-thumbnail-inner" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
<?php the_post_thumbnail( 'post-thumbnail' ); ?>
</a>
</figure>
<?php
endif; // End is_singular().
}
/* Register themes's custom blocks */
add_action( 'init', 'register_c4aa_org_blocks' );
function register_c4aa_org_blocks() {
register_block_type( dirname(__FILE__) . '/blocks/person-title');
register_block_type( dirname(__FILE__) . '/blocks/person-email' );
register_block_type( dirname(__FILE__) . '/blocks/promo-image' );
}
/* Register the block category all the theme's blocks sit in */
function c4aa_register_block_category( $block_categories, $editor_context ) {
if ( ! empty( $editor_context->post ) ) {
array_push(
$block_categories,
array(
'slug' => 'c4aa',
'title' => __( 'C4AA', 'c4aa-org' ),
'icon' => 'groups'
)
);
}
return $block_categories;
}
add_filter( 'block_categories_all', 'c4aa_register_block_category', 10, 2 );
/* oEmbeds */
function c4aa_add_custom_styles_to_embeds()
{
?>
<style>
.wp-embed {
font-family: "Work Sans", Helvetica Neue, Helvetica, Arial, sans-serif !important;
border: 1rem solid #f9f4d2 !important;
background-color: #fffef6 !important;
color: #292724 !important;
}
.wp-embed .wp-embed-heading, .wp-embed .wp-embed-site-title {
font-family: "Zilla Slab", Courier Bold, Courier, Georgia, Times, Times New Roman, serif;
}
.wp-embed .wp-embed-heading a {
text-decoration: underline;
text-decoration-style: dotted;
text-decoration-thickness: 10%;
text-underline-offset: 0.2em;
}
.wp-embed .wp-embed-heading a:hover {
text-decoration: underline;
text-decoration-style: solid;
text-decoration-thickness: 10%;
text-underline-offset: 0.2em;
text-decoration-skip-ink: none;
}
.wp-embed .wp-embed-site-title {
text-transform: uppercase;
font-weight: 400;
}
.wp-embed .wp-embed-site-title span {
color: #292724
}
.wp-embed a.wp-embed-more {
text-decoration: underline;
text-decoration-style: dotted;
text-decoration-thickness: 10%;
text-underline-offset: 0.2em;
color: #f5333f;
}
.wp-embed a.wp-embed-more:hover {
text-decoration: underline;
text-decoration-style: solid;
text-decoration-thickness: 10%;
text-underline-offset: 0.2em;
}
.wp-embed .button {
color: #7B736c;
}
.wp-embed .button:hover {
color: #27aae1;
}
</style>
<?php
}
add_action('embed_head', "c4aa_add_custom_styles_to_embeds");
// remove whisper pages from indexing
add_filter( 'wp_robots', function ( $robots ) {
if ( is_singular( 'whisper' ) ) {
$robots['noindex'] = true;
$robots['nofollow'] = true;
}
return $robots;
} );