Make WordPress Core


Ignore:
Timestamp:
11/03/2026 02:36:41 PM (9 days ago)
Author:
jonsurrell
Message:

Interactivity API: Remove event handler bind directives.

Server processing now removes data-wp-bind--on* directives from output.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/15396

Follow-up to r61885.

Props jonsurrell, ntsekouras, luisherranz.
See #66452.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php

    r64878 r65228  
    11541154         *              JSON encoder, and a value which cannot be sent to the client is rejected rather than passed to
    11551155         *              WP_HTML_Tag_Processor::set_attribute().
     1156         * @since 7.2.0 Event handler bind directives are removed.
    11561157         *
    11571158         * @param WP_Interactivity_API_Directives_Processor $p    The directives processor instance.
    … …  
    11601161        private function data_wp_bind_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ): void {
    11611162                if ( 'enter' === $mode ) {
    1162                         $entries = $this->get_directive_entries( $p, 'bind' );
     1163                        $event_handler_prefix = 'data-wp-bind--on';
     1164                        $entries              = $this->get_directive_entries( $p, 'bind' );
    11631165                        foreach ( $entries as $entry ) {
     1166                                // Binding event handler attributes is not supported.
     1167                                if ( str_starts_with( $entry['attribute_name'], $event_handler_prefix ) ) {
     1168                                        $p->remove_attribute( $entry['attribute_name'] );
     1169                                        _doing_it_wrong(
     1170                                                __METHOD__,
     1171                                                sprintf(
     1172                                                        /* translators: %s: The directive, e.g. data-wp-on--click. */
     1173                                                        __( 'Binding event handler attributes is not supported. Please use "%s" instead.' ),
     1174                                                        esc_attr( 'data-wp-on--' . substr( $entry['attribute_name'], strlen( $event_handler_prefix ) ) )
     1175                                                ),
     1176                                                '6.9.2'
     1177                                        );
     1178                                        continue;
     1179                                }
     1180
    11641181                                if ( empty( $entry['suffix'] ) || null !== $entry['unique_id'] ) {
    11651182                                        continue;
    … …  
    11801197                                                ),
    11811198                                                '7.1.4'
    1182                                         );
    1183                                         continue;
    1184                                 }
    1185 
    1186                                 // Skip if the suffix is an event handler.
    1187                                 if ( str_starts_with( $entry['suffix'], 'on' ) ) {
    1188                                         _doing_it_wrong(
    1189                                                 __METHOD__,
    1190                                                 sprintf(
    1191                                                         /* translators: %s: The directive, e.g. data-wp-on--click. */
    1192                                                         __( 'Binding event handler attributes is not supported. Please use "%s" instead.' ),
    1193                                                         esc_attr( 'data-wp-on--' . substr( $entry['suffix'], 2 ) )
    1194                                                 ),
    1195                                                 '6.9.2'
    11961199                                        );
    11971200                                        continue;
Note: See TracChangeset for help on using the changeset viewer.