Make WordPress Core

Opened 13 months ago

Closed 13 months ago

Last modified 13 months ago

#58665 closed defect (bug) (fixed)

Update the `wp_print_scripts` filter in default-filters.php to be an action

Reported by: davidbaumwald's profile davidbaumwald Owned by: davidbaumwald's profile davidbaumwald
Milestone: 6.3 Priority: normal
Severity: normal Version: 4.2
Component: General Keywords: good-first-bug has-patch
Focuses: Cc:


Original reporter is @cybr.

In src/wp-includes/default-filters.php, wp_print_scripts is added as a filter, but is actually an action. Underneath they are the same, but this should be updated to use the correct alias with add_action.

This would be a great first bug for a newer contributor, so marking as such.

Change History (10)

#1 @Cybr
13 months ago

Action 'customize_controls_print_styles' has the same issue, only a few lines down.

#2 @abhi3315
13 months ago

I am a first-time contributor to the WordPress core. I believe this issue will be good to get started.

I am working to create a patch for this issue.

This ticket was mentioned in PR #4757 on WordPress/wordpress-develop by @abhi3315.

13 months ago

  • Keywords has-patch added; needs-patch removed

Trac ticket: 58665

  • Added add_action for the below action hooks:
    • customize_controls_print_styles
    • wp_print_scripts

#4 @davidbaumwald
13 months ago

  • Owner set to davidbaumwald
  • Status changed from new to reviewing

#5 @davidbaumwald
13 months ago

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

In 56140:

Default Filters: Correct hook type for wp_print_scripts and customize_controls_print_styles.

Props Cybr, bhi3315.
Fixes #58665.

@davidbaumwald commented on PR #4757:

13 months ago

Thanks for the PR @abhi3315! I was able to merge this into Core in, so this will be a part of the 6.3 release!

#7 @stevenlinx
13 months ago

  • Keywords add-to-field-guide added

#8 @davidbaumwald
13 months ago

@stevenlinx I don't think this should be added to the field guide. That's usually reserved for larger changes that Devs should be aware of.

In this case, this isn't adding or changing the root hooks. The do_actions have been in place forever. This change simply corrected the hook type in a place where Core was hooking in itself.

#9 @stevenlinx
13 months ago

I'm indifferent to whether the field guide includes it.

My rational to add the label was that it's been modified.

Per "Publishing the Field Guide" | Core Handbook:
"Ideally all new and modified hooks are noted in a bulleted list (e.g., 4.8)."

If you look at v4.8 guide

There is a "Modified Filter Hooks" section at the bottom.

In my current draft guide, I noted it as "The filter hooks wp_print_scripts and customize_controls_print_styles have been fixed to become action hooks."
(my understanding: a filter expects a return value, action does not; so a third party developer may need to change their code? if their code no longer need to expect a return value)

In this case, the original code was wrong to begin with, so it's a good thing to let the developers know the code have been fixed?

As the owner of the ticket, if you feel it's insignificant, then feel free to remove the label.

#10 @davidbaumwald
13 months ago

  • Keywords add-to-field-guide removed

@stevenlinx Thanks for the context. However, the changes there are to the apply_filters and do_action sides of each hook. In this ticket, these were not changed. This changed two instances of add_filter to add_action where Core was hooking into itself. As such, there's nothing to note for developers as the name/signature of the hooks themselves remain unchanged.

Note: See TracTickets for help on using tickets.