[wp-hackers] add_filter before or after function?

Jamie Holly hovercrafter at earthlink.net
Thu Aug 30 02:08:49 GMT 2007


Since the function name is only getting stored in an array (or object - my
mind is shot right now), it doesn't really matter. I couldn't imagine adding
a function_exists check on add_filter, add_hook. That would be best done
when the function is actually called to prevent fatal errors. In 99% of the
situations, the add_filter and add_hook would only be adding a function
defined within that plugin, or possibly one of the core filters. 

Jamie Holly
http://www.intoxination.net
1.513.252.2919 | Skype:intoxination


>-----Original Message-----
>From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-
>bounces at lists.automattic.com] On Behalf Of Jeremy Visser
>Sent: Wednesday, August 29, 2007 9:55 PM
>To: wp-hackers at lists.automattic.com
>Subject: [wp-hackers] add_filter before or after function?
>
>DD32 wrote:
>> add_filter('query_vars', 'test_queryvars' );
>> function test_queryvars( $qvars ){
>>     $qvars[] = 'artist_slug';
>>     $qvars[] = 'artist_page';
>>     return $qvars;
>> }
>
>I notice you add the add_filter() _before_ you declare the actual
>function. Others do that too, while other add the add_filter() (or
>add_action()) _after_ the function.
>
>Which is best?
>
>I tend to put it after the function because, well, if you put it before,
>aren't you referencing a non-existant function? What if add_filter() one
>day adds a check to see if the function_exists()? If you do add_filter()
>first, then won't it break?
>
>I'm not knowledgeable enough with PHP to really know which is right.
>_______________________________________________
>wp-hackers mailing list
>wp-hackers at lists.automattic.com
>http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list