Question

I am getting error

Parse error: syntax error, unexpected 'add_filter' (T_STRING), expecting function (T_FUNCTION) 

when i write the below code in my plugin class file. but this is the only easiest method i saw to get the screen options working. is that code needs to be placed somewhere else?

function pippin_set_screen_option($status, $option, $value) {
    if ( 'pippin_per_page' == $option ) return $value;
}
add_filter('set-screen-option', 'pippin_set_screen_option', 10, 3);
Was it helpful?

Solution

My guess would be you have just dropped filter into a class body in between the methods. That is invalid PHP and not going to work.

First you need to call it from where code makes sense, inside another class method or from outside a class.

Second you cannot hook methods by their name alone, you need to use proper callback with a name of the class. Examples would be [ __CLASS__, 'method_name' ] (static method) or [ $this, 'method_name' ] (non-static method in class instance).

And finally if you are new to PHP then spending some time with PHP manual is highly recommended, it will save you a lot of time in dealing with WordPress.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top