Nothing. A theme_name_setup()
function should not even exist.
-
The name is too vague. What does setup mean? This is also the root of your question, because such a name tells us nothing about what the function does. Could be anything or nothing at all. Technically, themes don’t even need a
functions.php
. But they work, the setup happens by WordPress. -
It violates the principle of single responsibility. This term comes from object-oriented programming, but the idea applies to all good code, it is even the core of the UNIX philosophy: Do one thing and do it well.
This leads us to the next problem. -
It impairs interoperability. Consider the following function:
add_action( 'after_setup_theme', 'theme_name_setup' ); function theme_name_setup() { require 'widgets.php'; require 'comment-enhancements.php'; require 'javascript.php'; }
What do I have to do to load only
widgets.php
andjavascript.php
in my child theme? I have to unhook the broad function and repeat parts of your code. And then I pray you will never rename, combine or split files in an update of your parent theme.
To express this in a more positive way:
-
Give each class and function a name that tells the reader what it does. If you cannot come up with a good, precise name, this code does probably too much.
-
You can use the same hook with multiple callbacks. This is the point of the action/filter API. Use it.
-
Try to let each function return an useful value, so you can test and debug it separately.
load_theme_textdomain()
for example returnsTRUE
when a file was found,FALSE
otherwise. If you are using a separate function to load the translation, you can use that return value.