Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-inclu.../blocks
File: post-featured-image.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/post-featured-image` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/post-featured-image` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.8.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param array $attributes Block attributes.
[12] Fix | Delete
* @param string $content Block default content.
[13] Fix | Delete
* @param WP_Block $block Block instance.
[14] Fix | Delete
* @return string Returns the featured image for the current post.
[15] Fix | Delete
*/
[16] Fix | Delete
function render_block_core_post_featured_image( $attributes, $content, $block ) {
[17] Fix | Delete
if ( ! isset( $block->context['postId'] ) ) {
[18] Fix | Delete
return '';
[19] Fix | Delete
}
[20] Fix | Delete
$post_ID = $block->context['postId'];
[21] Fix | Delete
[22] Fix | Delete
$is_link = isset( $attributes['isLink'] ) && $attributes['isLink'];
[23] Fix | Delete
$size_slug = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail';
[24] Fix | Delete
$attr = get_block_core_post_featured_image_border_attributes( $attributes );
[25] Fix | Delete
$overlay_markup = get_block_core_post_featured_image_overlay_element_markup( $attributes );
[26] Fix | Delete
[27] Fix | Delete
if ( $is_link ) {
[28] Fix | Delete
if ( get_the_title( $post_ID ) ) {
[29] Fix | Delete
$attr['alt'] = trim( strip_tags( get_the_title( $post_ID ) ) );
[30] Fix | Delete
} else {
[31] Fix | Delete
$attr['alt'] = sprintf(
[32] Fix | Delete
// translators: %d is the post ID.
[33] Fix | Delete
__( 'Untitled post %d' ),
[34] Fix | Delete
$post_ID
[35] Fix | Delete
);
[36] Fix | Delete
}
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$extra_styles = '';
[40] Fix | Delete
[41] Fix | Delete
// Aspect ratio with a height set needs to override the default width/height.
[42] Fix | Delete
if ( ! empty( $attributes['aspectRatio'] ) ) {
[43] Fix | Delete
$extra_styles .= 'width:100%;height:100%;';
[44] Fix | Delete
} elseif ( ! empty( $attributes['height'] ) ) {
[45] Fix | Delete
$extra_styles .= "height:{$attributes['height']};";
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
if ( ! empty( $attributes['scale'] ) ) {
[49] Fix | Delete
$extra_styles .= "object-fit:{$attributes['scale']};";
[50] Fix | Delete
}
[51] Fix | Delete
if ( ! empty( $attributes['style']['shadow'] ) ) {
[52] Fix | Delete
$shadow_styles = wp_style_engine_get_styles( array( 'shadow' => $attributes['style']['shadow'] ) );
[53] Fix | Delete
[54] Fix | Delete
if ( ! empty( $shadow_styles['css'] ) ) {
[55] Fix | Delete
$extra_styles .= $shadow_styles['css'];
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
if ( ! empty( $extra_styles ) ) {
[60] Fix | Delete
$attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
$featured_image = get_the_post_thumbnail( $post_ID, $size_slug, $attr );
[64] Fix | Delete
[65] Fix | Delete
// Get the first image from the post.
[66] Fix | Delete
if ( $attributes['useFirstImageFromPost'] && ! $featured_image ) {
[67] Fix | Delete
$content_post = get_post( $post_ID );
[68] Fix | Delete
$content = $content_post->post_content;
[69] Fix | Delete
$processor = new WP_HTML_Tag_Processor( $content );
[70] Fix | Delete
[71] Fix | Delete
/*
[72] Fix | Delete
* Transfer the image tag from the post into a new text snippet.
[73] Fix | Delete
* Because the HTML API doesn't currently expose a way to extract
[74] Fix | Delete
* HTML substrings this is necessary as a workaround. Of note, this
[75] Fix | Delete
* is different than directly extracting the IMG tag:
[76] Fix | Delete
* - If there are duplicate attributes in the source there will only be one in the output.
[77] Fix | Delete
* - If there are single-quoted or unquoted attributes they will be double-quoted in the output.
[78] Fix | Delete
* - If there are named character references in the attribute values they may be replaced with their direct code points. E.g. `&hellip;` becomes `…`.
[79] Fix | Delete
* In the future there will likely be a mechanism to copy snippets of HTML from
[80] Fix | Delete
* one document into another, via the HTML Processor's `get_outer_html()` or
[81] Fix | Delete
* equivalent. When that happens it would be appropriate to replace this custom
[82] Fix | Delete
* code with that canonical code.
[83] Fix | Delete
*/
[84] Fix | Delete
if ( $processor->next_tag( 'img' ) ) {
[85] Fix | Delete
$tag_html = new WP_HTML_Tag_Processor( '<img>' );
[86] Fix | Delete
$tag_html->next_tag();
[87] Fix | Delete
foreach ( $processor->get_attribute_names_with_prefix( '' ) as $name ) {
[88] Fix | Delete
$tag_html->set_attribute( $name, $processor->get_attribute( $name ) );
[89] Fix | Delete
}
[90] Fix | Delete
$featured_image = $tag_html->get_updated_html();
[91] Fix | Delete
}
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
if ( ! $featured_image ) {
[95] Fix | Delete
return '';
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
if ( $is_link ) {
[99] Fix | Delete
$link_target = $attributes['linkTarget'];
[100] Fix | Delete
$rel = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : '';
[101] Fix | Delete
$height = ! empty( $attributes['height'] ) ? 'style="' . esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . '"' : '';
[102] Fix | Delete
$featured_image = sprintf(
[103] Fix | Delete
'<a href="%1$s" target="%2$s" %3$s %4$s>%5$s%6$s</a>',
[104] Fix | Delete
get_the_permalink( $post_ID ),
[105] Fix | Delete
esc_attr( $link_target ),
[106] Fix | Delete
$rel,
[107] Fix | Delete
$height,
[108] Fix | Delete
$featured_image,
[109] Fix | Delete
$overlay_markup
[110] Fix | Delete
);
[111] Fix | Delete
} else {
[112] Fix | Delete
$featured_image = $featured_image . $overlay_markup;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
$aspect_ratio = ! empty( $attributes['aspectRatio'] )
[116] Fix | Delete
? esc_attr( safecss_filter_attr( 'aspect-ratio:' . $attributes['aspectRatio'] ) ) . ';'
[117] Fix | Delete
: '';
[118] Fix | Delete
$width = ! empty( $attributes['width'] )
[119] Fix | Delete
? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';'
[120] Fix | Delete
: '';
[121] Fix | Delete
$height = ! empty( $attributes['height'] )
[122] Fix | Delete
? esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';'
[123] Fix | Delete
: '';
[124] Fix | Delete
if ( ! $height && ! $width && ! $aspect_ratio ) {
[125] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes();
[126] Fix | Delete
} else {
[127] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $aspect_ratio . $width . $height ) );
[128] Fix | Delete
}
[129] Fix | Delete
return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Generate markup for the HTML element that will be used for the overlay.
[134] Fix | Delete
*
[135] Fix | Delete
* @since 6.1.0
[136] Fix | Delete
*
[137] Fix | Delete
* @param array $attributes Block attributes.
[138] Fix | Delete
*
[139] Fix | Delete
* @return string HTML markup in string format.
[140] Fix | Delete
*/
[141] Fix | Delete
function get_block_core_post_featured_image_overlay_element_markup( $attributes ) {
[142] Fix | Delete
$has_dim_background = isset( $attributes['dimRatio'] ) && $attributes['dimRatio'];
[143] Fix | Delete
$has_gradient = isset( $attributes['gradient'] ) && $attributes['gradient'];
[144] Fix | Delete
$has_custom_gradient = isset( $attributes['customGradient'] ) && $attributes['customGradient'];
[145] Fix | Delete
$has_solid_overlay = isset( $attributes['overlayColor'] ) && $attributes['overlayColor'];
[146] Fix | Delete
$has_custom_overlay = isset( $attributes['customOverlayColor'] ) && $attributes['customOverlayColor'];
[147] Fix | Delete
$class_names = array( 'wp-block-post-featured-image__overlay' );
[148] Fix | Delete
$styles = array();
[149] Fix | Delete
[150] Fix | Delete
if ( ! $has_dim_background ) {
[151] Fix | Delete
return '';
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
// Apply border classes and styles.
[155] Fix | Delete
$border_attributes = get_block_core_post_featured_image_border_attributes( $attributes );
[156] Fix | Delete
[157] Fix | Delete
if ( ! empty( $border_attributes['class'] ) ) {
[158] Fix | Delete
$class_names[] = $border_attributes['class'];
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
if ( ! empty( $border_attributes['style'] ) ) {
[162] Fix | Delete
$styles[] = $border_attributes['style'];
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
// Apply overlay and gradient classes.
[166] Fix | Delete
if ( $has_dim_background ) {
[167] Fix | Delete
$class_names[] = 'has-background-dim';
[168] Fix | Delete
$class_names[] = "has-background-dim-{$attributes['dimRatio']}";
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
if ( $has_solid_overlay ) {
[172] Fix | Delete
$class_names[] = "has-{$attributes['overlayColor']}-background-color";
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
if ( $has_gradient || $has_custom_gradient ) {
[176] Fix | Delete
$class_names[] = 'has-background-gradient';
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
if ( $has_gradient ) {
[180] Fix | Delete
$class_names[] = "has-{$attributes['gradient']}-gradient-background";
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
// Apply background styles.
[184] Fix | Delete
if ( $has_custom_gradient ) {
[185] Fix | Delete
$styles[] = sprintf( 'background-image: %s;', $attributes['customGradient'] );
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
if ( $has_custom_overlay ) {
[189] Fix | Delete
$styles[] = sprintf( 'background-color: %s;', $attributes['customOverlayColor'] );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
return sprintf(
[193] Fix | Delete
'<span class="%s" style="%s" aria-hidden="true"></span>',
[194] Fix | Delete
esc_attr( implode( ' ', $class_names ) ),
[195] Fix | Delete
esc_attr( safecss_filter_attr( implode( ' ', $styles ) ) )
[196] Fix | Delete
);
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Generates class names and styles to apply the border support styles for
[201] Fix | Delete
* the Post Featured Image block.
[202] Fix | Delete
*
[203] Fix | Delete
* @since 6.1.0
[204] Fix | Delete
*
[205] Fix | Delete
* @param array $attributes The block attributes.
[206] Fix | Delete
* @return array The border-related classnames and styles for the block.
[207] Fix | Delete
*/
[208] Fix | Delete
function get_block_core_post_featured_image_border_attributes( $attributes ) {
[209] Fix | Delete
$border_styles = array();
[210] Fix | Delete
$sides = array( 'top', 'right', 'bottom', 'left' );
[211] Fix | Delete
[212] Fix | Delete
// Border radius.
[213] Fix | Delete
if ( isset( $attributes['style']['border']['radius'] ) ) {
[214] Fix | Delete
$border_styles['radius'] = $attributes['style']['border']['radius'];
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
// Border style.
[218] Fix | Delete
if ( isset( $attributes['style']['border']['style'] ) ) {
[219] Fix | Delete
$border_styles['style'] = $attributes['style']['border']['style'];
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
// Border width.
[223] Fix | Delete
if ( isset( $attributes['style']['border']['width'] ) ) {
[224] Fix | Delete
$border_styles['width'] = $attributes['style']['border']['width'];
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
// Border color.
[228] Fix | Delete
$preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null;
[229] Fix | Delete
$custom_color = $attributes['style']['border']['color'] ?? null;
[230] Fix | Delete
$border_styles['color'] = $preset_color ? $preset_color : $custom_color;
[231] Fix | Delete
[232] Fix | Delete
// Individual border styles e.g. top, left etc.
[233] Fix | Delete
foreach ( $sides as $side ) {
[234] Fix | Delete
$border = $attributes['style']['border'][ $side ] ?? null;
[235] Fix | Delete
$border_styles[ $side ] = array(
[236] Fix | Delete
'color' => isset( $border['color'] ) ? $border['color'] : null,
[237] Fix | Delete
'style' => isset( $border['style'] ) ? $border['style'] : null,
[238] Fix | Delete
'width' => isset( $border['width'] ) ? $border['width'] : null,
[239] Fix | Delete
);
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
$styles = wp_style_engine_get_styles( array( 'border' => $border_styles ) );
[243] Fix | Delete
$attributes = array();
[244] Fix | Delete
if ( ! empty( $styles['classnames'] ) ) {
[245] Fix | Delete
$attributes['class'] = $styles['classnames'];
[246] Fix | Delete
}
[247] Fix | Delete
if ( ! empty( $styles['css'] ) ) {
[248] Fix | Delete
$attributes['style'] = $styles['css'];
[249] Fix | Delete
}
[250] Fix | Delete
return $attributes;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Registers the `core/post-featured-image` block on the server.
[255] Fix | Delete
*
[256] Fix | Delete
* @since 5.8.0
[257] Fix | Delete
*/
[258] Fix | Delete
function register_block_core_post_featured_image() {
[259] Fix | Delete
register_block_type_from_metadata(
[260] Fix | Delete
__DIR__ . '/post-featured-image',
[261] Fix | Delete
array(
[262] Fix | Delete
'render_callback' => 'render_block_core_post_featured_image',
[263] Fix | Delete
)
[264] Fix | Delete
);
[265] Fix | Delete
}
[266] Fix | Delete
add_action( 'init', 'register_block_core_post_featured_image' );
[267] Fix | Delete
[268] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function