WordPress.org

Make WordPress Core

Ticket #51124: 51124.2.diff

File 51124.2.diff, 2.3 KB (added by byohann6, 4 months ago)
  • src/wp-includes/class.wp-scripts.php

    diff --git a/src/wp-includes/class.wp-scripts.php b/src/wp-includes/class.wp-scripts.php
    index 4d7bd9e1b2..877e7e5295 100644
    a b class WP_Scripts extends WP_Dependencies { 
    418418         * @param string $data     String containing the JavaScript to be added.
    419419         * @param string $position Optional. Whether to add the inline script
    420420         *                         before the handle or after. Default 'after'.
     421         * @param string $type     Optional. Value of the type html attribute. Default empty.
    421422         * @return bool True on success, false on failure.
    422423         */
    423         public function add_inline_script( $handle, $data, $position = 'after' ) {
     424        public function add_inline_script( $handle, $data, $position = 'after', $type = '' ) {
    424425                if ( ! $data ) {
    425426                        return false;
    426427                }
    class WP_Scripts extends WP_Dependencies { 
    429430                        $position = 'before';
    430431                }
    431432
     433                if ( ! empty ( $type ) ) {
     434                        $this->type_attr = " type='" . esc_attr( $type ) . "'";
     435                }
     436
    432437                $script   = (array) $this->get_data( $handle, $position );
    433438                $script[] = $data;
    434439
  • src/wp-includes/functions.wp-scripts.php

    diff --git a/src/wp-includes/functions.wp-scripts.php b/src/wp-includes/functions.wp-scripts.php
    index abe87a10bb..acfdd86e21 100644
    a b function wp_print_scripts( $handles = false ) { 
    125125 * @param string $data     String containing the JavaScript to be added.
    126126 * @param string $position Optional. Whether to add the inline script before the handle
    127127 *                         or after. Default 'after'.
     128 * @param string $type     Optional. Value of the type html attribute. Default empty.
    128129 * @return bool True on success, false on failure.
    129130 */
    130 function wp_add_inline_script( $handle, $data, $position = 'after' ) {
     131function wp_add_inline_script( $handle, $data, $position = 'after', $type = '' ) {
    131132        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    132133
    133134        if ( false !== stripos( $data, '</script>' ) ) {
    function wp_add_inline_script( $handle, $data, $position = 'after' ) { 
    144145                $data = trim( preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) );
    145146        }
    146147
    147         return wp_scripts()->add_inline_script( $handle, $data, $position );
     148        return wp_scripts()->add_inline_script( $handle, $data, $position, $type );
    148149}
    149150
    150151/**