[wp-trac] [WordPress Trac] #32557: programming error found inside wp_print_scripts function (wp-includes/functions.wp-scripts.php)

WordPress Trac noreply at wordpress.org
Wed Jun 3 01:31:02 UTC 2015


#32557: programming error found inside wp_print_scripts function (wp-
includes/functions.wp-scripts.php)
---------------------------+------------------------------
 Reporter:  seeyouu        |       Owner:
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Script Loader  |     Version:  4.2.2
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+------------------------------
Changes (by SergeyBiryukov):

 * component:  General => Script Loader


Old description:

> Dear Sir/Mdm,
>
> I'd recently installed a slider plugin called Slider WD
> [http://52.74.232.138/WordPress/wp-admin/plugin-install.php?tab=plugin-
> information&plugin=slider-wd&TB_iframe=true&width=600&height=550] into my
> wordpress version 4.2.2, and i found a problem which i can't add image
> into my slider.
>
> Once clicked "Add Image" button, it will show that Fatal error occured at
> wp-includes/functions.wp-scripts.php line 85, do_items is referred to a
> non-object.
>
> I did further study about the script and i found that probably a
> programming error under wp_print_scripts function which caused this
> issue.
>
> Below are the comparison of the same function under different version
> version 4.2.2:
> function wp_print_scripts( $handles = false ) {
>         /**
>          * Fires before scripts in the $handles queue are printed.
>          *
>          * @since 2.1.0
>          */
>         do_action( 'wp_print_scripts' );
>         if ( '' === $handles ) { // for wp_head
>                 $handles = false;
>         }
>
>         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
>
>         global $wp_scripts;
>         if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
>                 if ( ! $handles ) {
>                         return array(); // No need to instantiate if
> nothing is there.
>                 }
>         }
>
>         return wp_scripts()->do_items( $handles );
> }
>
> Version 4.0.2:
> function wp_print_scripts( $handles = false ) {
>         /**
>          * Fires before scripts in the $handles queue are printed.
>          *
>          * @since 2.1.0
>          */
>         do_action( 'wp_print_scripts' );
>         if ( '' === $handles ) // for wp_head
>                 $handles = false;
>
>         global $wp_scripts;
>         if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
>                 if ( ! did_action( 'init' ) )
>                         _doing_it_wrong( __FUNCTION__, sprintf( __(
> 'Scripts and styles should not be registered or enqueued until the %1$s,
> %2$s, or %3$s hooks.' ),
>                                 '<code>wp_enqueue_scripts</code>',
> '<code>admin_enqueue_scripts</code>',
> '<code>login_enqueue_scripts</code>' ), '3.3' );
>
>                 if ( !$handles )
>                         return array(); // No need to instantiate if
> nothing is there.
>                 else
>                         $wp_scripts = new WP_Scripts();
>         }
>
>         return $wp_scripts->do_items( $handles );
> }
>
> under the condition if ( !$handles ), there's an else statement
> $wp_scripts = new WP_Scripts(); in version 4.0.2, however, version 4.2.2,
> this statement is missing.

New description:

 Dear Sir/Mdm,

 I'd recently installed a slider plugin called Slider WD
 [http://52.74.232.138/WordPress/wp-admin/plugin-install.php?tab=plugin-
 information&plugin=slider-wd&TB_iframe=true&width=600&height=550] into my
 wordpress version 4.2.2, and i found a problem which i can't add image
 into my slider.

 Once clicked "Add Image" button, it will show that Fatal error occured at
 wp-includes/functions.wp-scripts.php line 85, do_items is referred to a
 non-object.

 I did further study about the script and i found that probably a
 programming error under wp_print_scripts function which caused this issue.

 Below are the comparison of the same function under different version
 version 4.2.2:
 {{{
 function wp_print_scripts( $handles = false ) {
         /**
          * Fires before scripts in the $handles queue are printed.
          *
          * @since 2.1.0
          */
         do_action( 'wp_print_scripts' );
         if ( '' === $handles ) { // for wp_head
                 $handles = false;
         }

         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );

         global $wp_scripts;
         if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
                 if ( ! $handles ) {
                         return array(); // No need to instantiate if
 nothing is there.
                 }
         }

         return wp_scripts()->do_items( $handles );
 }
 }}}
 Version 4.0.2:
 {{{
 function wp_print_scripts( $handles = false ) {
         /**
          * Fires before scripts in the $handles queue are printed.
          *
          * @since 2.1.0
          */
         do_action( 'wp_print_scripts' );
         if ( '' === $handles ) // for wp_head
                 $handles = false;

         global $wp_scripts;
         if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
                 if ( ! did_action( 'init' ) )
                         _doing_it_wrong( __FUNCTION__, sprintf( __(
 'Scripts and styles should not be registered or enqueued until the %1$s,
 %2$s, or %3$s hooks.' ),
                                 '<code>wp_enqueue_scripts</code>',
 '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>'
 ), '3.3' );

                 if ( !$handles )
                         return array(); // No need to instantiate if
 nothing is there.
                 else
                         $wp_scripts = new WP_Scripts();
         }

         return $wp_scripts->do_items( $handles );
 }
 }}}
 under the condition if ( !$handles ), there's an else statement
 $wp_scripts = new WP_Scripts(); in version 4.0.2, however, version 4.2.2,
 this statement is missing.

--

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32557#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list