Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#16642 closed defect (bug) (invalid)

Function "remove_filter" does not seem to work right

Reported by: 1manfactory's profile 1manfactory Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Formatting Keywords:
Focuses: Cc:

Description

On my plugin to manipulate permalinks I used this to remove the default filter

remove_filter('sanitize_title', 'sanitize_title');

before I add my own filter

It used to work until Wordpress 3.1

Now I can see that the filter which should have been removed is still active.

I checked it by manipulating the default filter sanitize_title (\wp-includes\formatting.php) in a way that it always gave back a special value. And the value always showed up though it should not when using remove_filter

Attachments (1)

test-remove-filter.php (415 bytes) - added by scribu 12 years ago.

Download all attachments as: .zip

Change History (13)

#1 @sivel
12 years ago

  • Keywords reporter-feedback added

I am slightly confused as to why there would be filtering on sanitize_title using sanitize_title. I cannot see any place where this is used in the WP code base.

Perhaps you are really wanting to use:

remove_filter( 'sanitize_title', 'sanitize_title_with_dashes' );

#2 @1manfactory
12 years ago

  • Keywords reporter-feedback removed

Oh, sorry, you are right. That was a remainder of my futile debugging attempts
Of course I meant

remove_filter('sanitize_title', 'sanitize_title_with_dashes');

But the error remains.

remove_filter gives back true, but I am quite sure that the filter has not been deactivated.

Maybe you would like to check inside my simple plugin to manipulate German umlauts: http://wordpress.org/extend/plugins/wp-cleanumlauts2/

It used to work for WP<3.1

#3 @scribu
12 years ago

Related: #9591

#4 @toscho
12 years ago

  • Cc info@… added

Confirmed. My plugin Germanix URL stopped working too. remove_filter() seems to be broken.

Even a later priority doesn’t work:

remove_filter( 'sanitize_title', 'sanitize_title_with_dashes', 11 );

#5 @scribu
12 years ago

This is not a problem with remove_filter() itself, as demonstrated by test-remove-filter.php.

More likely, it's caused by one of my commits on #9591.

#6 @sivel
12 years ago

I haven't tried any of the plugins referenced to have issues but did create a test plugin that successfully removes that filter and adds a new filter without issue.

When I get a chance I will try to test. however, looking at what those 2 plugins do, leads me to believe it was likely the addition of the following code in sanitize_title and has nothing to do with the filter referenced:

    if ( 'save' == $context )
        $title = remove_accents($title);

A work around may be to do something like:

remove_filter( 'sanitize_title', 'sanitize_title_with_dashes');
add_filter( 'sanitize_title', 'restore_raw_title', 9, 3 );
function restore_raw_title( $title, $raw_title, $context ) {
    if ( $context == 'save' )
        return $raw_title;
    else
        return $title;
}

And then go about adding your own filter at priority 10 or higher to filter sanitize_title the way you want.

#7 @toscho
12 years ago

In wp-includes/formatting.php function sanitize_title() there are two lines which cause this bug:

	if ( 'save' == $context )
		$title = remove_accents($title);

Later filters don’t get the original string and cannot perform a correct transliteration like in earlier versions of WP.
I have fixed my plugin now by accessing the variable $raw_title.

We really need a working transliteration in the core … *sigh*

#8 @sivel
12 years ago

Yeah, guess your filter, could just directly access $raw_title instead of restoring it like I mentioned...over thinking things here.

#9 @toscho
12 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

Setting it to wontfix because plugin authors can restore the old functionality.
See this code for an example.

#10 @scribu
12 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

#11 @scribu
12 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

Indeed, $raw_title should have been used from the beginning.

Even in WP 3.0, strip_tags() was applied before calling the filter.

#12 @hakre
12 years ago

Duplicate: #16905

Note: See TracTickets for help on using tickets.