Make WordPress Core

Opened 9 months ago

Last modified 9 months ago

#60212 new defect (bug)

apply_filters_deprecated() should tell the caller location

Reported by: cybr's profile Cybr Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: Cc:

Description

When calling this inside a plugin:

add_filter( 'contextual_help_list', function( $a ) { return $a; } );

We get:

  • Deprecated: Hook contextual_help_list is deprecated since version 3.3.0! Use get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab() instead. in /www/public/wp-includes/functions.php on line 6033

This points directly to the trigger_error() call inside function wp_trigger_error(), which isn't useful in resolving the deprecation issue.

It'd be helpful to assert the location of the deprecated filter call.

Change History (8)

#1 @swissspidy
9 months ago

Makes sense to me. I think the same should be done for similar functions. We got quite a few trac tickets and support requests in the forums because of these messages, as people think the error is coming from core rather than their plugin/theme.

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


9 months ago
#2

  • Keywords has-patch added

Introduces a 'callers' property to WP_Hook and assigns it to filters utilized by plugins. This enhancement facilitates distinguishing those called by plugins from those invoked by the core.

Trac ticket: https://core.trac.wordpress.org/ticket/60212

@benniledl commented on PR #5858:


9 months ago
#3

Sorry, new contributor here, I messed up with the commits. I will make a new PR

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


9 months ago
#4

Introduces a 'callers' property to WP_Hook and assigns it to filters utilized by plugins. This enhancement facilitates distinguishing those called by plugins from those invoked by the core.

Trac ticket: https://core.trac.wordpress.org/ticket/60212

@benniledl commented on PR #5859:


9 months ago
#5

https://i0.wp.com/github.com/WordPress/wordpress-develop/assets/109149472/bd0ff369-b65e-4cda-b044-ee25f26c2af5

@Cybr commented on PR #5859:


9 months ago
#6

The solution proposed adds a lot of processing every time a filter is added.

I recommend registering the location regardless of whether it's from a plugin --- fewer branches, more consistency.
Practically, only this line is necessary for add_filter() (I added the 'line' part, which I recommend incorporating in the deprecation message later):

$caller               = debug_backtrace()[1];
$this->callers[] = [ 
    'file' => $caller['file'], 
    'line' => $caller['line'],
];

@benniledl commented on PR #5859:


9 months ago
#7

Thanks for the feedback @sybrew I thought I want to only add it for plugins because I thought this would reduce the amount of memory that would be needed when we add the caller to every filter

@benniledl commented on PR #5859:


9 months ago
#8

Adding it to core files too would use about 0,5MB memory currently. I think we should test how the extra processing affects the performance with many plugins activated and then weigh which option is better.

Note: See TracTickets for help on using tickets.