Make WordPress Core


Ignore:
Timestamp:
01/23/2026 05:02:27 PM (4 months ago)
Author:
jonsurrell
Message:

Script Loader: Deprecate wp_sanitize_script_attributes().

The function is no longer used by WordPress and better alternatives are available: wp_get_script_tag() and wp_get_inline_script_tag().

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

Follow-up to [61415], [61485].

Props jonsurrell, westonruter.
Fixes #64511. See #64442.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/deprecated.php

    r61487 r61518  
    64806480    <?php
    64816481}
     6482
     6483/**
     6484 * Sanitizes an attributes array into an attributes string to be placed inside a `<script>` tag.
     6485 *
     6486 * This function is deprecated, use {@see wp_get_script_tag()} or {@see wp_get_inline_script_tag()} instead.
     6487 *
     6488 * @since 5.7.0
     6489 * @deprecated 7.0.0 Use wp_get_script_tag() or wp_get_inline_script_tag().
     6490 * @see wp_get_script_tag()
     6491 * @see wp_get_inline_script_tag()
     6492 *
     6493 * @param array<string, string|bool> $attributes Key-value pairs representing `<script>` tag attributes.
     6494 * @return string String made of sanitized `<script>` tag attributes.
     6495 */
     6496function wp_sanitize_script_attributes( $attributes ) {
     6497    _deprecated_function( __FUNCTION__, '7.0.0', 'wp_get_script_tag() or wp_get_inline_script_tag()' );
     6498
     6499    $attributes_string = '';
     6500    foreach ( $attributes as $attribute_name => $attribute_value ) {
     6501        if ( is_bool( $attribute_value ) ) {
     6502            if ( $attribute_value ) {
     6503                $attributes_string .= ' ' . esc_attr( $attribute_name );
     6504            }
     6505        } else {
     6506            $attributes_string .= sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
     6507        }
     6508    }
     6509    return $attributes_string;
     6510}
     6511
Note: See TracChangeset for help on using the changeset viewer.