WordPress.org

Make WordPress Core

Opened 13 days ago

Last modified 3 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
Focuses: Cc:

Description

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@… 13 days ago.
44341.2.diff (1.3 KB) - added by lbenicio 13 days ago.
44341.3.diff (1.3 KB) - added by ianbelanger 3 days ago.
Refreshed patch and added @deprecated documentation

Download all attachments as: .zip

Change History (7)

@sebastien@…
13 days ago

@lbenicio
13 days ago

#1 @SergeyBiryukov
13 days ago

  • Milestone changed from Awaiting Review to 4.9.7

#2 @birgire
6 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
3 days ago

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

@ianbelanger
3 days ago

Refreshed patch and added @deprecated documentation

#4 @ianbelanger
3 days ago

  • Keywords needs-refresh removed
Note: See TracTickets for help on using tickets.