Make WordPress Core

Opened 2 weeks ago

Last modified 2 days ago

#44341 new defect (bug)

Replace _deprecated_function( 'add_filter' ) with apply_filters_deprecated()

Reported by: birgire Owned by:
Milestone: 4.9.7 Priority: normal
Severity: normal Version: 4.3
Component: Editor Keywords: good-first-bug has-patch needs-refresh
Focuses: docs Cc:


Since 4.6 we have the function apply_filters_deprecated() for deprecated filters:

When a filter hook is deprecated, the apply_filters() call is replaced with >apply_filters_deprecated(), which triggers a deprecation notice and then fires the >original filter hook.

In wp-includes/class-wp-editor.php we have:

// Back-compat for the `htmledit_pre` and `richedit_pre` filters
if ( 'html' === $default_editor && has_filter( 'htmledit_pre' ) ) {
	// TODO: needs _deprecated_filter(), use _deprecated_function() as substitute for now
	_deprecated_function( 'add_filter( htmledit_pre )', '4.3.0', 'add_filter( format_for_editor )' );
	$content = apply_filters( 'htmledit_pre', $content );
} elseif ( 'tinymce' === $default_editor && has_filter( 'richedit_pre' ) ) {
	_deprecated_function( 'add_filter( richedit_pre )', '4.3.0', 'add_filter( format_for_editor )' );
	$content = apply_filters( 'richedit_pre', $content );

I think we can replace it with:

// Back-compat for the `htmledit_pre` and `richedit_pre` filters
if ( 'html' === $default_editor && has_filter( 'htmledit_pre' ) ) {
	$content = apply_filters_deprecated( 'htmledit_pre', array( $content ), '4.3.0', 'format_for_editor' );
} elseif ( 'tinymce' === $default_editor && has_filter( 'richedit_pre' ) ) {
	$content = apply_filters_deprecated( 'richedit_pre', array( $content ), '4.3.0', 'format_for_editor' );

I also wonder if the missing inline documentation should be added, for those deprecated filters.

Attachments (3)

44341.diff (79.2 KB) - added by sebastien@… 2 weeks ago.
44341.2.diff (1.3 KB) - added by lbenicio 2 weeks ago.
44341.3.diff (1.3 KB) - added by ianbelanger 5 days ago.
Refreshed patch and added @deprecated documentation

Download all attachments as: .zip

Change History (8)

2 weeks ago

2 weeks ago

#1 @SergeyBiryukov
2 weeks ago

  • Milestone changed from Awaiting Review to 4.9.7

#2 @birgire
8 days ago

Thanks for the patch @lbenicio and @sebastien@…

The patch in 44341.diff seems to be unrelated.

The patch in 44341.2.diff duplicates a comment line.

Shouldn't we also add inline documentation for the filters, including the @deprecate tag with the version when it was deprecated?

#3 @desrosj
5 days ago

  • Keywords has-patch needs-refresh added; needs-patch removed

5 days ago

Refreshed patch and added @deprecated documentation

#4 @ianbelanger
5 days ago

  • Keywords needs-refresh removed

#5 @desrosj
2 days ago

  • Focuses docs added
  • Keywords needs-refresh added

@ianbelanger 44341.3.diff looks good. A few minor changes:

  • Instead of putting the inline documentation before the if() statement, can there be a docblock above each apply_filter_deprecated() call? Putting it before each filter call would make it harder to miss.
  • There should be a @param string $content line in the docblocks describing the parameter.
  • The empy * line after @deprecated should not be there.
Note: See TracTickets for help on using tickets.