Make WordPress Core

Changeset 57367

Timestamp:
01/27/2024 01:02:35 AM (6 months ago)
Author:
westonruter
Message:

Script Loader: Clarify in docs that wp_get_inline_script_tag() and wp_print_inline_script_tag() can take non-JS data.

Props vladimiraus.
Fixes #60331.

File:
1 edited

Legend:

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

    r57341 r57367  
    28352835
    28362836/**
    2837  * Wraps inline JavaScript in `<script>` tag.
     2837 * tag.
    28382838 *
    28392839 * It is possible to inject attributes in the `<script>` tag via the  {@see 'wp_script_attributes'}  filter.
     
    28422842 * @since 5.7.0
    28432843 *
    2844  * @param string $javascript Inline JavaScript code.
     2844 * @param string $.
    28452845 * @param array  $attributes Optional. Key-value pairs representing `<script>` tag attributes.
    28462846 * @return string String containing inline JavaScript code wrapped around `<script>` tag.
    28472847 */
    2848 function wp_get_inline_script_tag( $javascript, $attributes = array() ) {
     2848function wp_get_inline_script_tag( $, $attributes = array() ) {
    28492849    $is_html5 = current_theme_supports( 'html5', 'script' ) || is_admin();
    28502850    if ( ! isset( $attributes['type'] ) && ! $is_html5 ) {
     
    29002900         * an additional `<![CDATA[` leaves the contents unchanged.
    29012901         */
    2902         $javascript = str_replace( ']]>', ']]]]><![CDATA[>', $javascript );
     2902        $ );
    29032903
    29042904        // Wrap the entire escaped script inside a CDATA section.
    2905         $javascript = sprintf( "/* <![CDATA[ */\n%s\n/* ]]> */", $javascript );
    2906     }
    2907 
    2908     $javascript = "\n" . trim( $javascript, "\n\r " ) . "\n";
     2905        $ );
     2906    }
     2907
     2908    $, "\n\r " ) . "\n";
    29092909
    29102910    /**
     
    29162916     *                           Only the attribute name is added to the `<script>` tag for
    29172917     *                           entries with a boolean value, and that are true.
    2918      * @param string $javascript Inline JavaScript code.
     2918     * @param string $.
    29192919     */
    2920     $attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $javascript );
    2921 
    2922     return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $javascript );
    2923 }
    2924 
    2925 /**
    2926  * Prints inline JavaScript wrapped in `<script>` tag.
     2920    $attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $ );
     2921
     2922    return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $ );
     2923}
     2924
     2925/**
     2926 * Prints tag.
    29272927 *
    29282928 * It is possible to inject attributes in the `<script>` tag via the  {@see 'wp_script_attributes'}  filter.
     
    29312931 * @since 5.7.0
    29322932 *
    2933  * @param string $javascript Inline JavaScript code.
     2933 * @param string $.
    29342934 * @param array  $attributes Optional. Key-value pairs representing `<script>` tag attributes.
    29352935 */
    2936 function wp_print_inline_script_tag( $javascript, $attributes = array() ) {
    2937     echo wp_get_inline_script_tag( $javascript, $attributes );
     2936function wp_print_inline_script_tag( $, $attributes = array() ) {
     2937    echo wp_get_inline_script_tag( $, $attributes );
    29382938}
    29392939
Note: See TracChangeset for help on using the changeset viewer.