From e656d4cff6e99cde8da4971d7e1cce5035693696 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 2 Oct 2025 14:02:56 +0200 Subject: [PATCH] Image block: Rename $p variable to $processor --- packages/block-library/src/image/index.php | 62 +++++++++++----------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/block-library/src/image/index.php b/packages/block-library/src/image/index.php index cdac5b719d6d39..601b7bed25263d 100644 --- a/packages/block-library/src/image/index.php +++ b/packages/block-library/src/image/index.php @@ -22,7 +22,7 @@ function render_block_core_image( $attributes, $content, $block ) { return ''; } - $p = new class( $content ) extends WP_HTML_Tag_Processor { + $processor = new class( $content ) extends WP_HTML_Tag_Processor { /** * Return input span for an empty FIGCAPTION element. * @@ -53,7 +53,7 @@ public function block_core_image_extract_empty_figcaption_element() { } }; - if ( ! $p->next_tag( 'img' ) || ! $p->get_attribute( 'src' ) ) { + if ( ! $processor->next_tag( 'img' ) || ! $processor->get_attribute( 'src' ) ) { return ''; } @@ -65,11 +65,11 @@ public function block_core_image_extract_empty_figcaption_element() { // probably overridden by block bindings. Update it to the correct value. // See https://github.com/WordPress/gutenberg/issues/62886 for why this is needed. $id = $attributes['id']; - $image_classnames = $p->get_attribute( 'class' ); + $image_classnames = $processor->get_attribute( 'class' ); $class_with_binding_value = "wp-image-$id"; if ( is_string( $image_classnames ) && ! str_contains( $image_classnames, $class_with_binding_value ) ) { $image_classnames = preg_replace( '/wp-image-(\d+)/', $class_with_binding_value, $image_classnames ); - $p->set_attribute( 'class', $image_classnames ); + $processor->set_attribute( 'class', $image_classnames ); } } @@ -83,15 +83,15 @@ public function block_core_image_extract_empty_figcaption_element() { // Else the `data-id` is used for backwards compatibility, since // third parties may be filtering its value. $data_id = $has_id_binding ? $attributes['id'] : $attributes['data-id']; - $p->set_attribute( 'data-id', $data_id ); + $processor->set_attribute( 'data-id', $data_id ); } /* * If the `caption` attribute is empty and we encounter a `
` element, * we take note of its span so we can remove it later. */ - if ( $p->next_tag( 'FIGCAPTION' ) && empty( $attributes['caption'] ) ) { - $figcaption_span = $p->block_core_image_extract_empty_figcaption_element(); + if ( $processor->next_tag( 'FIGCAPTION' ) && empty( $attributes['caption'] ) ) { + $figcaption_span = $processor->block_core_image_extract_empty_figcaption_element(); } $link_destination = isset( $attributes['linkDestination'] ) ? $attributes['linkDestination'] : 'none'; @@ -125,7 +125,7 @@ public function block_core_image_extract_empty_figcaption_element() { remove_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15 ); } - $output = $p->get_updated_html(); + $output = $processor->get_updated_html(); if ( ! empty( $figcaption_span ) ) { return substr( $output, 0, $figcaption_span->start ) . substr( $output, $figcaption_span->start + $figcaption_span->length ); } @@ -182,18 +182,18 @@ function block_core_image_render_lightbox( $block_content, $block ) { * as-is. There's nothing that this code can knowingly modify to add the * lightbox behavior. */ - $p = new WP_HTML_Tag_Processor( $block_content ); - if ( $p->next_tag( 'figure' ) ) { - $p->set_bookmark( 'figure' ); + $processor = new WP_HTML_Tag_Processor( $block_content ); + if ( $processor->next_tag( 'figure' ) ) { + $processor->set_bookmark( 'figure' ); } - if ( ! $p->next_tag( 'img' ) ) { + if ( ! $processor->next_tag( 'img' ) ) { return $block_content; } - $alt = $p->get_attribute( 'alt' ); - $img_uploaded_src = $p->get_attribute( 'src' ); - $img_class_names = $p->get_attribute( 'class' ); - $img_styles = $p->get_attribute( 'style' ); + $alt = $processor->get_attribute( 'alt' ); + $img_uploaded_src = $processor->get_attribute( 'src' ); + $img_class_names = $processor->get_attribute( 'class' ); + $img_styles = $processor->get_attribute( 'style' ); $img_width = 'none'; $img_height = 'none'; $aria_label = __( 'Enlarge' ); @@ -207,9 +207,9 @@ function block_core_image_render_lightbox( $block_content, $block ) { } // Figure. - $p->seek( 'figure' ); - $figure_class_names = $p->get_attribute( 'class' ); - $figure_styles = $p->get_attribute( 'style' ); + $processor->seek( 'figure' ); + $figure_class_names = $processor->get_attribute( 'class' ); + $figure_styles = $processor->get_attribute( 'style' ); // Create unique id and set the image metadata in the state. $unique_image_id = uniqid(); @@ -234,9 +234,9 @@ function block_core_image_render_lightbox( $block_content, $block ) { ) ); - $p->add_class( 'wp-lightbox-container' ); - $p->set_attribute( 'data-wp-interactive', 'core/image' ); - $p->set_attribute( + $processor->add_class( 'wp-lightbox-container' ); + $processor->set_attribute( 'data-wp-interactive', 'core/image' ); + $processor->set_attribute( 'data-wp-context', wp_json_encode( array( @@ -245,21 +245,21 @@ function block_core_image_render_lightbox( $block_content, $block ) { JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ) ); - $p->set_attribute( 'data-wp-key', $unique_image_id ); + $processor->set_attribute( 'data-wp-key', $unique_image_id ); // Image. - $p->next_tag( 'img' ); - $p->set_attribute( 'data-wp-init', 'callbacks.setButtonStyles' ); - $p->set_attribute( 'data-wp-on-async--load', 'callbacks.setButtonStyles' ); - $p->set_attribute( 'data-wp-on-async-window--resize', 'callbacks.setButtonStyles' ); + $processor->next_tag( 'img' ); + $processor->set_attribute( 'data-wp-init', 'callbacks.setButtonStyles' ); + $processor->set_attribute( 'data-wp-on-async--load', 'callbacks.setButtonStyles' ); + $processor->set_attribute( 'data-wp-on-async-window--resize', 'callbacks.setButtonStyles' ); // Sets an event callback on the `img` because the `figure` element can also // contain a caption, and we don't want to trigger the lightbox when the // caption is clicked. - $p->set_attribute( 'data-wp-on-async--click', 'actions.showLightbox' ); - $p->set_attribute( 'data-wp-class--hide', 'state.isContentHidden' ); - $p->set_attribute( 'data-wp-class--show', 'state.isContentVisible' ); + $processor->set_attribute( 'data-wp-on-async--click', 'actions.showLightbox' ); + $processor->set_attribute( 'data-wp-class--hide', 'state.isContentHidden' ); + $processor->set_attribute( 'data-wp-class--show', 'state.isContentVisible' ); - $body_content = $p->get_updated_html(); + $body_content = $processor->get_updated_html(); // Adds a button alongside image in the body content. $img = null;