-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.php
executable file
·775 lines (643 loc) · 20.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
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
<?php
/**
* URI Modern functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package uri-modern
*/
require 'inc/get-breadcrumbs.php';
/**
* Returns a string to be used for cache busting
*
* @return str
*/
function uri_modern_cache_buster() {
static $cache_buster;
if ( empty( $cache_buster ) ) {
$cache_buster = wp_get_theme()->get( 'Version' );
// $cache_buster = date(time());
}
return $cache_buster;
}
/**
* Returns the root domain to use
*
* @return str
*/
function uri_modern_get_the_domain( $sub = 'www' ) {
if ( 'web' === $sub ) {
return defined( 'URI_DOMAIN_WEB' ) ? URI_DOMAIN_WEB : 'web.uri.edu';
}
return defined( 'URI_DOMAIN_WWW' ) ? URI_DOMAIN_WWW : 'www.uri.edu';
}
/**
* Echos the root domain to use
*/
function uri_modern_the_domain( $sub = 'www' ) {
echo uri_modern_get_the_domain( $sub );
}
if ( ! function_exists( 'uri_modern_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 uri_modern_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on _s, use a find and replace
* to change 'uri' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'uri', 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' );
// add custom URI image sizes
add_image_size( 'thumbnail@2x', 300, 300, true );
add_image_size( 'third_column', 364 );
add_image_size( 'half_column', 500 );
add_image_size( 'full_column', 1000 );
add_image_size( 'hero', 1280 );
add_image_size( 'full_column@2x', 2000 );
add_image_size( 'hero@2x', 2560 );
// This theme uses wp_nav_menu() in one location.
register_nav_menus(
array(
'menu-1' => esc_html__( 'Primary', 'uri' ),
)
);
/*
* 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',
)
);
// Set up the WordPress core custom background feature.
add_theme_support(
'custom-background',
apply_filters(
'uri_modern_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => '',
)
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Add theme support for post formats
add_theme_support(
'post-formats',
array(
'video',
)
);
}
endif;
add_action( 'after_setup_theme', 'uri_modern_setup' );
/**
* Label the custom image sizes.
*/
function uri_modern_custom_sizes( $sizes ) {
return array_merge(
$sizes,
array(
'thumbnail@2x' => __( 'Thumbnail @2x', 'uri' ),
'third_column' => __( 'Third Column', 'uri' ),
'half_column' => __( 'Half Column', 'uri' ),
'full_column' => __( 'Full Column', 'uri' ),
'hero' => __( 'Hero', 'uri' ),
'full_column@2x' => __( 'Full Column @2x', 'uri' ),
'hero@2x' => __( 'Hero @2x', 'uri' ),
)
);
}
add_filter( 'image_size_names_choose', 'uri_modern_custom_sizes' );
/**
* Set max srcset image width to 2560px
*/
function set_max_srcset_image_width( $max_width ) {
$max_width = 2560;
return $max_width;
}
add_filter( 'max_srcset_image_width', 'set_max_srcset_image_width' );
/**
* Enables the Excerpt meta box in Page edit screen.
*/
function uri_modern_add_excerpt_support_for_pages() {
add_post_type_support( 'page', 'excerpt' );
}
add_action( 'init', 'uri_modern_add_excerpt_support_for_pages' );
/**
* Add post-formats to post_type 'post'.
*/
function uri_modern_add_post_formats_to_post() {
add_post_type_support( 'post', 'post-formats' );
register_taxonomy_for_object_type( 'post_format', 'post' );
}
add_action( 'init', 'uri_modern_add_post_formats_to_post', 11 );
/**
* 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 uri_modern_content_width() {
$GLOBALS['content_width'] = apply_filters( 'uri_modern_content_width', 1000 );
}
add_action( 'after_setup_theme', 'uri_modern_content_width', 0 );
/**
* Add open graph elements to the <head>
*
* @todo: allow other twitter handles
*/
function uri_modern_open_graph() {
global $post;
$summary_type = 'summary';
if ( is_single() || is_page() ) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
if ( is_array( $image ) ) {
// use a larger image in twitter card if the image is wider than it is tall.
$landscape = ( $image[1] > $image[2] );
if ( true === $landscape ) {
$summary_type = 'summary_large_image';
}
$image_thumb = $image[0];
}
if ( empty( $image_thumb ) ) {
$image_thumb = get_template_directory_uri() . '/images/logo-wordmark.png';
$summary_type = 'summary_large_image';
}
$title = get_the_title();
if ( empty( $title ) ) {
$title = get_bloginfo( 'name', 'display' ); }
$excerpt = get_the_excerpt();
if ( empty( $excerpt ) ) {
if ( strpos( $post->post_content, '<!--more' ) !== false ) {
$bits = explode( '<!--more', $post->post_content );
} else {
$bits = explode( "\n", wordwrap( $post->post_content, 400 ) );
}
$excerpt = $bits[0];
}
$excerpt = do_shortcode( $excerpt ); // parse shortcodes
$excerpt = preg_replace( '/(<[^>]+>)+/', ' ... ', $excerpt ); // replace html
$excerpt = ltrim( $excerpt, ' .' ); // remove leading points of ellipses from replace
$excerpt = str_replace( '"', '"', $excerpt ); // sanitize quotes
$excerpt = trim( $excerpt ); // remove whitespace on either end
?>
<meta name="description" content="<?php echo $excerpt; ?>" />
<meta name="twitter:card" content="<?php echo $summary_type; ?>" />
<meta name="twitter:site" content="@universityofri" />
<meta name="twitter:creator" content="@universityofri" />
<meta property="og:url" content="<?php echo get_permalink(); ?>" />
<meta property="og:title" content="<?php echo $title; ?>" />
<meta property="og:description" content="<?php echo $excerpt; ?>" />
<?php
if ( $image_thumb ) :
?>
<meta property="og:image" content="<?php echo $image_thumb; ?>" />
<?php
endif;
}
}
add_action( 'wp_head', 'uri_modern_open_graph' );
/**
* Set the Google Search identifier
*/
function uri_modern_the_gs_id() {
echo '016863979916529535900:17qai8akniu';
}
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function uri_modern_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Banner', 'uri' ),
'id' => 'banner',
'description' => esc_html__( 'Widgets here appear between the brandbar and sitebar', 'uri' ),
'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__( 'Before Content', 'uri' ),
'id' => 'before-content',
'description' => esc_html__( 'Widgets here appear after the header and above the content.', 'uri' ),
'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__( 'After Content', 'uri' ),
'id' => 'after-content',
'description' => esc_html__( 'Widgets here appear after content and above the footer.', 'uri' ),
'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', 'uri_modern_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function uri_modern_scripts() {
$values = array(
'base' => get_site_url(),
'path' => array(
'page' => get_permalink(),
'theme' => get_stylesheet_directory_uri(),
'themes' => get_theme_root_uri(),
'plugins' => WP_PLUGIN_URL,
),
'theme' => array(
'name' => wp_get_theme()->get( 'Name' ),
'version' => wp_get_theme()->get( 'Version' ),
'textDomain' => wp_get_theme()->get( 'TextDomain' ),
),
'is' => array(
'404' => is_404(),
'childTheme' => get_template_directory_uri() != get_stylesheet_directory_uri() ? true : false,
'admin' => uri_modern_has_admin_privilages(),
),
'features' => array(),
);
wp_enqueue_style( 'uri-modern-style', get_template_directory_uri() . '/style.css', array(), uri_modern_cache_buster(), 'all' );
wp_enqueue_script( 'uri-modern-navigation', get_template_directory_uri() . '/js/navigation.js', array(), uri_modern_cache_buster(), true );
wp_enqueue_script( 'uri-modern-smoothscroll', get_template_directory_uri() . '/js/smoothscroll.min.js', array(), uri_modern_cache_buster(), true );
wp_enqueue_script( 'uri-modern-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), uri_modern_cache_buster(), true );
wp_enqueue_script( 'uri-modern-scripts', get_template_directory_uri() . '/js/script.min.js', array('jquery'), uri_modern_cache_buster(), true );
wp_localize_script( 'uri-modern-scripts', 'URIMODERN', $values );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'uri_modern_scripts' );
/**
* Enable styles in the WYSIWYG Editor (BETA FEATURE)
*/
if ( get_option( 'beta_editor_theme_styles' ) ) {
if ( is_admin() ) {
add_editor_style( get_template_directory_uri() . '/style.css', __FILE__ );
}
}
/**
* Gets the current WP path as known by Apache, not WordPress.
*
* @param bool $strip is a switch to strip slashes from the end of the URL.
* It does this so that paths like "who" and "who/*" can be differentiated.
* Otherwise, there's no way to single out "who".
*
* @return str
*/
function uri_modern_get_current_path( $strip = true ) {
if ( ! isset( $_SERVER['HTTP_REFERER'] ) || strpos( $_SERVER['HTTP_REFERER'], 'wp-admin/customize.php' ) === false ) {
$current_path = trim( $_SERVER['REQUEST_URI'] );
} else {
// when the Customizer is being used, we need to use the referrer
// because the Request URI is a different endpoint.
$url = parse_url( $_SERVER['HTTP_REFERER'] );
$q = trim( urldecode( $url['query'] ) );
$q = str_replace( 'url=', '', $q );
$url = parse_url( $q );
$current_path = $url['path'];
}
$base_bits = parse_url( site_url() );
if ( ! empty( $current_path ) && ! empty( $base_bits['path'] ) ) {
if ( strpos( $current_path, $base_bits['path'] ) === 0 ) {
$current_path = substr( $current_path, strlen( $base_bits['path'] ) );
}
}
if ( true === $strip ) {
$current_path = rtrim( $current_path, '/' );
}
return $current_path;
}
/**
* Wrap oembeds with a styleable class
*
* @param str $html the html.
* @param str $url is the URL that was originally included in the post.
* @param arr $attr is an array with width and height... neither value seems to have a purpose.
* @param str $post_id is the id of the current post.
*/
function uri_modern_embed_oembed_html( $html, $url, $attr, $post_id ) {
// parse the URL of the embed to convert the domain name into a CSS class.
preg_match( '#(http|ftp)s?://(www\.)?([a-z0-9\.\-]+)/?.*#i', $url, $matches );
$server_class = str_replace( '.', '-', $matches[3] );
return '<div class="oembed oembed-' . $server_class . '" style="" data-url="' . $url . '">' . $html . '</div>';
}
add_filter( 'embed_oembed_html', 'uri_modern_embed_oembed_html', 99, 4 );
/**
* People Tool compatibility
*
* @param str $template the template.
*/
function uri_modern_people_page_template( $template ) {
if ( is_singular( 'people' ) ) {
$new_template = locate_template( array( 'page.php' ) );
if ( '' != $new_template ) {
return $new_template;
}
}
return $template;
}
add_filter( 'template_include', 'uri_modern_people_page_template', 99 );
/**
* Get the featured image caption
*
* @param obj $post the post.
*/
function uri_modern_get_thumbnail_caption( $post ) {
if ( empty( $post ) ) {
return false;
}
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail_image = get_posts(
array(
'p' => $thumbnail_id,
'post_type' => 'attachment',
)
);
if ( $thumbnail_image && isset( $thumbnail_image[0] ) ) {
return nl2br( $thumbnail_image[0]->post_excerpt );
}
return '';
}
/**
* Remove WordPress page title prepends
*
* @param str $t the post title.
*/
function uri_modern_sanitize_title( $t ) {
$prepends = array(
'Category: ',
'Archive: ',
'Tag: ',
);
foreach ( $prepends as $p ) {
if ( substr( $t, 0, strlen( $p ) ) == $p ) {
return substr( $t, strlen( $p ) );
}
}
// still here, title can go out the way it came in.
return $t;
}
/**
* Wrapper for Advanced Custom Fields get_field()
*/
function uri_modern_get_field() {
$r = false;
if ( function_exists( 'get_field' ) ) {
$r = call_user_func_array( 'get_field', func_get_args() );
}
return $r;
}
/**
* Get user role
*/
function uri_modern_has_admin_privilages() {
$admin = false;
$role = current_user_can('administrator');
if ( $role ) {
$admin = true;
}
return $admin;
}
/**
* Callback function for Action Bar buttons
*/
function uri_modern_action_bar_link( $link ) {
$apply = apply_filters( 'uri_modern_action_bar_link', $link );
$atts = '';
if ( ! empty( $apply['title'] ) ) {
$atts .= ' title="' . esc_attr( $apply['title'] ) . '"';
}
if ( ! empty( $apply['class'] ) ) {
$atts .= ' class="' . esc_attr( $apply['class'] ) . '"';
}
return '<a href="' . esc_url( $apply['href'] ) . '" id="' . esc_attr( $apply['id'] ) . '" role="menuitem"><span role="presentation"' . $atts . '></span>' . wp_filter_post_kses( $apply['text'] ) . '</a>';
}
/**
* Filter for action bar buttons
*/
function uri_modern_action_bar_filter_callback( $a ) {
$defaults = array(
'class' => '',
'href' => 'https://' . uri_modern_get_the_domain() . '/apply',
'id' => 'action-apply',
'text' => 'Apply',
'title' => '',
);
// if we're in a graduate context, and it's the apply button, override the passed values
// @todo: how to allow for overrides in a non-clunky way?
// - changing $GLOBALS['actionbar_apply'] works
// - getting away from a global would be better
if ( empty( $a['text'] ) || 'Apply' === $a['text'] ) {
// it's an apply button, let's check for a context to determine grad or undergrad
$is_grad = get_option( 'action_bar_apply_url_is_graduate', false );
if ( ! $is_grad ) {
$field = uri_modern_get_field( 'is_graduate' );
if ( isset( $field[0] ) && 'graduate' === strtolower( $field[0] ) ) {
$is_grad = true;
}
}
if ( $is_grad ) {
// it's a grad school page, override the link
$a['href'] = 'https://' . uri_modern_get_the_domain() . '/apply/graduate';
$a['title'] = 'Apply with GradCAS';
}
}
// Finally, customize the link with supplied input
$link = array_replace( $defaults, $a );
return $link;
}
add_filter( 'uri_modern_action_bar_link', 'uri_modern_action_bar_filter_callback', 10, 1 );
/**
* Enable shortcodes in text widgets
*/
add_filter( 'widget_text', 'do_shortcode' );
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.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';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Layout options
*/
require get_template_directory() . '/inc/layout-options.php';
/**
* Shortcodes additions.
*/
require get_template_directory() . '/inc/shortcodes.php';
/**
* WYSIWYG additions
*/
require get_template_directory() . '/inc/wysiwyg.php';
/**
* Gutenberg additions
*/
require get_template_directory() . '/inc/gutenberg.php';
/**
* Display Posts customizations
*/
require get_template_directory() . '/inc/display-posts.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Load the Search and Filter helper functions
*/
require get_template_directory() . '/inc/search-filter.php';
/**
* Add page slug to body class list in the format 'ln-{slug}'
*
* @param array $classes the classes.
*/
function uri_modern_add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = 'ln-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'uri_modern_add_slug_body_class' );
/**
* Add a span around the title prefix so that the prefix can be hidden with CSS
* if desired.
* Note that this will only work with LTR languages.
*
* @see https://www.binarymoon.co.uk/2017/02/hide-archive-title-prefix-wordpress/
*
* @param string $title Archive title.
* @return string Archive title with inserted span around prefix.
*/
function uri_modern_hide_archive_title( $title ) {
// Skip if the site isn't LTR, this is visual, not functional.
// Should try to work out an elegant solution that works for both directions.
if ( is_rtl() ) {
return $title;
}
// Split the title into parts so we can wrap them with spans.
$title_parts = explode( ': ', $title, 2 );
// Given higher ed's propensity for colons in titles, let's be specific with our targeting
$hide = array( 'Category', 'Tag', 'Archives' );
// Glue it back together again.
if ( ! empty( $title_parts[1] ) && in_array( trim( $title_parts[0] ), $hide ) ) {
$title = wp_kses(
$title_parts[1],
array(
'span' => array(
'class' => array(),
),
)
);
$title = '<span class="screen-reader-text">' . esc_html( $title_parts[0] ) . ': </span>' . $title;
}
return $title;
}
add_filter( 'get_the_archive_title', 'uri_modern_hide_archive_title' );
/**
* Adds an image to the rss and atom feeds
*/
function uri_modern_add_image_to_feed() {
global $post;
$output = "\n";
if ( has_post_thumbnail( $post->ID ) ) {
$id = get_post_thumbnail_id( $post->ID );
$thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
$type = get_post_mime_type( $id );
if ( ! empty( $thumbnail ) ) {
$output .= "\t" . '<media:thumbnail url="' . $thumbnail[0] . '" width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" />' . "\n";
} else {
$url = get_template_directory_uri() . '/img/default/uri-200.png';
if ( 'rss2_item' === current_filter() ) {
$output .= '<enclosure url="' . $url . '" type="image/png" />' . "\n";
}
if ( 'atom_entry' === current_filter() ) {
$output .= '<link rel="enclosure" href="' . $url . '" type="image/png" />' . "\n";
}
}
$original = wp_get_attachment_image_src( $id, null );
if ( ! empty( $original ) ) {
$bytes = filesize( get_attached_file( $id ) );
$output .= "\t" . '<media:content url="' . $original[0] . '" type="' . $type . '" width="' . $original[1] . '" height="' . $original[2] . '" />' . "\n";
if ( 'rss2_item' === current_filter() ) {
$output .= "\t" . '<enclosure url="' . $original[0] . '" length="' . $bytes . '" type="' . $type . '" />' . "\n";
}
if ( 'atom_entry' === current_filter() ) {
$output .= "\t" . '<link rel="enclosure" href="' . $original[0] . '" length="' . $bytes . '" type="' . $type . '" />' . "\n";
}
}
}
echo $output;
}
add_action( 'rss2_item', 'uri_modern_add_image_to_feed' );
add_action( 'atom_entry', 'uri_modern_add_image_to_feed' );
/**
* Adds the correct name space for media elements in rss feed
*/
function uri_modern_add_media_namespace() {
echo "xmlns:media=\"http://search.yahoo.com/mrss/\"\n";
}
add_action( 'rss2_ns', 'uri_modern_add_media_namespace' );
add_action( 'atom_ns', 'uri_modern_add_media_namespace' );
// Allow webadmins to lock blocks from other users
add_filter(
'block_editor_settings_all',
static function( $settings ) {
// Allow for the Admin role and above.
$settings['canLockBlocks'] = current_user_can( 'administrator' );
return $settings;
},
10,
2
);