Last active
November 10, 2024 22:16
-
-
Save josanua/80e34f43ef110fb6911a924546a07997 to your computer and use it in GitHub Desktop.
wp cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// installing | |
https://make.wordpress.org/cli/handbook/guides/installing/\ | |
https://deliciousbrains.com/complete-guide-to-installing-wp-cli/ | |
// https://www.youtube.com/watch?v=O_LoQ0WC7DQ | |
//--> The Complete Guide to Installing WP-CLI | |
https://deliciousbrains.com/complete-guide-to-installing-wp-cli/#verifying-wp-cli | |
https://wp-cli.org/ | |
https://make.wordpress.org/cli/handbook/ | |
https://make.wordpress.org/cli/handbook/quick-start/ | |
https://developer.wordpress.org/cli/commands/ | |
//--> install on mamp/local | |
https://wp-cli.org/ | |
https://medium.com/@tomlarge/wordpress-made-easy-with-wp-cli-9d52b298c5a6 | |
// good one install on mamp/local | |
https://desktopvibes.com/using-wp-cli-to-manage-multiple-mamp-websites/ | |
// 1. go to: | |
cd /usr/local/bin | |
// 2. after that do installation from here https://make.wordpress.org/cli/handbook/guides/installing/ | |
cd /usr/local/bin | |
// 3. | |
// check if it works | |
wp --info | |
wp option get siteurl | |
https://www.alibabacloud.com/blog/advanced-wordpress-management-using-wp-cli-on-alibaba-cloud-ecs--part-3_591416 | |
//--> Troubles | |
// `Access denied for user 'root'@'localhost' (using password: YES)` | |
// Error establishing a database connection | |
// needs to setup the same port address in MAMP from phpMyAdmin setings and write it in 'DB_HOST' - 127.0.0.1:8889 (write numbers but not 'localhost' word) | |
https://www.youtube.com/watch?v=12jKRfmMTbU | |
https://desktopvibes.com/using-wp-cli-to-manage-multiple-mamp-websites/ | |
// config file | |
// nano ~/.wp-cli/config.yml | |
WP-CLI Commands A-N | |
wp admin – Open /wp-admin/ in a browser. | |
wp cache – Adds, removes, fetches, and flushes the WP Object Cache object. | |
wp cap – Adds, removes, and lists capabilities of a user role. | |
wp cli – Review current WP-CLI info, check for updates, or see defined aliases. | |
wp comment – Creates, updates, deletes, and moderates comments. | |
wp config – Generates and reads the wp-config.php file. | |
wp core – Downloads, installs, updates, and manages a WordPress installation. | |
wp cron – Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules. | |
wp db – Performs basic database operations using credentials stored in wp-config.php. | |
wp dist-archive – Create a distribution archive based on a project’s .distignore file. | |
wp embed – Inspects oEmbed providers, clears embed cache, and more. | |
wp eval – Executes arbitrary PHP code. | |
wp eval-file – Loads and executes a PHP file. | |
wp export – Exports WordPress content to a WXR file. | |
wp find – Find WordPress installations on the filesystem. | |
wp help – Get help on WP-CLI, or on a specific command. | |
wp i18n – Provides internationalization tools for WordPress projects. | |
wp import – Imports content from a given WXR file. | |
wp language – Installs, activates, and manages language packs. | |
wp media – Imports files as attachments, regenerates thumbnails, or lists registered image sizes. | |
wp menu – Lists, creates, assigns, and deletes the active theme’s navigation menus. | |
wp network – Perform network-wide operations. | |
WP-CLI Commands O-Z | |
wp option – Retrieves and sets site options, including plugin and WordPress settings. | |
wp package – Lists, installs, and removes WP-CLI packages. | |
wp plugin – Manages plugins, including installs, activations, and updates. | |
wp post – Manages posts, content, and meta. | |
wp post-type – Retrieves details on the site’s registered post types. | |
wp profile – Profiles arbitrary code execution, files, key metrics, and stages. | |
wp rewrite – Lists or flushes the site’s rewrite rules, updates the permalink structure. | |
wp role – Manages user roles, including creating new roles and resetting to defaults. | |
wp scaffold – Generates code for post types, taxonomies, plugins, child themes, etc. | |
wp search-replace – Searches/replaces strings in the database. | |
wp server – Launches PHP’s built-in web server for a specific WordPress installation. | |
wp shell – Opens an interactive PHP console for running and testing PHP code. | |
wp sidebar – Lists registered sidebars. | |
wp site – Creates, deletes, empties, moderates, and lists one or more sites on a multisite installation. | |
wp super-admin – Lists, adds, or removes super admin users on a multisite installation. | |
wp taxonomy – Retrieves information about registered taxonomies. | |
wp term – Manages taxonomy terms and term meta, with create, delete, and list commands. | |
wp theme – Manages themes, including installs, activations, and updates. | |
wp transient – Adds, gets, and deletes entries in the WordPress Transient Cache. | |
wp user – Manages users, along with their roles, capabilities, and meta. | |
wp widget – Manages widgets, including adding and moving them within sidebars. | |
//--> Download and install WordPress in seconds | |
https://developer.wordpress.org/cli/commands/core/download/ | |
// greate post about | |
https://www.cloudways.com/blog/wp-cli-commands/ | |
// start to use main commands | |
wp core download // (install in current folder) | |
wp core download --path=gutenberg // (install in gutenberg folder) | |
// Steps | |
wp core download | |
wp config create --dbname=kickjobs_update --dbuser=root | |
wp core install --url= --title= --admin_user= --admin_email= | |
// create wp-config and db connection | |
wp config create --dbname=testing --dbuser=wp --dbpass=securepswd --locale=ro_RO | |
//--> install bedrock | |
composer create-project roots/bedrock | |
# install plugins with bedrock | |
composer require wpackagist-plugin/contact-form-7 | |
# folder structure | |
├── composer.json # → Manage versions of WordPress, plugins & dependencies | |
├── config # → WordPress configuration files | |
│ ├── application.php # → Primary WP config file (wp-config.php equivalent) | |
│ └── environments # → Environment specific configs | |
│ ├── development.php # → Development config | |
│ └── staging.php # → Staging config | |
├── vendor # → Composer packages (never edit) | |
└── web # → Web root (document root on your webserver) | |
├── app # → wp-content equivalent | |
│ ├── mu-plugins # → Must use plugins | |
│ ├── plugins # → Plugins | |
│ ├── themes # → Themes | |
│ └── uploads # → Uploads | |
├── wp-config.php # → Required by WP (never edit) | |
├── index.php # → WordPress view bootstrapper | |
└── wp # → WordPress core (never edit) | |
# Some utils | |
// db export db | |
wp db export (export sql in wp folder) | |
# change links to ssl | |
wp search-replace 'http://example.com' 'https://example.com' --dry-run (just for testing) | |
wp search-replace 'http://example.com' 'https://example.com' | |
wp search-replace 'example.com' 'example.com' --dry-run (just for testing) | |
wp search-replace 'example.com' 'example.com' | |
# for industria project | |
wp user meta list 1 | |
wp user meta get 1 user-shifts | |
wp post meta get 2566 shift-occupied-seats | |
//--> get basic data | |
https://developer.wordpress.org/cli/commands/option/ | |
wp option get siteurl | |
//--> Work with multisite | |
https://docs.wpvip.com/how-tos/search-replace/ | |
# show list of sites url | |
wp site list --field=url | |
# work with db | |
# search and replace urls | |
https://developer.wordpress.org/cli/commands/search-replace/ | |
wp search-replace 'http://localhost:8001/' 'http://kd.localhost:8000/' --dry-run --network (dry-run it;s for testing) | |
wp search-replace 'example.dev' 'example.com' --skip-columns=guid | |
// replace url on migration, replace sitename | |
// wp search-replace <‘old’> <‘new’> | |
wp search-replace https://oldsite.com https://newsite.com | |
# Turn your production multisite database into a local dev database | |
$ wp search-replace --url=example.com example.com example.test 'wp_*options' wp_blogs | |
# Or, if you only want to change the option, you can do: | |
wp option update home 'http://example.com' | |
wp option update siteurl 'http://example.com' | |
#! At the end of a successful search-replace command, you will be reminded to flush the cache. This is important step is required prior to checking your results: | |
wp cache flush | |
// apply commands on a specific multisite | |
https://danielbachhuber.com/tip/run-wp-cli-command-wordpress-multisite/ | |
// select site domain and apply plugin list test command | |
wp site list (to take site addresses) | |
wp --url=kd.localhost:8000/wp/ plugin list | |
// work with WooCommerce | |
wp --url=kd.localhost:8000/wp/ wc tax list --user=1 | |
wp --url=kd.localhost:8000/wp/ wc product_cat list --user=1 | |
//--> Work with users | |
https://wp-kama.ru/handbook/wp-cli/wp/user | |
https://support.cloudways.com/en/articles/5126631-managing-users-and-roles-using-wordpress-cli | |
# List user IDs | |
$ wp user list --field=ID | |
1 | |
# Create a new user. | |
$ wp user create bob [email protected] --role=author | |
Success: Created user 3. | |
Password: k9**&I4vNH(& | |
# Update an existing user. | |
$ wp user update 123 --display_name=Mary --user_pass=marypass | |
# update user pass with id param | |
$ wp user update 1 --user_pass=admin | |
# Delete user 123 and reassign posts to user 567 | |
$ wp user delete 123 --reassign=567 | |
# on multisite we have different behaviour | |
wp user get 26 --url=site.name ( http://kd.localhost:8000 ) | |
//--> Some global stuff | |
// https://deliciousbrains.com/complete-guide-to-installing-wp-cli/ | |
// https://make.wordpress.org/cli/handbook/references/config/ | |
WP_CLI_CONFIG_PATH | |
//--> Some quick commands, Manage WordPress Plugin via WP-CLI | |
// https://www.cloudways.com/blog/wp-cli-commands/ | |
// work with plugins | |
wp plugin install [plugin name] (wp plugin install woocommerce) | |
wp plugin activate woocommerce | |
// check the version of the WordPress Core, manage WordPress Core | |
wp core version | |
wp core update | |
wp theme status twentytwentytwo | |
// commands | |
wp help <command name> | |
//--> work db | |
https://developer.wordpress.org/cli/commands/db/ | |
# get db data | |
wp db size | |
# Import MySQL from a file. | |
wp db import wordpress_dbase.sql | |
# export | |
https://developer.wordpress.org/cli/commands/db/export/ | |
wp db export wordpress_dbase.sql --allow-root | |
// 1. database migration without wp cli | |
UPDATE wp_options SET option_value = replace(option_value, 'https://www.watchesworld.com', 'http://localhost:8888') WHERE option_name = 'home' OR option_name = 'siteurl'; | |
UPDATE wp_posts SET guid = replace(guid, 'https://www.watchesworld.com', 'localhost:8888'); | |
UPDATE wp_posts SET post_content = replace(post_content, 'https://www.watchesworld.com', 'localhost:8888'); | |
UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://www.watchesworld.com', 'localhost:8888'); | |
// 2. do | |
wp cache flush |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment