[wp-hackers] Call to add_action() outside function in theme.php

DD32 wordpress at dd32.id.au
Fri Jan 9 04:58:18 GMT 2009


It depends on the developer..
As a dev, I dont look at the headers of files, i just zip straight
through to the function in question, In some files having a few
thousand lines, skipping back to the start, or end of the file for the
actions/filters would simply be anoying..

I personally prefer the calls to be at the start of the function, ie:

add_action('boo', 'bar');
function bar(){
return 'baz';
}
But that can have problems with PHPDoc i think.. And so it then ends
up before pages worth of phpdoc:
add_action('boo', 'bar');
/**
*
*
....
*
*/
function bar(){
return 'baz';
}


Others prefer them at the bottom, (And some claim they need to be at
the bottom possibly due to the way that other languages dont know of
the function until after its defined, not a problem with PHP).

Theres also default-filters.php which makes sense for some items.. But
doesnt really suit items such as preview_theme(); all in all.. I think
its going to continue to be up to whoever creates the filter for where
the filters are defined.. Some files define the actions along with the
function, some define them in blocks at the end of the file, some
define in default-filters.php, some define in other functions
elsewhere..

2009/1/9 Charles K. Clarkson <cclarkson at htcomp.net>:
> Hello,
>
>   I was checking the preview_theme() function in wp-includes/theme.php to
> add a reference page in the codex when I noticed a statement outside the the
> function.
>
>    Is there a good reason for this call to add_action() being located
> outside all function definitions in this file? Shouldn't this be located at
> the top of the file where people would be less likely to miss it?
>
> function preview_theme() {
>    .
>    .
>    .
> }
> add_action('setup_theme', 'preview_theme');
>
>
> Thanks,
>
> Charles Clarkson
> --
> Mobile Home Investor
> Free Market Advocate
> Programmer
>
> Stephenville, TX
> http://www.clarksonenergyhomes.com/wordpress/about/
> http://twitter.com/CharlesClarkson
> +1 (254) 968-8328
> _______________________________________________
> 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