PHP 8.2.31
Preview: post-featured-image.php Size: 7.19 KB
/home/nshryvcy/himaltourism.com/wp-includes/blocks/post-featured-image.php

<?php
/**
 * Server-side rendering of the `core/post-featured-image` block.
 *
 * @package WordPress
 */

/**
 * Renders the `core/post-featured-image` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function render_block_core_post_featured_image( $attributes, $content, $block ) {
	if ( ! isset( $block->context['postId'] ) ) {
		return '';
	}
	$post_ID = $block->context['postId'];

	// Check is needed for backward compatibility with third-party plugins
	// that might rely on the `in_the_loop` check; calling `the_post` sets it to true.
	if ( ! in_the_loop() && have_posts() ) {
		the_post();
	}

	$is_link        = isset( $attributes['isLink'] ) && $attributes['isLink'];
	$size_slug      = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail';
	$attr           = get_block_core_post_featured_image_border_attributes( $attributes );
	$overlay_markup = get_block_core_post_featured_image_overlay_element_markup( $attributes );

	if ( $is_link ) {
		if ( get_the_title( $post_ID ) ) {
			$attr['alt'] = trim( strip_tags( get_the_title( $post_ID ) ) );
		} else {
			$attr['alt'] = sprintf(
				// translators: %d is the post ID.
				__( 'Untitled post %d' ),
				$post_ID
			);
		}
	}

	if ( ! empty( $attributes['height'] ) ) {
		$extra_styles = "height:{$attributes['height']};";
		if ( ! empty( $attributes['scale'] ) ) {
			$extra_styles .= "object-fit:{$attributes['scale']};";
		}
		$attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles;
	}

	$featured_image = get_the_post_thumbnail( $post_ID, $size_slug, $attr );
	if ( ! $featured_image ) {
		return '';
	}
	if ( $is_link ) {
		$link_target    = $attributes['linkTarget'];
		$rel            = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : '';
		$height         = ! empty( $attributes['height'] ) ? 'style="' . esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . '"' : '';
		$featured_image = sprintf(
			'<a href="%1$s" target="%2$s" %3$s %4$s>%5$s%6$s</a>',
			get_the_permalink( $post_ID ),
			esc_attr( $link_target ),
			$rel,
			$height,
			$featured_image,
			$overlay_markup
		);
	} else {
		$featured_image = $featured_image . $overlay_markup;
	}

	$width  = ! empty( $attributes['width'] ) ? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';' : '';
	$height = ! empty( $attributes['height'] ) ? esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';' : '';
	if ( ! $height && ! $width ) {
		$wrapper_attributes = get_block_wrapper_attributes();
	} else {
		$wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $width . $height ) );
	}
	return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

/**
 * Generate markup for the HTML element that will be used for the overlay.
 *
 * @param array $attributes Block attributes.
 *
 * @return string HTML markup in string format.
 */
function get_block_core_post_featured_image_overlay_element_markup( $attributes ) {
	$has_dim_background  = isset( $attributes['dimRatio'] ) && $attributes['dimRatio'];
	$has_gradient        = isset( $attributes['gradient'] ) && $attributes['gradient'];
	$has_custom_gradient = isset( $attributes['customGradient'] ) && $attributes['customGradient'];
	$has_solid_overlay   = isset( $attributes['overlayColor'] ) && $attributes['overlayColor'];
	$has_custom_overlay  = isset( $attributes['customOverlayColor'] ) && $attributes['customOverlayColor'];
	$class_names         = array( 'wp-block-post-featured-image__overlay' );
	$styles              = array();

	if ( ! $has_dim_background ) {
		return '';
	}

	// Apply border classes and styles.
	$border_attributes = get_block_core_post_featured_image_border_attributes( $attributes );

	if ( ! empty( $border_attributes['class'] ) ) {
		$class_names[] = $border_attributes['class'];
	}

	if ( ! empty( $border_attributes['style'] ) ) {
		$styles[] = $border_attributes['style'];
	}

	// Apply overlay and gradient classes.
	if ( $has_dim_background ) {
		$class_names[] = 'has-background-dim';
		$class_names[] = "has-background-dim-{$attributes['dimRatio']}";
	}

	if ( $has_solid_overlay ) {
		$class_names[] = "has-{$attributes['overlayColor']}-background-color";
	}

	if ( $has_gradient || $has_custom_gradient ) {
		$class_names[] = 'has-background-gradient';
	}

	if ( $has_gradient ) {
		$class_names[] = "has-{$attributes['gradient']}-gradient-background";
	}

	// Apply background styles.
	if ( $has_custom_gradient ) {
		$styles[] = sprintf( 'background-image: %s;', $attributes['customGradient'] );
	}

	if ( $has_custom_overlay ) {
		$styles[] = sprintf( 'background-color: %s;', $attributes['customOverlayColor'] );
	}

	return sprintf(
		'<span class="%s" style="%s" aria-hidden="true"></span>',
		esc_attr( implode( ' ', $class_names ) ),
		esc_attr( safecss_filter_attr( implode( ' ', $styles ) ) )
	);
}

/**
 * Generates class names and styles to apply the border support styles for
 * the Post Featured Image block.
 *
 * @param array $attributes The block attributes.
 * @return array The border-related classnames and styles for the block.
 */
