[theme-reviewers] wrapping functions with if( ! function_exists() ) {…}

Ulrich Pogson grapplerulrich at gmail.com
Sat Oct 11 15:48:20 UTC 2014


The guidelines states: "Themes must not provide backward compatibility for
out-of-date WordPress versions (more than two prior major WordPress
versions – currently, that means versions prior to WordPress 3.8),
including using function_exists() conditional wrappers for current *WordPress
functions*." https://make.wordpress.org/themes/handbook/guidelines/

This is one thing we require but I could not find in the guidelines.
"Function calls must be placed inside callbacks and hooked into appropriate
actions or filters (such as after_setup_theme for Theme setup functions, or
widgets_init for Widgets/dynamic sidebar functions)"

The *theme functions* can be wrapped in a if( !function_exists()) {…}. At
the moment this is not required nor recommended.

Actually Chris wrote a good answer below Ottos:
http://wordpress.stackexchange.com/a/111318/17937

P.S I personally don't think every every theme function needs to be wrapped
in if( !function_exists()) {…} because depending on the function you can
just as well overwrite it with another function hooking into the same hook.
If the function was a bit more complex then it would be better to make the
function extendable with hooks and filters. So that child theme could
change single values instead of having to copy the whole function.

On 11 October 2014 17:19, Bego Mario Garde <pixolin at yahoo.com> wrote:

> Hello,
>
> I have another question, this time regarding the usage of
>
>   if( !function_exists()) {…}
>
> for non-core theme-functions.
>
> Otto (Samuel Wood) explained very well on
>
> http://wordpress.stackexchange.com/questions/111299/why-use-if-function-exists
>
> "The if function_exists approach allows for a child theme to override
> the function definition by simply defining the function themselves.
> Since child theme's functions.php files load first, then they will
> define the function first and the parent's definition will not get loaded."
>
> Chip Bennet defined on
>
> http://www.chipbennett.net/2011/04/20/a-guide-to-reviewing-themes-for-the-wordpress-theme-repository/
>
>
> "No core WordPress functions introduced prior to one previous, major
> WordPress release are wrapped in function_exists() conditionals."
>
> Yet I miss this being mentioned in the theme review guidelines nor do I
> know whether wrapping functions is only *recommended* or even *required*.
>
> Could someone please explain how I should deal with it?
>
> Thank you, Bego (@pixolin)
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20141011/56a4e4aa/attachment.html>


More information about the theme-reviewers mailing list