Advanced WordPress Management Using WP-CLI on Alibaba Cloud ECS — Part 3

1. Managing Multiple WordPress sites using WP-CLI

$ cd ~
$ wp @example plugin list
$ wp @another plugin list
# Alias Groups
@all-examples:
- @example
- @another
$ sudo touch /usr/local/bin/wp-plugin-list.sh
$ sudo nano /usr/local/bin/wp-plugin-list.sh
#!/bin/bash 
declare -a sites=(
'/var/www/an-example-domain.com/htdocs'
'/var/www/another-example-domain.com/htdocs'
)
for site in "${sites[@]}";
do
echo “List plugins for:
echo $site
wp --path=$site plugin list
echo “ “
done

2. Using SSH with WP-CLI for remote management

$ sudo mkdir ~/.wp-cli && sudo touch ~/.wp-cli/config.yml
$ sudo nano ~/.wp-cli/config.yml
#Global Parameter Defaults
disabled_commands:
- db drop
# Aliases
@example:
ssh: new_user@an-example-domain.com/var/www/an-example-domain.com/htdocs/
@another:
ssh: new_user@another-example-domain.com/var/www/another-example-domain.com/htdocs/
@all-examples:
- @example
- @another
$ cd /local/sites/anotherexampledomain/app/public
$ sudo nano wp-cli.yml
@test:
ssh: new_user@another-example-domain.com/var/www/test.another-example-domain.com/htdocs
@staging:
ssh: new_user@another-domain.com/var/www/staging.another-domain.com/htdocs/
@production:
ssh: new_user@another-domain.com/var/www/another-domain.com/htdocs/
@test:
ssh: new_user@another-example-domain.com/var/www/test.another-example-domain.com/htdocs
@staging:
ssh: new_user@another-domain.com/var/www/staging.another-domain.com/htdocs/
@production:
ssh: new_user@another-domain.com/var/www/another-domain.com/htdocs/
@prerelease:
- @test
- @staging

3. Using WP-CLI Scaffold to speed up development

  • Child Themes
  • Feature Plugins
  • Custom Post Types
  • Custom Taxonomies
  • PHPunit testing of plugins
  • PHPunit testing of themes
wp @example scaffold child-theme twentyseventeen-child --parent_theme=twentyseventeen --theme_name="Twenty Seventeen Child" --author="New User" --author_uri="an-example-domain.com" --theme_uri="an-example-theme.com" —activate
<?php
global $wpdb;
$random_example_post = $wpdb->get_var(
"SELECT post_title
FROM $wpdb->posts
WHERE post_type = 'post'
AND post_status = 'publish'
ORDER BY rand()
LIMIT 1"
);
echo "A random example post: $random_example_post \n";
if( defined( 'WP_CLI' ) && WP_CLI ) {        class Custom_Commands {                function random_post ( $args, $assoc_args ) {                        global $wpdb;                        $random_post = $wpdb->get_var(
"SELECT post_title FROM $wpdb->posts
WHERE post_type = 'post'
AND post_status = 'publish'
ORDER BY rand()
LIMIT 1");
WP_CLI::success( "Random post: $random_post" );
}
}
WP_CLI::add_command( 'custom_commands', 'Custom_Commands' );
}

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Creation of simple pipeline using Microsoft Azure data factory

Loot: Driving NFT Paradigm With Collective Imagination

Bounce Finance Guide- Presale

Fifth Week of Coding 5th July — 9th July

Multiple Gradients with Shapes

Punchh’s automation framework — Enhancing scale and quality of mobile app testing

How to access Jupyter Notebooks running in your local server with ngrok (and an intro to GNU…

MongoDB vs. MySQL

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

How to build a CRUD App on Heroku with Php & Pdo & Github Deployment & ClearDB & MySQL Workbench

Parsing site with Node JS

Top Node.Js Web Development Framework Trends For 2022

electron, electron-builder, node, sqlite3 and universal Mac builds (x64 and arm64)