Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#31126 closed enhancement (fixed)

wp_register_script|style() should return boolean success/failure value

Reported by: katzwebdesign's profile katzwebdesign Owned by: johnbillion's profile johnbillion
Milestone: 4.3 Priority: normal
Severity: minor Version: 4.2
Component: Script Loader Keywords: has-patch commit
Focuses: Cc:

Description

wp_register_script() currently returns no value. When registering a script fails, it fails silently.

The wp_register_script() function is essentially a wrapper for $wp_scripts->add(), so wp_register_script() should return the same boolean "True on success, false on failure." value.

Attachments (6)

add-return-to-wp_register_script.diff (1.0 KB) - added by katzwebdesign 10 years ago.
Have the wp_register_script() function return boolean passed by $wp_scripts->add()
add-return-to-wp_register_script-and-wp_register_style.diff (1.9 KB) - added by katzwebdesign 10 years ago.
Have the wp_register_script() and wp_register_style() functions return boolean on success/fail
31126.diff (1.4 KB) - added by pareshradadiya 10 years ago.
31126.2.diff (4.0 KB) - added by DrewAPicture 10 years ago.
Tests + changes combined + docs
31126.3.diff (4.0 KB) - added by DrewAPicture 10 years ago.
Updated changelogs
31126.4.diff (4.0 KB) - added by DrewAPicture 10 years ago.
$registered

Download all attachments as: .zip

Change History (19)

@katzwebdesign
10 years ago

Have the wp_register_script() function return boolean passed by $wp_scripts->add()

#1 @katzwebdesign
10 years ago

  • Keywords has-patch dev-feedback needs-unit-tests needs-codex added
  • Severity changed from normal to minor
  • Version set to trunk

#2 follow-up: @SergeyBiryukov
10 years ago

This would apply to wp_register_style() as well.

@katzwebdesign
10 years ago

Have the wp_register_script() and wp_register_style() functions return boolean on success/fail

#3 in reply to: ↑ 2 @katzwebdesign
10 years ago

Replying to SergeyBiryukov:

This would apply to wp_register_style() as well.

Done!

#4 @pareshradadiya
10 years ago

  • Keywords needs-unit-tests removed

PHPUnit test case added

@DrewAPicture
10 years ago

Tests + changes combined + docs

#5 @DrewAPicture
10 years ago

  • Keywords 4.3-early added; needs-codex removed
  • Milestone changed from Awaiting Review to Future Release

31126.2.diff combines the changes with the tests, adds changelog entries for the added return values. Let's pick this up in 4.3-early.

#6 @obenland
10 years ago

  • Owner set to DrewAPicture
  • Status changed from new to assigned

#7 @obenland
10 years ago

  • Keywords 4.3-early removed
  • Milestone changed from Future Release to 4.3

@DrewAPicture
10 years ago

Updated changelogs

#8 @DrewAPicture
10 years ago

  • Keywords commit added; dev-feedback removed

31126.3.diff updates the changelog entries to 4.3.0, and simplifies/self-documents the return values in both contexts. Looks good to me.

#9 @DrewAPicture
10 years ago

  • Summary changed from wp_register_script() should return boolean success/failure value to wp_register_script|style() should return boolean success/failure value

#10 follow-up: @obenland
10 years ago

Would $registered or $is_registered be more descriptive than $add_result? That could also mean adding up results or something.

@DrewAPicture
10 years ago

$registered

#11 in reply to: ↑ 10 @DrewAPicture
10 years ago

Replying to obenland:

Would $registered or $is_registered be more descriptive than $add_result? That could also mean adding up results or something.

Changed to $registered in 31126.4.diff.

#12 @DrewAPicture
10 years ago

  • Owner changed from DrewAPicture to johnbillion

Reassigning for code committer review.

#13 @johnbillion
10 years ago

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

In 32483:

Add a return value to wp_register_script() and wp_register_style() which matches the return value of WP_Dependencies::add().

Props katzwebdesign, pareshradadiya, DrewAPicture.

Fixes #31126

Note: See TracTickets for help on using tickets.