简体   繁体   中英

Can I use wp-cli to get the Wordpress installation directory?

Can I use wp-cli to return a value for the local Wordpress installation root directory?

Ideally I'd like a wp-cli command like "wp pathname" that returns "user/myname/sites/project_a" when invoked from inside Projects A's installation, and "user/myname/sites/project_b" when invoked inside Project B.

I'm writing a bash script to dump a Wordpress database and do a little post-processing on it. I'm calling on wp-cli to make the dump; I'd also like to use wp-cli to find the pathname for the installation so that I can guarantee than when invoked anywhere in the current installation the dumpfile will always be written to "some/path/to/project_name/dbdumps/". I can't find anything in the documentation about install directory.

wp-cli seems like the right tool for the job because it's Wordpress aware, but I am happy to use some other tool that is capable of discovering my install directory; perhaps a creative and elegant use of the find command, or a way to report the value of Wordpress's FTP_BASE variable?

I ended up doing this with bash, not wp-cli, by using BASH_SOURCE.

There doesn't appear to be a way to do this from within wp-cli itself, but since my script is always running from inside the Wordpress install directory it doesn't matter — I can just find my script's location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM