Edit File by line
/home/barbar84/public_h.../wp-conte.../themes/twentytw.../inc
File: template-functions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Functions which enhance the theme by hooking into WordPress
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Twenty_Twenty_One
[5] Fix | Delete
* @since Twenty Twenty-One 1.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Adds custom classes to the array of body classes.
[10] Fix | Delete
*
[11] Fix | Delete
* @since Twenty Twenty-One 1.0
[12] Fix | Delete
*
[13] Fix | Delete
* @param array $classes Classes for the body element.
[14] Fix | Delete
*
[15] Fix | Delete
* @return array
[16] Fix | Delete
*/
[17] Fix | Delete
function twenty_twenty_one_body_classes( $classes ) {
[18] Fix | Delete
[19] Fix | Delete
// Helps detect if JS is enabled or not.
[20] Fix | Delete
$classes[] = 'no-js';
[21] Fix | Delete
[22] Fix | Delete
// Adds `singular` to singular pages, and `hfeed` to all other pages.
[23] Fix | Delete
$classes[] = is_singular() ? 'singular' : 'hfeed';
[24] Fix | Delete
[25] Fix | Delete
// Add a body class if main navigation is active.
[26] Fix | Delete
if ( has_nav_menu( 'primary' ) ) {
[27] Fix | Delete
$classes[] = 'has-main-navigation';
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
// Add a body class if there are no footer widgets.
[31] Fix | Delete
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
[32] Fix | Delete
$classes[] = 'no-widgets';
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
return $classes;
[36] Fix | Delete
}
[37] Fix | Delete
add_filter( 'body_class', 'twenty_twenty_one_body_classes' );
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Adds custom class to the array of posts classes.
[41] Fix | Delete
*
[42] Fix | Delete
* @since Twenty Twenty-One 1.0
[43] Fix | Delete
*
[44] Fix | Delete
* @param array $classes An array of CSS classes.
[45] Fix | Delete
*
[46] Fix | Delete
* @return array
[47] Fix | Delete
*/
[48] Fix | Delete
function twenty_twenty_one_post_classes( $classes ) {
[49] Fix | Delete
$classes[] = 'entry';
[50] Fix | Delete
[51] Fix | Delete
return $classes;
[52] Fix | Delete
}
[53] Fix | Delete
add_filter( 'post_class', 'twenty_twenty_one_post_classes', 10, 3 );
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
[57] Fix | Delete
*
[58] Fix | Delete
* @since Twenty Twenty-One 1.0
[59] Fix | Delete
*
[60] Fix | Delete
* @return void
[61] Fix | Delete
*/
[62] Fix | Delete
function twenty_twenty_one_pingback_header() {
[63] Fix | Delete
if ( is_singular() && pings_open() ) {
[64] Fix | Delete
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
add_action( 'wp_head', 'twenty_twenty_one_pingback_header' );
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Remove the `no-js` class from body if JS is supported.
[71] Fix | Delete
*
[72] Fix | Delete
* @since Twenty Twenty-One 1.0
[73] Fix | Delete
*
[74] Fix | Delete
* @return void
[75] Fix | Delete
*/
[76] Fix | Delete
function twenty_twenty_one_supports_js() {
[77] Fix | Delete
echo '<script>document.body.classList.remove("no-js");</script>';
[78] Fix | Delete
}
[79] Fix | Delete
add_action( 'wp_footer', 'twenty_twenty_one_supports_js' );
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Changes comment form default fields.
[83] Fix | Delete
*
[84] Fix | Delete
* @since Twenty Twenty-One 1.0
[85] Fix | Delete
*
[86] Fix | Delete
* @param array $defaults The form defaults.
[87] Fix | Delete
*
[88] Fix | Delete
* @return array
[89] Fix | Delete
*/
[90] Fix | Delete
function twenty_twenty_one_comment_form_defaults( $defaults ) {
[91] Fix | Delete
[92] Fix | Delete
// Adjust height of comment form.
[93] Fix | Delete
$defaults['comment_field'] = preg_replace( '/rows="\d+"/', 'rows="5"', $defaults['comment_field'] );
[94] Fix | Delete
[95] Fix | Delete
return $defaults;
[96] Fix | Delete
}
[97] Fix | Delete
add_filter( 'comment_form_defaults', 'twenty_twenty_one_comment_form_defaults' );
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Determines if post thumbnail can be displayed.
[101] Fix | Delete
*
[102] Fix | Delete
* @since Twenty Twenty-One 1.0
[103] Fix | Delete
*
[104] Fix | Delete
* @return bool
[105] Fix | Delete
*/
[106] Fix | Delete
function twenty_twenty_one_can_show_post_thumbnail() {
[107] Fix | Delete
return apply_filters(
[108] Fix | Delete
'twenty_twenty_one_can_show_post_thumbnail',
[109] Fix | Delete
! post_password_required() && ! is_attachment() && has_post_thumbnail()
[110] Fix | Delete
);
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Returns the size for avatars used in the theme.
[115] Fix | Delete
*
[116] Fix | Delete
* @since Twenty Twenty-One 1.0
[117] Fix | Delete
*
[118] Fix | Delete
* @return int
[119] Fix | Delete
*/
[120] Fix | Delete
function twenty_twenty_one_get_avatar_size() {
[121] Fix | Delete
return 60;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* Creates continue reading text
[126] Fix | Delete
*/
[127] Fix | Delete
function twenty_twenty_one_continue_reading_text() {
[128] Fix | Delete
$continue_reading = sprintf(
[129] Fix | Delete
/* translators: %s: Name of current post. */
[130] Fix | Delete
esc_html__( 'Continue reading %s', 'twentytwentyone' ),
[131] Fix | Delete
the_title( '<span class="screen-reader-text">', '</span>', false )
[132] Fix | Delete
);
[133] Fix | Delete
[134] Fix | Delete
return $continue_reading;
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Create the continue reading link for excerpt.
[139] Fix | Delete
*/
[140] Fix | Delete
function twenty_twenty_one_continue_reading_link_excerpt() {
[141] Fix | Delete
if ( ! is_admin() ) {
[142] Fix | Delete
return '&hellip; <a class="more-link" href="' . esc_url( get_permalink() ) . '">' . twenty_twenty_one_continue_reading_text() . '</a>';
[143] Fix | Delete
}
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
// Filter the excerpt more link.
[147] Fix | Delete
add_filter( 'excerpt_more', 'twenty_twenty_one_continue_reading_link_excerpt' );
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Create the continue reading link.
[151] Fix | Delete
*/
[152] Fix | Delete
function twenty_twenty_one_continue_reading_link() {
[153] Fix | Delete
if ( ! is_admin() ) {
[154] Fix | Delete
return '<div class="more-link-container"><a class="more-link" href="' . esc_url( get_permalink() ) . '#more-' . esc_attr( get_the_ID() ) . '">' . twenty_twenty_one_continue_reading_text() . '</a></div>';
[155] Fix | Delete
}
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
// Filter the excerpt more link.
[159] Fix | Delete
add_filter( 'the_content_more_link', 'twenty_twenty_one_continue_reading_link' );
[160] Fix | Delete
[161] Fix | Delete
if ( ! function_exists( 'twenty_twenty_one_post_title' ) ) {
[162] Fix | Delete
/**
[163] Fix | Delete
* Add a title to posts and pages that are missing titles.
[164] Fix | Delete
*
[165] Fix | Delete
* @since Twenty Twenty-One 1.0
[166] Fix | Delete
*
[167] Fix | Delete
* @param string $title The title.
[168] Fix | Delete
*
[169] Fix | Delete
* @return string
[170] Fix | Delete
*/
[171] Fix | Delete
function twenty_twenty_one_post_title( $title ) {
[172] Fix | Delete
return '' === $title ? esc_html_x( 'Untitled', 'Added to posts and pages that are missing titles', 'twentytwentyone' ) : $title;
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
add_filter( 'the_title', 'twenty_twenty_one_post_title' );
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Gets the SVG code for a given icon.
[179] Fix | Delete
*
[180] Fix | Delete
* @since Twenty Twenty-One 1.0
[181] Fix | Delete
*
[182] Fix | Delete
* @param string $group The icon group.
[183] Fix | Delete
* @param string $icon The icon.
[184] Fix | Delete
* @param int $size The icon size in pixels.
[185] Fix | Delete
*
[186] Fix | Delete
* @return string
[187] Fix | Delete
*/
[188] Fix | Delete
function twenty_twenty_one_get_icon_svg( $group, $icon, $size = 24 ) {
[189] Fix | Delete
return Twenty_Twenty_One_SVG_Icons::get_svg( $group, $icon, $size );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* Changes the default navigation arrows to svg icons
[194] Fix | Delete
*
[195] Fix | Delete
* @param string $calendar_output The generated HTML of the calendar.
[196] Fix | Delete
*
[197] Fix | Delete
* @return string
[198] Fix | Delete
*/
[199] Fix | Delete
function twenty_twenty_one_change_calendar_nav_arrows( $calendar_output ) {
[200] Fix | Delete
$calendar_output = str_replace( '&laquo; ', is_rtl() ? twenty_twenty_one_get_icon_svg( 'ui', 'arrow_right' ) : twenty_twenty_one_get_icon_svg( 'ui', 'arrow_left' ), $calendar_output );
[201] Fix | Delete
$calendar_output = str_replace( ' &raquo;', is_rtl() ? twenty_twenty_one_get_icon_svg( 'ui', 'arrow_left' ) : twenty_twenty_one_get_icon_svg( 'ui', 'arrow_right' ), $calendar_output );
[202] Fix | Delete
return $calendar_output;
[203] Fix | Delete
}
[204] Fix | Delete
add_filter( 'get_calendar', 'twenty_twenty_one_change_calendar_nav_arrows' );
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* Get custom CSS.
[208] Fix | Delete
*
[209] Fix | Delete
* Return CSS for non-latin language, if available, or null
[210] Fix | Delete
*
[211] Fix | Delete
* @param string $type Whether to return CSS for the "front-end", "block-editor" or "classic-editor".
[212] Fix | Delete
*
[213] Fix | Delete
* @return string
[214] Fix | Delete
*/
[215] Fix | Delete
function twenty_twenty_one_get_non_latin_css( $type = 'front-end' ) {
[216] Fix | Delete
[217] Fix | Delete
// Fetch site locale.
[218] Fix | Delete
$locale = get_bloginfo( 'language' );
[219] Fix | Delete
[220] Fix | Delete
// Define fallback fonts for non-latin languages.
[221] Fix | Delete
$font_family = apply_filters(
[222] Fix | Delete
'twenty_twenty_one_get_localized_font_family_types',
[223] Fix | Delete
array(
[224] Fix | Delete
[225] Fix | Delete
// Arabic.
[226] Fix | Delete
'ar' => array( 'Tahoma', 'Arial', 'sans-serif' ),
[227] Fix | Delete
'ary' => array( 'Tahoma', 'Arial', 'sans-serif' ),
[228] Fix | Delete
'azb' => array( 'Tahoma', 'Arial', 'sans-serif' ),
[229] Fix | Delete
'ckb' => array( 'Tahoma', 'Arial', 'sans-serif' ),
[230] Fix | Delete
'fa-IR' => array( 'Tahoma', 'Arial', 'sans-serif' ),
[231] Fix | Delete
'haz' => array( 'Tahoma', 'Arial', 'sans-serif' ),
[232] Fix | Delete
'ps' => array( 'Tahoma', 'Arial', 'sans-serif' ),
[233] Fix | Delete
[234] Fix | Delete
// Chinese Simplified (China) - Noto Sans SC.
[235] Fix | Delete
'zh-CN' => array( '\'PingFang SC\'', '\'Helvetica Neue\'', '\'Microsoft YaHei New\'', '\'STHeiti Light\'', 'sans-serif' ),
[236] Fix | Delete
[237] Fix | Delete
// Chinese Traditional (Taiwan) - Noto Sans TC.
[238] Fix | Delete
'zh-TW' => array( '\'PingFang TC\'', '\'Helvetica Neue\'', '\'Microsoft YaHei New\'', '\'STHeiti Light\'', 'sans-serif' ),
[239] Fix | Delete
[240] Fix | Delete
// Chinese (Hong Kong) - Noto Sans HK.
[241] Fix | Delete
'zh-HK' => array( '\'PingFang HK\'', '\'Helvetica Neue\'', '\'Microsoft YaHei New\'', '\'STHeiti Light\'', 'sans-serif' ),
[242] Fix | Delete
[243] Fix | Delete
// Cyrillic.
[244] Fix | Delete
'bel' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[245] Fix | Delete
'bg-BG' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[246] Fix | Delete
'kk' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[247] Fix | Delete
'mk-MK' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[248] Fix | Delete
'mn' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[249] Fix | Delete
'ru-RU' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[250] Fix | Delete
'sah' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[251] Fix | Delete
'sr-RS' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[252] Fix | Delete
'tt-RU' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[253] Fix | Delete
'uk' => array( '\'Helvetica Neue\'', 'Helvetica', '\'Segoe UI\'', 'Arial', 'sans-serif' ),
[254] Fix | Delete
[255] Fix | Delete
// Devanagari.
[256] Fix | Delete
'bn-BD' => array( 'Arial', 'sans-serif' ),
[257] Fix | Delete
'hi-IN' => array( 'Arial', 'sans-serif' ),
[258] Fix | Delete
'mr' => array( 'Arial', 'sans-serif' ),
[259] Fix | Delete
'ne-NP' => array( 'Arial', 'sans-serif' ),
[260] Fix | Delete
[261] Fix | Delete
// Greek.
[262] Fix | Delete
'el' => array( '\'Helvetica Neue\', Helvetica, Arial, sans-serif' ),
[263] Fix | Delete
[264] Fix | Delete
// Gujarati.
[265] Fix | Delete
'gu' => array( 'Arial', 'sans-serif' ),
[266] Fix | Delete
[267] Fix | Delete
// Hebrew.
[268] Fix | Delete
'he-IL' => array( '\'Arial Hebrew\'', 'Arial', 'sans-serif' ),
[269] Fix | Delete
[270] Fix | Delete
// Japanese.
[271] Fix | Delete
'ja' => array( 'sans-serif' ),
[272] Fix | Delete
[273] Fix | Delete
// Korean.
[274] Fix | Delete
'ko-KR' => array( '\'Apple SD Gothic Neo\'', '\'Malgun Gothic\'', '\'Nanum Gothic\'', 'Dotum', 'sans-serif' ),
[275] Fix | Delete
[276] Fix | Delete
// Thai.
[277] Fix | Delete
'th' => array( '\'Sukhumvit Set\'', '\'Helvetica Neue\'', 'Helvetica', 'Arial', 'sans-serif' ),
[278] Fix | Delete
[279] Fix | Delete
// Vietnamese.
[280] Fix | Delete
'vi' => array( '\'Libre Franklin\'', 'sans-serif' ),
[281] Fix | Delete
[282] Fix | Delete
)
[283] Fix | Delete
);
[284] Fix | Delete
[285] Fix | Delete
// Return if the selected language has no fallback fonts.
[286] Fix | Delete
if ( empty( $font_family[ $locale ] ) ) {
[287] Fix | Delete
return '';
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
// Define elements to apply fallback fonts to.
[291] Fix | Delete
$elements = apply_filters(
[292] Fix | Delete
'twenty_twenty_one_get_localized_font_family_elements',
[293] Fix | Delete
array(
[294] Fix | Delete
'front-end' => array( 'body', 'input', 'textarea', 'button', '.button', '.faux-button', '.wp-block-button__link', '.wp-block-file__button', '.has-drop-cap:not(:focus)::first-letter', '.has-drop-cap:not(:focus)::first-letter', '.entry-content .wp-block-archives', '.entry-content .wp-block-categories', '.entry-content .wp-block-cover-image', '.entry-content .wp-block-latest-comments', '.entry-content .wp-block-latest-posts', '.entry-content .wp-block-pullquote', '.entry-content .wp-block-quote.is-large', '.entry-content .wp-block-quote.is-style-large', '.entry-content .wp-block-archives *', '.entry-content .wp-block-categories *', '.entry-content .wp-block-latest-posts *', '.entry-content .wp-block-latest-comments *', '.entry-content p', '.entry-content ol', '.entry-content ul', '.entry-content dl', '.entry-content dt', '.entry-content cite', '.entry-content figcaption', '.entry-content .wp-caption-text', '.comment-content p', '.comment-content ol', '.comment-content ul', '.comment-content dl', '.comment-content dt', '.comment-content cite', '.comment-content figcaption', '.comment-content .wp-caption-text', '.widget_text p', '.widget_text ol', '.widget_text ul', '.widget_text dl', '.widget_text dt', '.widget-content .rssSummary', '.widget-content cite', '.widget-content figcaption', '.widget-content .wp-caption-text' ),
[295] Fix | Delete
'block-editor' => array( '.editor-styles-wrapper > *', '.editor-styles-wrapper p', '.editor-styles-wrapper ol', '.editor-styles-wrapper ul', '.editor-styles-wrapper dl', '.editor-styles-wrapper dt', '.editor-post-title__block .editor-post-title__input', '.editor-styles-wrapper .wp-block h1', '.editor-styles-wrapper .wp-block h2', '.editor-styles-wrapper .wp-block h3', '.editor-styles-wrapper .wp-block h4', '.editor-styles-wrapper .wp-block h5', '.editor-styles-wrapper .wp-block h6', '.editor-styles-wrapper .has-drop-cap:not(:focus)::first-letter', '.editor-styles-wrapper cite', '.editor-styles-wrapper figcaption', '.editor-styles-wrapper .wp-caption-text' ),
[296] Fix | Delete
'classic-editor' => array( 'body#tinymce.wp-editor', 'body#tinymce.wp-editor p', 'body#tinymce.wp-editor ol', 'body#tinymce.wp-editor ul', 'body#tinymce.wp-editor dl', 'body#tinymce.wp-editor dt', 'body#tinymce.wp-editor figcaption', 'body#tinymce.wp-editor .wp-caption-text', 'body#tinymce.wp-editor .wp-caption-dd', 'body#tinymce.wp-editor cite', 'body#tinymce.wp-editor table' ),
[297] Fix | Delete
)
[298] Fix | Delete
);
[299] Fix | Delete
[300] Fix | Delete
// Return if the specified type doesn't exist.
[301] Fix | Delete
if ( empty( $elements[ $type ] ) ) {
[302] Fix | Delete
return '';
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
// Include file if function doesn't exist.
[306] Fix | Delete
if ( ! function_exists( 'twenty_twenty_one_generate_css' ) ) {
[307] Fix | Delete
require_once get_theme_file_path( 'inc/custom-css.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
// Return the specified styles.
[311] Fix | Delete
return twenty_twenty_one_generate_css( // @phpstan-ignore-line.
[312] Fix | Delete
implode( ',', $elements[ $type ] ),
[313] Fix | Delete
'font-family',
[314] Fix | Delete
implode( ',', $font_family[ $locale ] ),
[315] Fix | Delete
null,
[316] Fix | Delete
null,
[317] Fix | Delete
false
[318] Fix | Delete
);
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
/**
[322] Fix | Delete
* Print the first instance of a block in the content, and then break away.
[323] Fix | Delete
*
[324] Fix | Delete
* @since Twenty Twenty-One 1.0
[325] Fix | Delete
*
[326] Fix | Delete
* @param string $block_name The full block type name, or a partial match.
[327] Fix | Delete
* Example: `core/image`, `core-embed/*`.
[328] Fix | Delete
* @param string|null $content The content to search in. Use null for get_the_content().
[329] Fix | Delete
* @param int $instances How many instances of the block will be printed (max). Defaults to 1.
[330] Fix | Delete
*
[331] Fix | Delete
* @return bool Returns true if a block was located & printed, otherwise false.
[332] Fix | Delete
*/
[333] Fix | Delete
function twenty_twenty_one_print_first_instance_of_block( $block_name, $content = null, $instances = 1 ) {
[334] Fix | Delete
$instances_count = 0;
[335] Fix | Delete
$blocks_content = '';
[336] Fix | Delete
[337] Fix | Delete
if ( ! $content ) {
[338] Fix | Delete
$content = get_the_content();
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
// Parse blocks in the content.
[342] Fix | Delete
$blocks = parse_blocks( $content );
[343] Fix | Delete
[344] Fix | Delete
// Loop blocks.
[345] Fix | Delete
foreach ( $blocks as $block ) {
[346] Fix | Delete
[347] Fix | Delete
// Sanity check.
[348] Fix | Delete
if ( ! isset( $block['blockName'] ) ) {
[349] Fix | Delete
continue;
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
// Check if this the block matches the $block_name.
[353] Fix | Delete
$is_matching_block = false;
[354] Fix | Delete
[355] Fix | Delete
// If the block ends with *, try to match the first portion.
[356] Fix | Delete
if ( '*' === $block_name[-1] ) {
[357] Fix | Delete
$is_matching_block = 0 === strpos( $block['blockName'], rtrim( $block_name, '*' ) );
[358] Fix | Delete
} else {
[359] Fix | Delete
$is_matching_block = $block_name === $block['blockName'];
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
if ( $is_matching_block ) {
[363] Fix | Delete
// Increment count.
[364] Fix | Delete
$instances_count++;
[365] Fix | Delete
[366] Fix | Delete
// Add the block HTML.
[367] Fix | Delete
$blocks_content .= render_block( $block );
[368] Fix | Delete
[369] Fix | Delete
// Break the loop if the $instances count was reached.
[370] Fix | Delete
if ( $instances_count >= $instances ) {
[371] Fix | Delete
break;
[372] Fix | Delete
}
[373] Fix | Delete
}
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
if ( $blocks_content ) {
[377] Fix | Delete
echo apply_filters( 'the_content', $blocks_content ); // phpcs:ignore WordPress.Security.EscapeOutput
[378] Fix | Delete
return true;
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
return false;
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
/**
[385] Fix | Delete
* Retrieve protected post password form content.
[386] Fix | Delete
*
[387] Fix | Delete
* @since Twenty Twenty-One 1.0
[388] Fix | Delete
*
[389] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
[390] Fix | Delete
* @return string HTML content for password form for password protected post.
[391] Fix | Delete
*/
[392] Fix | Delete
function twenty_twenty_one_password_form( $post = 0 ) {
[393] Fix | Delete
$post = get_post( $post );
[394] Fix | Delete
$label = 'pwbox-' . ( empty( $post->ID ) ? wp_rand() : $post->ID );
[395] Fix | Delete
$output = '<p class="post-password-message">' . esc_html__( 'This content is password protected. Please enter a password to view.', 'twentytwentyone' ) . '</p>
[396] Fix | Delete
<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
[397] Fix | Delete
<label class="post-password-form__label" for="' . esc_attr( $label ) . '">' . esc_html_x( 'Password', 'Post password form', 'twentytwentyone' ) . '</label><input class="post-password-form__input" name="post_password" id="' . esc_attr( $label ) . '" type="password" size="20" /><input type="submit" class="post-password-form__submit" name="' . esc_attr_x( 'Submit', 'Post password form', 'twentytwentyone' ) . '" value="' . esc_attr_x( 'Enter', 'Post password form', 'twentytwentyone' ) . '" /></form>
[398] Fix | Delete
';
[399] Fix | Delete
return $output;
[400] Fix | Delete
}
[401] Fix | Delete
add_filter( 'the_password_form', 'twenty_twenty_one_password_form' );
[402] Fix | Delete
[403] Fix | Delete
/**
[404] Fix | Delete
* Filters the list of attachment image attributes.
[405] Fix | Delete
*
[406] Fix | Delete
* @since Twenty Twenty-One 1.0
[407] Fix | Delete
*
[408] Fix | Delete
* @param array $attr Array of attribute values for the image markup, keyed by attribute name.
[409] Fix | Delete
* See wp_get_attachment_image().
[410] Fix | Delete
* @param WP_Post $attachment Image attachment post.
[411] Fix | Delete
* @param string|array $size Requested size. Image size or array of width and height values
[412] Fix | Delete
* (in that order). Default 'thumbnail'.
[413] Fix | Delete
*
[414] Fix | Delete
* @return array
[415] Fix | Delete
*/
[416] Fix | Delete
function twenty_twenty_one_get_attachment_image_attributes( $attr, $attachment, $size ) {
[417] Fix | Delete
[418] Fix | Delete
if ( isset( $attr['class'] ) && false !== strpos( $attr['class'], 'custom-logo' ) ) {
[419] Fix | Delete
return $attr;
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
$width = false;
[423] Fix | Delete
$height = false;
[424] Fix | Delete
[425] Fix | Delete
if ( is_array( $size ) ) {
[426] Fix | Delete
$width = (int) $size[0];
[427] Fix | Delete
$height = (int) $size[1];
[428] Fix | Delete
} elseif ( $attachment && is_object( $attachment ) && $attachment->ID ) {
[429] Fix | Delete
$meta = wp_get_attachment_metadata( $attachment->ID );
[430] Fix | Delete
if ( $meta['width'] && $meta['height'] ) {
[431] Fix | Delete
$width = (int) $meta['width'];
[432] Fix | Delete
$height = (int) $meta['height'];
[433] Fix | Delete
}
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
if ( $width && $height ) {
[437] Fix | Delete
[438] Fix | Delete
// Add style.
[439] Fix | Delete
$attr['style'] = isset( $attr['style'] ) ? $attr['style'] : '';
[440] Fix | Delete
$attr['style'] = 'width:100%;height:' . round( 100 * $height / $width, 2 ) . '%;max-width:' . $width . 'px;' . $attr['style'];
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
return $attr;
[444] Fix | Delete
}
[445] Fix | Delete
add_filter( 'wp_get_attachment_image_attributes', 'twenty_twenty_one_get_attachment_image_attributes', 10, 3 );
[446] Fix | Delete
[447] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function