WordPress.org

Make WordPress Core

Ticket #25277: wp-25277-data-after.patch

File wp-25277-data-after.patch, 7.0 KB (added by hakre, 7 years ago)
  • wp-includes/class.wp-scripts.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
    <+><?php\n/**\n * BackPress Scripts enqueue.\n *\n * These classes were refactored from the WordPress WP_Scripts and WordPress\n * script enqueue API.\n *\n * @package BackPress\n * @since r16\n */\n\n/**\n * BackPress Scripts enqueue class.\n *\n * @package BackPress\n * @uses WP_Dependencies\n * @since r16\n */\nclass WP_Scripts extends WP_Dependencies {\n\tvar $base_url; // Full URL with trailing slash\n\tvar $content_url;\n\tvar $default_version;\n\tvar $in_footer = array();\n\tvar $concat = '';\n\tvar $concat_version = '';\n\tvar $do_concat = false;\n\tvar $print_html = '';\n\tvar $print_code = '';\n\tvar $ext_handles = '';\n\tvar $ext_version = '';\n\tvar $default_dirs;\n\n\tfunction __construct() {\n\t\t$this->init();\n\t\tadd_action( 'init', array( $this, 'init' ), 0 );\n\t}\n\n\tfunction init() {\n\t\tdo_action_ref_array( 'wp_default_scripts', array(&$this) );\n\t}\n\n\t/**\n\t * Prints scripts\n\t *\n\t * Prints the scripts passed to it or the print queue. Also prints all necessary dependencies.\n\t *\n\t * @param mixed $handles (optional) Scripts to be printed. (void) prints queue, (string) prints that script, (array of strings) prints those scripts.\n\t * @param int $group (optional) If scripts were queued in groups prints this group number.\n\t * @return array Scripts that have been printed\n\t */\n\tfunction print_scripts( $handles = false, $group = false ) {\n\t\treturn $this->do_items( $handles, $group );\n\t}\n\n\t// Deprecated since 3.3, see print_extra_script()\n\tfunction print_scripts_l10n( $handle, $echo = true ) {\n\t\t_deprecated_function( __FUNCTION__, '3.3', 'print_extra_script()' );\n\t\treturn $this->print_extra_script( $handle, $echo );\n\t}\n\n\tfunction print_extra_script( $handle, $echo = true ) {\n\t\tif ( !$output = $this->get_data( $handle, 'data' ) )\n\t\t\treturn;\n\n\t\tif ( !$echo )\n\t\t\treturn $output;\n\n\t\techo \"<script type='text/javascript'>\\n\"; // CDATA and type='text/javascript' is not needed for HTML 5\n\t\techo \"/* <![CDATA[ */\\n\";\n\t\techo \"$output\\n\";\n\t\techo \"/* ]]> */\\n\";\n\t\techo \"</script>\\n\";\n\n\t\treturn true;\n\t}\n\n\tfunction do_item( $handle, $group = false ) {\n\t\tif ( !parent::do_item($handle) )\n\t\t\treturn false;\n\n\t\tif ( 0 === $group && $this->groups[$handle] > 0 ) {\n\t\t\t$this->in_footer[] = $handle;\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( false === $group && in_array($handle, $this->in_footer, true) )\n\t\t\t$this->in_footer = array_diff( $this->in_footer, (array) $handle );\n\n\t\tif ( null === $this->registered[$handle]->ver )\n\t\t\t$ver = '';\n\t\telse\n\t\t\t$ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;\n\n\t\tif ( isset($this->args[$handle]) )\n\t\t\t$ver = $ver ? $ver . '&amp;' . $this->args[$handle] : $this->args[$handle];\n\n\t\t$src = $this->registered[$handle]->src;\n\n\t\tif ( $this->do_concat ) {\n\t\t\t$srce = apply_filters( 'script_loader_src', $src, $handle );\n\t\t\tif ( $this->in_default_dir($srce) ) {\n\t\t\t\t$this->print_code .= $this->print_extra_script( $handle, false );\n\t\t\t\t$this->concat .= \"$handle,\";\n\t\t\t\t$this->concat_version .= \"$handle$ver\";\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\t$this->ext_handles .= \"$handle,\";\n\t\t\t\t$this->ext_version .= \"$handle$ver\";\n\t\t\t}\n\t\t}\n\n\t\t$this->print_extra_script( $handle );\n\t\tif ( !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {\n\t\t\t$src = $this->base_url . $src;\n\t\t}\n\n\t\tif ( !empty($ver) )\n\t\t\t$src = add_query_arg('ver', $ver, $src);\n\n\t\t$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );\n\n\t\tif ( $this->do_concat )\n\t\t\t$this->print_html .= \"<script type='text/javascript' src='$src'></script>\\n\";\n\t\telse\n\t\t\techo \"<script type='text/javascript' src='$src'></script>\\n\";\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Localizes a script\n\t *\n\t * Localizes only if the script has already been added\n\t */\n\tfunction localize( $handle, $object_name, $l10n ) {\n\t\tif ( $handle === 'jquery' )\n\t\t\t$handle = 'jquery-core';\n\n\t\tif ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present\n\t\t\t$after = $l10n['l10n_print_after'];\n\t\t\tunset($l10n['l10n_print_after']);\n\t\t}\n\n\t\tforeach ( (array) $l10n as $key => $value ) {\n\t\t\tif ( !is_scalar($value) )\n\t\t\t\tcontinue;\n\n\t\t\t$l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');\n\t\t}\n\n\t\t$script = \"var $object_name = \" . json_encode($l10n) . ';';\n\n\t\tif ( !empty($after) )\n\t\t\t$script .= \"\\n$after;\";\n\n\t\t$data = $this->get_data( $handle, 'data' );\n\n\t\tif ( !empty( $data ) )\n\t\t\t$script = \"$data\\n$script\";\n\n\t\treturn $this->add_data( $handle, 'data', $script );\n\t}\n\n\tfunction set_group( $handle, $recursion, $group = false ) {\n\n\t\tif ( $this->registered[$handle]->args === 1 )\n\t\t\t$grp = 1;\n\t\telse\n\t\t\t$grp = (int) $this->get_data( $handle, 'group' );\n\n\t\tif ( false !== $group && $grp > $group )\n\t\t\t$grp = $group;\n\n\t\treturn parent::set_group( $handle, $recursion, $grp );\n\t}\n\n\tfunction all_deps( $handles, $recursion = false, $group = false ) {\n\t\t$r = parent::all_deps( $handles, $recursion );\n\t\tif ( !$recursion )\n\t\t\t$this->to_do = apply_filters( 'print_scripts_array', $this->to_do );\n\t\treturn $r;\n\t}\n\n\tfunction do_head_items() {\n\t\t$this->do_items(false, 0);\n\t\treturn $this->done;\n\t}\n\n\tfunction do_footer_items() {\n\t\t$this->do_items(false, 1);\n\t\treturn $this->done;\n\t}\n\n\tfunction in_default_dir($src) {\n\t\tif ( ! $this->default_dirs )\n\t\t\treturn true;\n\n\t\tif ( 0 === strpos( $src, '/wp-includes/js/l10n' ) )\n\t\t\treturn false;\n\n\t\tforeach ( (array) $this->default_dirs as $test ) {\n\t\t\tif ( 0 === strpos($src, $test) )\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tfunction reset() {\n\t\t$this->do_concat = false;\n\t\t$this->print_code = '';\n\t\t$this->concat = '';\n\t\t$this->concat_version = '';\n\t\t$this->print_html = '';\n\t\t$this->ext_version = '';\n\t\t$this->ext_handles = '';\n\t}\n}\n
     
    5858                return $this->print_extra_script( $handle, $echo );
    5959        }
    6060
    61         function print_extra_script( $handle, $echo = true ) {
    62                 if ( !$output = $this->get_data( $handle, 'data' ) )
     61        function print_extra_script( $handle, $echo = true, $key = 'data' ) {
     62                if ( !$output = $this->get_data( $handle, $key ) )
    6363                        return;
    6464
    6565                if ( !$echo )
     
    123123                        $this->print_html .= "<script type='text/javascript' src='$src'></script>\n";
    124124                else
    125125                        echo "<script type='text/javascript' src='$src'></script>\n";
     126
     127                $this->print_extra_script( $handle, true, 'data-after' );
    126128
    127129                return true;
    128130        }