Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#32557 closed defect (bug) (fixed)

programming error found inside wp_print_scripts function (wp-includes/functions.wp-scripts.php)

Reported by: seeyouu's profile seeyouu Owned by:
Milestone: 4.3 Priority: normal
Severity: normal Version: 4.2.2
Component: Script Loader Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Dear Sir/Mdm,

I'd recently installed a slider plugin called Slider WD https://wordpress.org/plugins/slider-wd/ 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.

Change History (12)

#1 in reply to: ↑ description @seeyouu
10 years ago

Sorry, copied a wrong like for Slider WD, here's the correct one: https://wordpress.org/plugins/slider-wd/

Last edited 10 years ago by SergeyBiryukov (previous) (diff)

#2 @SergeyBiryukov
10 years ago

  • Component changed from General to Script Loader
  • Description modified (diff)

#3 @SergeyBiryukov
10 years ago

  • Description modified (diff)

#4 @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #32541.

#5 @SergeyBiryukov
10 years ago

  • Milestone set to 4.2.3
  • Resolution duplicate deleted
  • Status changed from closed to reopened

On second thought, doesn't seem like a duplicate. Reopening and moving to 4.2.3 for investigation.

Thank you for the report.

#6 @chriscct7
10 years ago

This is an issue possibly caused by #20513

Last edited 10 years ago by chriscct7 (previous) (diff)

#7 @wonderboymusic
10 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

#8 @wonderboymusic
10 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopened for 4.2.3

#9 @dd32
10 years ago

  • Keywords fixed-major added

#10 @pento
10 years ago

wp_print_scripts() and wp_print_styles() are already using wp_scripts() and wp_styles() in the 4.2 branch.

@wonderboymusic, could you confirm if anything needs to be done here for 4.2.3?

#11 @wonderboymusic
10 years ago

@pento yes, this should be included - got more than a few random reports about it

#12 @wonderboymusic
10 years ago

  • Keywords fixed-major removed
  • Milestone changed from 4.2.3 to 4.3
  • Resolution set to fixed
  • Status changed from reopened to closed

This was churn in 4.3 - the code in 4.2 is already correct.

Note: See TracTickets for help on using tickets.