Make WordPress Core

Ticket #42804: wp-includes.patch

File wp-includes.patch, 13.6 KB (added by sasiddiqui, 7 years ago)
  • trunk/wp-includes/class.wp-scripts.php

     
    145145                 *
    146146                 * @param WP_Scripts $this WP_Scripts instance (passed by reference).
    147147                 */
    148                 do_action_ref_array( 'wp_default_scripts', array( &$this ) );
     148                do_action_ref_array( 'wp_default_scripts', array(&$this) );
    149149        }
    150150
    151151        /**
     
    196196         * @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, true otherwise.
    197197         */
    198198        public function print_extra_script( $handle, $echo = true ) {
    199                 if ( ! $output = $this->get_data( $handle, 'data' ) ) {
     199                if ( !$output = $this->get_data( $handle, 'data' ) )
    200200                        return;
    201                 }
    202201
    203                 if ( ! $echo ) {
     202                if ( !$echo )
    204203                        return $output;
    205                 }
    206204
    207                 echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5
     205                echo "<script>\n"; // CDATA and type='text/javascript' is not needed for HTML 5
    208206                echo "/* <![CDATA[ */\n";
    209207                echo "$output\n";
    210208                echo "/* ]]> */\n";
     
    226224         * @return bool True on success, false on failure.
    227225         */
    228226        public function do_item( $handle, $group = false ) {
    229                 if ( ! parent::do_item( $handle ) ) {
     227                if ( !parent::do_item($handle) )
    230228                        return false;
    231                 }
    232229
    233                 if ( 0 === $group && $this->groups[ $handle ] > 0 ) {
     230                if ( 0 === $group && $this->groups[$handle] > 0 ) {
    234231                        $this->in_footer[] = $handle;
    235232                        return false;
    236233                }
    237234
    238                 if ( false === $group && in_array( $handle, $this->in_footer, true ) ) {
     235                if ( false === $group && in_array($handle, $this->in_footer, true) )
    239236                        $this->in_footer = array_diff( $this->in_footer, (array) $handle );
    240                 }
    241237
    242                 $obj = $this->registered[ $handle ];
     238                $obj = $this->registered[$handle];
    243239
    244240                if ( null === $obj->ver ) {
    245241                        $ver = '';
     
    247243                        $ver = $obj->ver ? $obj->ver : $this->default_version;
    248244                }
    249245
    250                 if ( isset( $this->args[ $handle ] ) ) {
    251                         $ver = $ver ? $ver . '&amp;' . $this->args[ $handle ] : $this->args[ $handle ];
    252                 }
     246                if ( isset($this->args[$handle]) )
     247                        $ver = $ver ? $ver . '&amp;' . $this->args[$handle] : $this->args[$handle];
    253248
    254                 $src         = $obj->src;
     249                $src = $obj->src;
    255250                $cond_before = $cond_after = '';
    256251                $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
    257252
    258253                if ( $conditional ) {
    259254                        $cond_before = "<!--[if {$conditional}]>\n";
    260                         $cond_after  = "<![endif]-->\n";
     255                        $cond_after = "<![endif]-->\n";
    261256                }
    262257
    263258                $before_handle = $this->print_inline_script( $handle, 'before', false );
    264                 $after_handle  = $this->print_inline_script( $handle, 'after', false );
     259                $after_handle = $this->print_inline_script( $handle, 'after', false );
    265260
    266261                if ( $before_handle ) {
    267                         $before_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $before_handle );
     262                        $before_handle = sprintf( "<script>\n%s\n</script>\n", $before_handle );
    268263                }
    269264
    270265                if ( $after_handle ) {
    271                         $after_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $after_handle );
     266                        $after_handle = sprintf( "<script>\n%s\n</script>\n", $after_handle );
    272267                }
    273268
    274269                if ( $this->do_concat ) {
     
    289284                                _print_scripts();
    290285                                $this->reset();
    291286                        } elseif ( $this->in_default_dir( $srce ) && ! $conditional ) {
    292                                 $this->print_code     .= $this->print_extra_script( $handle, false );
    293                                 $this->concat         .= "$handle,";
     287                                $this->print_code .= $this->print_extra_script( $handle, false );
     288                                $this->concat .= "$handle,";
    294289                                $this->concat_version .= "$handle$ver";
    295290                                return true;
    296291                        } else {
     
    320315                        $src = $this->base_url . $src;
    321316                }
    322317
    323                 if ( ! empty( $ver ) ) {
     318                if ( ! empty( $ver ) )
    324319                        $src = add_query_arg( 'ver', $ver, $src );
    325                 }
    326320
    327321                /** This filter is documented in wp-includes/class.wp-scripts.php */
    328322                $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
    329323
    330                 if ( ! $src ) {
     324                if ( ! $src )
    331325                        return true;
    332                 }
    333326
    334                 $tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}";
     327                $tag = "{$cond_before}{$before_handle}<script src='$src'></script>\n{$after_handle}{$cond_after}";
    335328
    336329                /**
    337330                 * Filters the HTML script tag of an enqueued script.
     
    401394                $output = trim( implode( "\n", $output ), "\n" );
    402395
    403396                if ( $echo ) {
    404                         printf( "<script type='text/javascript'>\n%s\n</script>\n", $output );
     397                        printf( "<script>\n%s\n</script>\n", $output );
    405398                }
    406399
    407400                return $output;
     
    418411         * @return bool
    419412         */
    420413        public function localize( $handle, $object_name, $l10n ) {
    421                 if ( $handle === 'jquery' ) {
     414                if ( $handle === 'jquery' )
    422415                        $handle = 'jquery-core';
    423                 }
    424416
    425                 if ( is_array( $l10n ) && isset( $l10n['l10n_print_after'] ) ) { // back compat, preserve the code in 'l10n_print_after' if present
     417                if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present
    426418                        $after = $l10n['l10n_print_after'];
    427                         unset( $l10n['l10n_print_after'] );
     419                        unset($l10n['l10n_print_after']);
    428420                }
    429421
    430422                foreach ( (array) $l10n as $key => $value ) {
    431                         if ( ! is_scalar( $value ) ) {
     423                        if ( !is_scalar($value) )
    432424                                continue;
    433                         }
    434425
    435                         $l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
     426                        $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');
    436427                }
    437428
    438429                $script = "var $object_name = " . wp_json_encode( $l10n ) . ';';
    439430
    440                 if ( ! empty( $after ) ) {
     431                if ( !empty($after) )
    441432                        $script .= "\n$after;";
    442                 }
    443433
    444434                $data = $this->get_data( $handle, 'data' );
    445435
    446                 if ( ! empty( $data ) ) {
     436                if ( !empty( $data ) )
    447437                        $script = "$data\n$script";
    448                 }
    449438
    450439                return $this->add_data( $handle, 'data', $script );
    451440        }
     
    463452         * @return bool Not already in the group or a lower group
    464453         */
    465454        public function set_group( $handle, $recursion, $group = false ) {
    466                 if ( isset( $this->registered[ $handle ]->args ) && $this->registered[ $handle ]->args === 1 ) {
     455                if ( isset( $this->registered[$handle]->args ) && $this->registered[$handle]->args === 1 )
    467456                        $grp = 1;
    468                 } else {
     457                else
    469458                        $grp = (int) $this->get_data( $handle, 'group' );
    470                 }
    471459
    472                 if ( false !== $group && $grp > $group ) {
     460                if ( false !== $group && $grp > $group )
    473461                        $grp = $group;
    474                 }
    475462
    476463                return parent::set_group( $handle, $recursion, $grp );
    477464        }
     
    478465
    479466        /**
    480467         * Determines script dependencies.
    481         *
     468    *
    482469         * @since 2.1.0
    483470         *
    484471         * @see WP_Dependencies::all_deps()
     
    513500         * @return array Handles of items that have been processed.
    514501         */
    515502        public function do_head_items() {
    516                 $this->do_items( false, 0 );
     503                $this->do_items(false, 0);
    517504                return $this->done;
    518505        }
    519506
     
    527514         * @return array Handles of items that have been processed.
    528515         */
    529516        public function do_footer_items() {
    530                 $this->do_items( false, 1 );
     517                $this->do_items(false, 1);
    531518                return $this->done;
    532519        }
    533520
     
    562549         * @since 2.8.0
    563550         */
    564551        public function reset() {
    565                 $this->do_concat      = false;
    566                 $this->print_code     = '';
    567                 $this->concat         = '';
     552                $this->do_concat = false;
     553                $this->print_code = '';
     554                $this->concat = '';
    568555                $this->concat_version = '';
    569                 $this->print_html     = '';
    570                 $this->ext_version    = '';
    571                 $this->ext_handles    = '';
     556                $this->print_html = '';
     557                $this->ext_version = '';
     558                $this->ext_handles = '';
    572559        }
    573560}
  • trunk/wp-includes/class.wp-styles.php

     
    113113                 *
    114114                 * @param WP_Styles $this WP_Styles instance (passed by reference).
    115115                 */
    116                 do_action_ref_array( 'wp_default_styles', array( &$this ) );
     116                do_action_ref_array( 'wp_default_styles', array(&$this) );
    117117        }
    118118
    119119        /**
     
    127127         * @return bool True on success, false on failure.
    128128         */
    129129        public function do_item( $handle ) {
    130                 if ( ! parent::do_item( $handle ) ) {
     130                if ( !parent::do_item($handle) )
    131131                        return false;
    132                 }
    133132
    134                 $obj = $this->registered[ $handle ];
    135                 if ( null === $obj->ver ) {
     133                $obj = $this->registered[$handle];
     134                if ( null === $obj->ver )
    136135                        $ver = '';
    137                 } else {
     136                else
    138137                        $ver = $obj->ver ? $obj->ver : $this->default_version;
    139                 }
    140138
    141                 if ( isset( $this->args[ $handle ] ) ) {
    142                         $ver = $ver ? $ver . '&amp;' . $this->args[ $handle ] : $this->args[ $handle ];
    143                 }
     139                if ( isset($this->args[$handle]) )
     140                        $ver = $ver ? $ver . '&amp;' . $this->args[$handle] : $this->args[$handle];
    144141
    145142                if ( $this->do_concat ) {
    146                         if ( $this->in_default_dir( $obj->src ) && ! isset( $obj->extra['conditional'] ) && ! isset( $obj->extra['alt'] ) ) {
    147                                 $this->concat         .= "$handle,";
     143                        if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) {
     144                                $this->concat .= "$handle,";
    148145                                $this->concat_version .= "$handle$ver";
    149146
    150147                                $this->print_code .= $this->print_inline_style( $handle, false );
     
    153150                        }
    154151                }
    155152
    156                 if ( isset( $obj->args ) ) {
     153                if ( isset($obj->args) )
    157154                        $media = esc_attr( $obj->args );
    158                 } else {
     155                else
    159156                        $media = 'all';
    160                 }
    161157
    162158                // A single item may alias a set of items, by having dependencies, but no source.
    163159                if ( ! $obj->src ) {
    164160                        if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
    165                                 $inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
     161                                $inline_style = sprintf( "<style id='%s-inline-css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
    166162                                if ( $this->do_concat ) {
    167163                                        $this->print_html .= $inline_style;
    168164                                } else {
     
    177173                        return true;
    178174                }
    179175
    180                 $rel   = isset( $obj->extra['alt'] ) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
    181                 $title = isset( $obj->extra['title'] ) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';
     176                $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
     177                $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';
    182178
    183179                /**
    184180                 * Filters the HTML link tag of an enqueued style.
     
    192188                 * @param string $href   The stylesheet's source URL.
    193189                 * @param string $media  The stylesheet's media attribute.
    194190                 */
    195                 $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media );
    196                 if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl'] ) && $obj->extra['rtl'] ) {
     191                $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media);
     192                if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) {
    197193                        if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) {
    198                                 $suffix   = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : '';
    199                                 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src, $ver, "$handle-rtl" ) );
     194                                $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : '';
     195                                $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" ));
    200196                        } else {
    201197                                $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" );
    202198                        }
     
    221217                        $this->print_html .= $conditional_pre;
    222218                        $this->print_html .= $tag;
    223219                        if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
    224                                 $this->print_html .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
     220                                $this->print_html .= sprintf( "<style id='%s-inline-css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
    225221                        }
    226222                        $this->print_html .= $conditional_post;
    227223                } else {
     
    281277                        return $output;
    282278                }
    283279
    284                 printf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $output );
     280                printf( "<style id='%s-inline-css'>\n%s\n</style>\n", esc_attr( $handle ), $output );
    285281
    286282                return true;
    287283        }
     
    324320         * @return string Style's fully-qualified URL.
    325321         */
    326322        public function _css_href( $src, $ver, $handle ) {
    327                 if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
     323                if ( !is_bool($src) && !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
    328324                        $src = $this->base_url . $src;
    329325                }
    330326
    331                 if ( ! empty( $ver ) ) {
    332                         $src = add_query_arg( 'ver', $ver, $src );
    333                 }
     327                if ( !empty($ver) )
     328                        $src = add_query_arg('ver', $ver, $src);
    334329
    335330                /**
    336331                 * Filters an enqueued style's fully-qualified URL.
     
    353348         * @return bool True if found, false if not.
    354349         */
    355350        public function in_default_dir( $src ) {
    356                 if ( ! $this->default_dirs ) {
     351                if ( ! $this->default_dirs )
    357352                        return true;
    358                 }
    359353
    360354                foreach ( (array) $this->default_dirs as $test ) {
    361                         if ( 0 === strpos( $src, $test ) ) {
     355                        if ( 0 === strpos($src, $test) )
    362356                                return true;
    363                         }
    364357                }
    365358                return false;
    366359        }
     
    377370         * @return array Handles of items that have been processed.
    378371         */
    379372        public function do_footer_items() {
    380                 $this->do_items( false, 1 );
     373                $this->do_items(false, 1);
    381374                return $this->done;
    382375        }
    383376
     
    387380         * @since 3.3.0
    388381         */
    389382        public function reset() {
    390                 $this->do_concat      = false;
    391                 $this->concat         = '';
     383                $this->do_concat = false;
     384                $this->concat = '';
    392385                $this->concat_version = '';
    393                 $this->print_html     = '';
     386                $this->print_html = '';
    394387        }
    395388}