function get_block_core_post_featured_image_border_attributes( $attributes ) {
	$border_styles = array();
	$sides         = array( 'top', 'right', 'bottom', 'left' );

	// Border radius.
	if ( isset( $attributes['style']['border']['radius'] ) ) {
		$border_styles['radius'] = $attributes['style']['border']['radius'];
	}

	// Border style.
	if ( isset( $attributes['style']['border']['style'] ) ) {
		$border_styles['style'] = $attributes['style']['border']['style'];
	}

	// Border width.
	if ( isset( $attributes['style']['border']['width'] ) ) {
		$border_styles['width'] = $attributes['style']['border']['width'];
	}

	// Border color.
	$preset_color           = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null;
	$custom_color           = _wp_array_get( $attributes, array( 'style', 'border', 'color' ), null );
	$border_styles['color'] = $preset_color ? $preset_color : $custom_color;

	// Individual border styles e.g. top, left etc.
	foreach ( $sides as $side ) {
		$border                 = _wp_array_get( $attributes, array( 'style', 'border', $side ), null );
		$border_styles[ $side ] = array(
			'color' => isset( $border['color'] ) ? $border['color'] : null,
			'style' => isset( $border['style'] ) ? $border['style'] : null,
			'width' => isset( $border['width'] ) ? $border['width'] : null,
		);
	}

	$styles     = wp_style_engine_get_styles( array( 'border' => $border_styles ) );
	$attributes = array();
	if ( ! empty( $styles['classnames'] ) ) {
		$attributes['class'] = $styles['classnames'];
	}
	if ( ! empty( $styles['css'] ) ) {
		$attributes['style'] = $styles['css'];
	}
	return $attributes;
}

/**
 * Registers the `core/post-featured-image` block on the server.
 */
function register_block_core_post_featured_image() {
	register_block_type_from_metadata(
		__DIR__ . '/post-featured-image',
		array(
			'render_callback' => 'render_block_core_post_featured_image',
		)
	);
}
add_action( 'init', 'register_block_core_post_featured_image' );

Directory Contents

Dirs: 91 × Files: 68

Name Size Perms Modified Actions
archives DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
audio DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
avatar DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
block DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
button DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
buttons DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
calendar DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
code DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
column DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
columns DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
comments DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
cover DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
embed DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
file DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
freeform DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
gallery DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
group DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
heading DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
home-link DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
html DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
image DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
list DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
list-item DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
loginout DIR
- drwxr-xr-x 2026-02-14 07:57:34
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
missing DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
more DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
nextpage DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
page-list DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2023-04-04 05:42:19
Edit Download
paragraph DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
pattern DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2023-04-04 05:42:19
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
post-date DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2023-04-04 05:42:19
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
pullquote DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
query DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
quote DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
read-more DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
rss DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
search DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
separator DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
shortcode DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
site-logo DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2023-04-04 05:42:19
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
spacer DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
table DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
tag-cloud DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
verse DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
video DIR
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
- drwxr-xr-x 2022-11-10 06:10:12
Edit Download
2.89 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
5.31 KB lrw-r--r-- 2024-12-30 06:23:12
Edit Download
1.57 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
110.42 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
6.03 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.78 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.05 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.36 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
1.56 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
1.64 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
1.99 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
3.58 KB lrw-r--r-- 2024-12-30 06:23:12
Edit Download
1.80 KB lrw-r--r-- 2022-04-13 01:42:48
Edit Download
1.56 KB lrw-r--r-- 2022-04-13 01:42:48
Edit Download
1.60 KB lrw-r--r-- 2022-04-13 01:42:48
Edit Download
1.13 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.67 KB lrw-r--r-- 2022-09-21 02:13:30
Edit Download
6.50 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.43 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
115.69 KB lrw-r--r-- 2026-06-09 19:20:58
Edit Download
1.56 KB lrw-r--r-- 2022-09-21 02:13:30
Edit Download
4.85 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
1.23 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
4.74 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
1.26 KB lrw-r--r-- 2022-09-21 02:13:30
Edit Download
779 B lrw-r--r-- 2022-07-08 23:04:14
Edit Download
4.88 KB lrw-r--r-- 2022-04-13 01:42:48
Edit Download
7.43 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
3.81 KB lrw-r--r-- 2022-10-19 00:26:02
Edit Download
1.35 KB lrw-r--r-- 2021-11-09 01:59:22
Edit Download
11.51 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
10.77 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
30.54 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
13.14 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
921 B lrw-r--r-- 2021-11-09 13:47:18
Edit Download
1.41 KB lrw-r--r-- 2022-04-13 01:42:48
Edit Download
1.71 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.50 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.68 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.28 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
1.96 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.56 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
7.19 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
4.37 KB lrw-r--r-- 2024-12-30 06:23:12
Edit Download
4.06 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
3.21 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
1.81 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
1.76 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.66 KB lrw-r--r-- 2022-04-13 01:42:48
Edit Download
3.73 KB lrw-r--r-- 2021-11-09 01:59:22
Edit Download
2.12 KB lrw-r--r-- 2022-04-13 01:42:48
Edit Download
1.11 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.08 KB lrw-r--r-- 2022-09-21 02:13:30
Edit Download
304 B lrw-r--r-- 2021-05-20 01:39:28
Edit Download
1.75 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
3.74 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
543 B lrw-r--r-- 2023-04-04 05:42:19
Edit Download
3.83 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
19.94 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
697 B lrw-r--r-- 2020-06-27 00:03:48
Edit Download
5.67 KB lrw-r--r-- 2022-04-13 01:42:48
Edit Download
994 B lrw-r--r-- 2021-06-22 20:30:50
Edit Download
1.73 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
59.56 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
1.37 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
9.43 KB lrw-r--r-- 2024-12-30 06:23:12
Edit Download
1.27 KB lrw-r--r-- 2023-04-04 05:42:19
Edit Download
2.12 KB lrw-r--r-- 2022-10-19 00:26:02
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).