How to detect if a folder is having a WordPress installation or not ?
WP-CLI
does that and gives the error This does not seem to be a WP installation
, and detects correctly if the directory has a WP install even if it is in any of the subfolders (wp-includes/images
or wp-includes/js
) .
I went through the code and it searches for index.php
and compares content with the original index.php . One more thing it does is to check for the presence of wp-includes/version.php
. Got the idea but how it works on subfolders like those mentioned above is still not clear . Do anybody have any idea on how to do this ? Thanks in advance .
2
Answers
So i have scribbled a script that detects a WP install . It works as expected inside a wp install folder , but if it is not inside a WordPress install it executes an infinite loop . Can somebody guide on how to stop at top level directory as mentioned by @O.Jones ? Here is my code .
Look for the
wp-config.php
file. If you find it,require
it, then try to use its constantsDB_HOST
,DB_USER
,DB_PASSWORD
andDB_NAME
to connect to the WordPress database associated with the WordPress instance. If that works, you very likely have a working WordPress instance.If your current working directory doesn’t have
wp-config.php
look at parent directories recursively until you (a) find it or (b) come to the top level directory.wp-cli does more elaborate things. But this should work for you.