Skip to content

090ebier/wpcli-toolbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

wpcli-toolbox (WP-CLI Manager & Automation Tool)

A menu-driven + direct command Bash toolbox to run WP-CLI tasks on servers (DirectAdmin / cPanel / system PHP) with:

  • Automatic PHP detection (or choose a specific version)
  • Auto-download of wp-cli.phar
  • Runs WP-CLI with --allow-root
  • Interactive menu for common WordPress operations
  • Optional permissions & ownership fixes after sensitive operations

Quick Run (One-liner)

Run directly from GitHub (raw):

bash <(curl -Ls https://raw.githubusercontent.com/090ebier/wpcli-toolbox/refs/heads/main/wp-cli.sh)

Features

  • ✅ Auto-detect PHP binaries:

    • DirectAdmin: /usr/local/php*/bin/php
    • cPanel: /opt/cpanel/ea-php*/root/bin/php
    • System PHP: php in PATH
  • ✅ Auto-selects the highest available PHP version

  • ✅ Choose a specific PHP version via argument (e.g. 7.4, 81, php74)

  • ✅ Interactive menu for most used WordPress maintenance tasks

  • ✅ Direct command mode (run any WP-CLI command)

  • ✅ Optional permissions fix:

    • Directories: 755
    • Files: 644
    • wp-config.php: 600
  • ✅ Attempts ownership fix (chown -R user:user .) when possible


Requirements

  • bash
  • curl
  • At least one php binary available on the server
  • Recommended to run inside your WordPress directory (public_html)

If you don’t have root/sudo, ownership (chown) may fail and the script will warn you.


Usage

1) Interactive Menu Mode

Run with no arguments:

./wp-cli.sh

If multiple PHP versions are found, you’ll be asked to choose one.


2) Direct Command Mode

Anything after the script name will be executed as a WP-CLI command.

Examples:

./wp-cli.sh core version --extra
./wp-cli.sh plugin update --all
./wp-cli.sh cache flush

PHP Version Selection

You can specify a PHP version as the first argument. Supported formats:

  • 74, 7.4, php74, PHP7.4
  • 81, 8.1, php81

Examples:

Use PHP 7.4:

./wp-cli.sh 7.4 core version

Use PHP 8.1:

./wp-cli.sh 8.1 plugin update --all

If the requested version is not found, the script prints available versions.


Working Directory Check

The script prefers to run inside public_html. If you are not in a public_html directory, it warns you and asks whether to continue.

Expected paths:

  • /home/username/public_html
  • /home/username/domains/example.com/public_html

It also tries to detect the system user from the current path to fix ownership automatically.


Permissions & Ownership Fix

Some operations enable auto-fixing permissions after running WP-CLI:

  • Directories: 755
  • Files: 644
  • wp-config.php: 600

Then it attempts:

chown -R user:user .

If permissions do not allow ownership changes (no root/sudo), it shows a warning and continues.


Common Examples

Download WordPress Core

./wp-cli.sh core download --version=latest --locale=fa_IR

Update WordPress Core

./wp-cli.sh core update

Export Database Backup

./wp-cli.sh db export backup-$(date +%Y%m%d-%H%M%S).sql

Import Database Restore

./wp-cli.sh db import backup.sql

Search & Replace Domain (skip GUID)

./wp-cli.sh search-replace old-domain.tld new-domain.tld --skip-columns=guid

Install & Activate a Plugin

./wp-cli.sh plugin install contact-form-7 --activate

Reset Admin Password (interactive prompt)

./wp-cli.sh user update admin --prompt=user_pass

Security Notes

  • This toolbox runs WP-CLI with --allow-root by design (useful for server administration/support environments).

  • WP-CLI is downloaded to:

    • WPCLI_PATH="/tmp/wp-cli.phar"
  • The temporary file is removed on exit.


Troubleshooting

“No PHP versions found”

Make sure PHP exists on the server:

which php
php -v

“Not in public_html”

You can continue, but best practice is:

cd /home/<user>/public_html

“Could not change ownership”

You likely need sudo/root permissions for chown.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages