FM

/home/u523506497/domains/mymelon.in/public_html/wp-includes/blocks UP

<?php
/**
 * Tabs Block
 *
 * @package WordPress
 */

/**
 * Extract tabs list from tab-panel innerblocks.
 *
 * @since 7.1.0
 *
 * @param array  $innerblocks Parsed inner blocks of tabs block.
 * @param string $tabs_id     Unique ID for the tabs instance, used to generate tab IDs.
 *
 * @return array List of tab IDs.
 */
function block_core_tabs_generate_tabs_list( array $innerblocks = array(), string $tabs_id = '' ): array {
	$tabs_list = array();

	// Find tab-panel block
	foreach ( $innerblocks as $inner_block ) {
		if ( 'core/tab-panels' === ( $inner_block['blockName'] ?? '' ) ) {
			$tab_index = 0;
			foreach ( $inner_block['innerBlocks'] ?? array() as $tab_block ) {
				if ( 'core/tab-panel' === ( $tab_block['blockName'] ?? '' ) ) {
					$attrs = $tab_block['attrs'] ?? array();

					$tab_id = ! empty( $attrs['anchor'] )
						? $attrs['anchor']
						: ( ! empty( $tabs_id )
							? $tabs_id . '-tab-' . $tab_index
							: 'tab-' . $tab_index );

					$tabs_list[] = esc_attr( $tab_id );
					++$tab_index;
				}
			}
			break;
		}
	}

	return $tabs_list;
}

/**
 * Filter to provide tabs list context to core/tabs and core/tab-list blocks.
 * It is more performant to do this here, once, rather than in the tabs render and tabs context filters.
 * In this way core/tabs is both a provider and a consumer of the core/tabs-list context.
 *
 * @since 7.1.0
 *
 * @param array $context      Default block context.
 * @param array $parsed_block The block being rendered.
 *
 * @return array Modified context.
 */
function block_core_tabs_provide_context( array $context, array $parsed_block ): array {
	if ( 'core/tabs' === $parsed_block['blockName'] ) {
		// Generate a unique ID for the tabs instance first, so it can be used
		// to derive stable tab IDs.
		$tabs_id                   = $parsed_block['attrs']['anchor'] ?? wp_unique_id( 'tabs_' );
		$tabs_list                 = block_core_tabs_generate_tabs_list( $parsed_block['innerBlocks'] ?? array(), $tabs_id );
		$context['core/tabs-list'] = $tabs_list;
		$context['core/tabs-id']   = $tabs_id;
	}

	return $context;
}
add_filter( 'render_block_context', 'block_core_tabs_provide_context', 10, 2 );

/**
 * Render callback for core/tabs.
 *
 * @since 7.1.0
 *
 * @param array     $attributes Block attributes.
 * @param string    $content    Block content.
 * @param \WP_Block $block      WP_Block instance.
 *
 * @return string Updated HTML.
 */
function block_core_tabs_render_block_callback( array $attributes, string $content, \WP_Block $block ): string {
	$active_tab_index = $attributes['activeTabIndex'] ?? 0;
	$tabs_list        = $block->context['core/tabs-list'] ?? array();
	$tabs_id          = $block->context['core/tabs-id'] ?? null;

	if ( empty( $tabs_id ) ) {
		// If malformed tabs, return early to avoid errors.
		return '';
	}

	$tag_processor = new WP_HTML_Tag_Processor( $content );

	$tag_processor->next_tag( array( 'class_name' => 'wp-block-tabs' ) );
	$tag_processor->set_attribute( 'data-wp-interactive', 'core/tabs' );

	$tag_processor->set_attribute(
		'data-wp-context',
		wp_json_encode(
			array(
				'tabsId'         => $tabs_id,
				'activeTabIndex' => $active_tab_index,
			)
		)
	);
	$tag_processor->set_attribute( 'data-wp-init', 'callbacks.onTabsInit' );
	$tag_processor->set_attribute( 'data-wp-on--keydown', 'actions.handleTabKeyDown' );

	$output = $tag_processor->get_updated_html();

	/**
	 * Builds a client side state for just this tabs instance, so each
	 * core/tabs block manages its own state, like context.
	 */
	wp_interactivity_state(
		'core/tabs',
		array(
			$tabs_id => $tabs_list,
		)
	);

	return $output;
}

/**
 * Registers the `core/tabs` block on the server.
 *
 * @since 7.1.0
 */
