diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php
index b4f9ed1afcb98..ccebaaa5478e9 100644
--- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php
+++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php
@@ -1235,7 +1235,7 @@ private function data_wp_context_processor( WP_Interactivity_API_Directives_Proc
* @since 7.1.0 An object is resolved to whatever it serializes to for the client, a number is formatted by the
* JSON encoder, and a value which cannot be sent to the client is rejected rather than passed to
* WP_HTML_Tag_Processor::set_attribute().
- * @since 7.2.0 Event handler bind directives are removed.
+ * @since 7.2.0 Event handler and directive bind directives are removed.
*
* @param WP_Interactivity_API_Directives_Processor $p The directives processor instance.
* @param string $mode Whether the processing is entering or exiting the tag.
@@ -1243,6 +1243,7 @@ private function data_wp_context_processor( WP_Interactivity_API_Directives_Proc
private function data_wp_bind_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ): void {
if ( 'enter' === $mode ) {
$event_handler_prefix = 'data-wp-bind--on';
+ $directive_prefix = 'data-wp-bind--data-wp-';
$entries = $this->get_directive_entries( $p, 'bind' );
foreach ( $entries as $entry ) {
// Binding event handler attributes is not supported.
@@ -1260,6 +1261,21 @@ private function data_wp_bind_processor( WP_Interactivity_API_Directives_Process
continue;
}
+ // Binding Interactivity API directive attributes is not supported.
+ if ( str_starts_with( $entry['attribute_name'], $directive_prefix ) ) {
+ $p->remove_attribute( $entry['attribute_name'] );
+ _doing_it_wrong(
+ __METHOD__,
+ sprintf(
+ /* translators: %s: The directive, e.g. data-wp-bind--data-wp-context. */
+ __( 'Binding Interactivity API directive attributes is not supported, so "%s" was removed.' ),
+ esc_html( $entry['attribute_name'] )
+ ),
+ '7.2.0'
+ );
+ continue;
+ }
+
if ( empty( $entry['suffix'] ) || null !== $entry['unique_id'] ) {
continue;
}
diff --git a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php
index 5d6306827faf1..bb43f11dbfc96 100644
--- a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php
+++ b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php
@@ -1037,4 +1037,39 @@ public function test_wp_bind_removes_event_handler_binding_but_processes_valid_b
$new_html = $this->interactivity->process_directives( $html );
$this->assertEqualHTML( '', $new_html );
}
+
+ /**
+ * Data provider for directive bindings.
+ *
+ * @return array Data provider.
+ */
+ public static function data_directive_bindings(): array {
+ return array(
+ 'interactive directive' => array( 'attribute' => 'data-wp-bind--data-wp-interactive' ),
+ 'context directive' => array( 'attribute' => 'data-wp-bind--data-wp-context' ),
+ 'text directive' => array( 'attribute' => 'data-wp-bind--data-wp-text' ),
+ 'bind directive' => array( 'attribute' => 'data-wp-bind--data-wp-bind--id' ),
+ 'context directive with an empty unique ID' => array( 'attribute' => 'data-wp-bind--data-wp-context---' ),
+ 'context directive with a unique ID' => array( 'attribute' => 'data-wp-bind--data-wp-context---unique-id' ),
+ );
+ }
+
+ /**
+ * Tests that `data-wp-bind` removes bindings to directive attributes.
+ *
+ * @ticket 66452
+ *
+ * @covers ::process_directives
+ *
+ * @dataProvider data_directive_bindings
+ *
+ * @expectedIncorrectUsage WP_Interactivity_API::data_wp_bind_processor
+ *
+ * @param non-empty-string $attribute Directive attribute name.
+ */
+ public function test_wp_bind_removes_directive_bindings( string $attribute ): void {
+ $html = "";
+ $new_html = $this->interactivity->process_directives( $html );
+ $this->assertEqualHTML( '', $new_html );
+ }
}