I'm currently using a custom child theme across multiple sites, and would like to modularise particular custom features (e.g. ecommerce) by separating them into individual php files, and including the relevant ones as needed (without making them into plugins), since otherwise it's difficult to keep track of the customisations in each file across multiple variations of the child theme.
To do this, I'd like to be able to copy particular php files into a folder in the child theme, and for these to be included automatically. How would I achieve this?I've tried several solutions, but they don't seem to work in this context. Here's an example of a code I used:
function include_all_php($folder){
foreach (glob("{$folder}/*.php") as $filename)
{
include $filename;
}
}
include_all_php("includes"); // "includes" is the name of the folder in the child theme