function register_block_core_tabs() {
	register_block_type_from_metadata(
		__DIR__ . '/tabs',
		array(
			'render_callback' => 'block_core_tabs_render_block_callback',
		)
	);
}
add_action( 'init', 'register_block_core_tabs' );
accordion-
accordion-heading-
accordion-item-
accordion-item.php3052V
accordion-panel-
accordion.php1147V
archives-
archives.php4385V
audio-
avatar-
avatar.php5638V
block-
block.php3122V
blocks-json.php210661V
breadcrumbs-
breadcrumbs.php19057V
button-
button.php4211V
buttons-
calendar-
calendar.php6075V
categories-
categories.php4938V
code-
column-
columns-
comment-author-name-
comment-author-name.php2136V
comment-content-
comment-content.php2459V
comment-date-
comment-date.php1865V
comment-edit-link-
comment-edit-link.php1713V
comment-reply-link-
comment-reply-link.php2075V
comment-template-
comment-template.php4494V
comments-
comments-pagination-
comments-pagination-next-
comments-pagination-next.php1924V
comments-pagination-numbers-
comments-pagination-numbers.php1632V
comments-pagination-previous-
comments-pagination-previous.php1790V
comments-pagination.php1261V
comments-title-
comments-title.php2787V
comments.php6784V
cover-
cover.php7404V
details-
details.php1498V
embed-
file-
file.php1879V
footnotes-
footnotes.php3818V
freeform-
gallery-
gallery.php22345V
group-
heading-
heading.php1301V
home-link-
home-link.php4703V
html-
icon-
icon.php4374V
image-
image.php17642V
index.php5104V
latest-comments-
latest-comments.php5622V
latest-posts-
latest-posts.php10459V
legacy-widget-
legacy-widget.php4011V
list-
list-item-
list.php1273V
loginout-
loginout.php2123V
math-
media-text-
media-text.php4298V
missing-
more-
navigation-
navigation-link-
navigation-link.php16654V
navigation-overlay-close-
navigation-overlay-close.php1765V
navigation-submenu-
navigation-submenu.php11050V
navigation.php70892V
nextpage-
page-list-
page-list-item-
page-list-item.php361V
page-list.php13863V
paragraph-
paragraph.php1139V
pattern-
pattern.php1788V
playlist-
playlist-track-
playlist-track.php2487V
playlist.php6616V
post-author-
post-author-biography-
post-author-biography.php1524V
post-author-name-
post-author-name.php1962V
post-author.php2734V
post-comments-count-
post-comments-count.php1275V
post-comments-form-
post-comments-form.php2805V
post-comments-link-
post-comments-link.php2237V
post-content-
post-content.php2668V
post-date-
post-date.php3692V
post-excerpt-
post-excerpt.php4315V
post-featured-image-
post-featured-image.php9452V
post-navigation-link-
post-navigation-link.php4807V
post-template-
post-template.php5940V
post-terms-
post-terms.php3640V
post-time-to-read-
post-time-to-read.php6411V
post-title-
post-title.php2138V
preformatted-
pullquote-
query-
query-no-results-
query-no-results.php1847V
query-pagination-
query-pagination-next-
query-pagination-next.php3676V
query-pagination-numbers-
query-pagination-numbers.php4700V
query-pagination-previous-
query-pagination-previous.php3473V
query-pagination.php1176V
query-title-
query-title.php2771V
query-total-
query-total.php2471V
query.php5690V
quote-
read-more-
read-more.php1846V
require-dynamic-blocks.php5256V
require-static-blocks.php535V
rss-
rss.php4609V
search-
search.php25600V
separator-
shortcode-
shortcode.php735V
site-logo-
site-logo.php6334V
site-tagline-
site-tagline.php1203V
site-title-
site-title.php1864V
social-link-
social-link.php67602V
social-links-
spacer-
tab-list-
tab-list.php2322V
tab-panel-
tab-panel.php1669V
tab-panels-
table-
tabs-
tabs.php3949V
tag-cloud-
tag-cloud.php1586V
template-part-
template-part.php9964V
term-count-
term-count.php1843V
term-description-
term-description.php1770V
term-name-
term-name.php2038V
term-template-
term-template.php4518V
terms-query-
text-columns-
verse-
video-
video-plain.php0V
video.php2733V
widget-group-
widget-group.php2438V
Blog - Page 5 of 508 - My Melon - Digital Marketing & Creative Agency
Skip to content Skip to footer