Tips on what to do with bloating setup.php file

I’ve been using the Sage base theme on my work’s website for just over a year. I really love this theme. I’ve been recommending it to developers and have used it on sites requiring me to use WP.

As we continue to add more features to the site, I’m noticing that our setup.php file is getting a bit bloated.

I am sure other developers have come across this before, and I am curious to learn from more experienced folks how they deal with keeping the setup file manageable.

You could try to add this code to your setup.php file:

/**
 * Include all actions files from actions folder
 */
foreach (glob(__DIR__ . '/Actions/*') as $filename) {
    require_once $filename;
}

…and split your logic into multiple files under /Actions/ folder.

Kindly suggested by @UnlocDavid

6 Likes

I have a similar problem. Since the Sage team removed helpers.php suggesting that we used classes for all the helper functions I tried to think about this the laravel/sage way.

It was fairly easy with everything user or cpt related, but I have a lot of holes in this strategy. For example, I don’t know where to put all conditionals (maybe in a post class similar shared with cpt methods?), query related methods, and so on and so forth.

At the end of the day it is a very personal matter, but I would love to hear the community’s thoughts and examples.

1 Like