I've got projects (both themes and plugins) set up as composer projects. These projects can be dev-dependencies of each other. Right now I'm working on a theme which requires the vendor/autoload.php
file. However, when I bring that theme into another project (like a plugin), I still need access to the autoload.php
. The problem is that the autoload.php
file is now inside the directory structure for the plugin and not the theme.
define('FL_CHILD_THEME_DIR', get_stylesheet_directory());
define('FL_CHILD_THEME_URL', get_stylesheet_directory_uri());
if (!file_exists(FL_CHILD_THEME_DIR . '/vendor/autoload.php')) {
// somehow check all the directories within the plugins directory
// for vendor/autoload.php
} else {
require FL_CHILD_THEME_DIR . '/vendor/autoload.php';
}
}
I've tried using things like scandir
and glob
but I'm not getting any closer. I thought something like this would work, but I'm still no closer.
foreach(glob(plugin_dir_path() . 'vendor/autoload.php') as $file {
require $file;
}
composer.json
so that there's a singularvendor
folder inwp-content
that's loaded which contains the shared dependencies. Then the WP custom installer would make sure the themes and plugins themselves went to the right folders rather than thevendor
folder. The situation you're in shouldn't occur, can you give us some more context as to the structure?