Edge-case bug with require/include and WP-CLI
-
In the
Wow_Plugin
class, in the_includes
method, there’s three includes:if ( ! class_exists( 'Wow_Company' ) ) { include_once 'includes/class-wow-company.php'; } include_once 'admin/class-admin.php'; include_once 'public/class-public.php';
Unless the include uses path semantics such as
./
,.//
or/
(depending on OS), PHP actually searches the local directory last, which is probably not what you mean.We’ve run into an issue with your plugin because our theme happens to have a file at exactly
admin/class-admin.php
, same as you, and when we run any WP CLI commands while we are cd’d into our theme, your plugin is including our file.As noted, this is an edge case but is pretty easy to fix by just adding
__DIR__
, same as you are already doing at the bottom of the file.We made a very minimal theme to repro this which is available here: https://github.com/vendi-advertising/vendi-minimum-theme
- Take a brand new WordPress site
- Install and activate the modal-window plugin
- Install and activate the theme (don’t bother browsing to it in a browser)
- cd into the vendi-minimum-theme directory
- Try running a WP CLI command such as
wp cache flush
, and you should see a die message along with a stack trace showing who is requesting for it to be included.
- The topic ‘Edge-case bug with require/include and WP-CLI’ is closed to new replies.