Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#5015 closed defect (bug) (worksforme)

Add_Filter priority fails with some hooks

Reported by: mattyrob's profile mattyrob Owned by:
Milestone: Priority: high
Severity: normal Version: 2.3
Component: General Keywords: plugin add_filter
Focuses: Cc:


The ability to give a plugin function that is being added as a filter fails if it is called by hooking in an array:

For example:

add_filter('the_content', 'my_filter', 1); works fine

add_filter('the_content', array(&$this, 'filter'), 1); fails

Change History (4)

#1 @markjaquith
16 years ago

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

Cannot reproduce. Here was my test code:


class FooBar {
	function FooBar() {
		add_filter('myfilter', array(&$this, 'method_do'), 1);

	function method_do($input) {
		return $input . " method_do() called,";

function function_do($input) {
	return $input ." function_do() called.";

add_filter('myfilter', 'function_do', 10);
$foobar = new FooBar; // adds with priority 1

$output = apply_filters('myfilter', 'Filter started,');

echo $output;


Output was:

Filter started, method_do() called, function_do() called.

... as expected.

Try doing a die('Worked') or a mail('', 'the_content', 'Worked'); in your method.

#2 @Nazgul
16 years ago

  • Milestone 2.3 deleted

#3 @mattyrob
16 years ago

You are quite right - no bug in the add_filter code. Still something funny going on though.

Basically I've fixed my issue so I'll leave this ticket closed but..

I have a preg_replace looking for (<p>)(\n)*<!--subscribe2-->(\n)*(</p>) which worked fine with no priority set and with the priority set as 10. Lower than this it fails unless I change my regualr expression to <!--subscribe2-->.

#4 @markjaquith
16 years ago

Ah, that's because wpautop() (which turns line breaks into paragraphs) is a filter on the_content with a priority of 10. So before that (1-9), you're dealing with line breaks. After that (11 and up), you'll have paragraph tags.

Note: See TracTickets for help on using tickets.