diff --git a/phpunit/directives/attributes/wp-show.php b/phpunit/directives/attributes/wp-show.php
index 4f9ed298..f9314c19 100644
--- a/phpunit/directives/attributes/wp-show.php
+++ b/phpunit/directives/attributes/wp-show.php
@@ -46,7 +46,7 @@ public function test_directive_wraps_content_in_template_if_when_is_false() {
$tags->next_tag( array( 'tag_closers' => 'visit' ) );
process_wp_show( $tags, $context );
- $updated_markup = 'I should not be shown!
';
+ $updated_markup = 'I should not be shown!
';
$this->assertSame( $updated_markup, $tags->get_updated_html() );
$this->assertSame( $context_before->get_context(), $context->get_context(), 'data-wp-show directive changed context' );
@@ -64,7 +64,7 @@ public function test_directive_wraps_void_tag_in_template_if_when_is_false() {
$tags->next_tag( array( 'tag_closers' => 'visit' ) );
process_wp_show( $tags, $context );
- $updated_markup = '';
+ $updated_markup = '';
$this->assertSame( $updated_markup, $tags->get_updated_html() );
$this->assertSame( $context_before->get_context(), $context->get_context(), 'data-wp-show directive changed context' );
diff --git a/src/directives/attributes/wp-show.php b/src/directives/attributes/wp-show.php
index a5626c94..141c26ee 100644
--- a/src/directives/attributes/wp-show.php
+++ b/src/directives/attributes/wp-show.php
@@ -14,6 +14,10 @@ function process_wp_show( $tags, $context ) {
$show = evaluate( $value, $context->get_context() );
if ( ! $show ) {
- $tags->wrap_in_tag( 'TEMPLATE' );
+ $wrapper_bookmark = $tags->wrap_in_tag( 'TEMPLATE' );
+ $tags->seek( $wrapper_bookmark );
+ $tags->set_attribute( 'data-wp-show', $value );
+ $tags->next_tag();
+ $tags->remove_attribute( 'data-wp-show' );
}
}
diff --git a/src/directives/class-wp-directive-processor.php b/src/directives/class-wp-directive-processor.php
index 048ccef2..58977e84 100644
--- a/src/directives/class-wp-directive-processor.php
+++ b/src/directives/class-wp-directive-processor.php
@@ -134,7 +134,8 @@ public function get_balanced_tag_bookmarks() {
* calling the function.
*
* @param string $tag An HTML tag, specified in uppercase (e.g. "DIV").
- * @return bool Whether the operation was successful.
+ * @return string|false The name of a bookmark pointing to the wrapping tag opener
+ * if successful; false otherwise.
*
* @todo Allow passing in tags with attributes, e.g. ?
*/
@@ -179,7 +180,16 @@ public function wrap_in_tag( $tag ) {
$this->seek( $start_name ); // Return to original position.
$this->release_bookmark( $start_name );
- return true;
+ $i = 0;
+ while ( array_key_exists( $tag . $i, $this->bookmarks ) ) {
+ ++$i;
+ }
+ $bookmark_name = $tag . $i;
+ $this->bookmarks[ $bookmark_name ] = new WP_HTML_Span(
+ $start,
+ $start + strlen( $tag ) + 2
+ );
+ return $bookmark_name;
}
/**