Skip to content

Commit

Permalink
Update dev-tools scripts (#779)
Browse files Browse the repository at this point in the history
* Skip plugins and themes when calling WP-CLI commands in dev-tools

* Update the wording in setup.sh to be more descriptive and follow the same style
  • Loading branch information
rinatkhaziev authored Jun 17, 2024
1 parent 9f49e69 commit 1c36d3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
8 changes: 4 additions & 4 deletions dev-tools/add-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ done
[ -z "$slug" ] && echo "ERROR: Missing or empty slug argument" && syntax
[ -z "$title" ] && echo "ERROR: Missing or empty title argument" && syntax

network_domain=$(wp --allow-root site list --field=domain | head -n1)
network_domain=$(wp --allow-root site list --field=domain --skip-plugins --skip-themes | head -n1)

site_domain=$slug.$network_domain

echo "Checking if this is a multisite installation..."
if ! wp --allow-root core is-installed --network; then
if ! wp --allow-root core is-installed --network --skip-plugins --skip-themes; then
echo "ERROR: Not a multisite"
exit 1
fi

echo "Checking if $site_domain already belongs to another site..."
if wp --allow-root --path=/wp site list --field=domain | grep -q "^$site_domain$"; then
if wp --allow-root --path=/wp site list --field=domain --skip-plugins --skip-themes | grep -q "^$site_domain$"; then
echo "ERROR: site with domain $site_domain already exists"
exit 1
fi

echo "Creating the new site..."
wp --allow-root --path=/wp site create --title="$title" --slug="$slug"
wp --allow-root --skip-plugins --skip-themes --path=/wp site create --title="$title" --slug="$slug"

echo
echo "======================================================================"
Expand Down
6 changes: 3 additions & 3 deletions dev-tools/dev-env-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ function dev_env_add_admin( $args, $assoc_args ) {
return;
}

WP_CLI::runcommand( 'user create ' . $username . ' ' . $email . ' --user_pass=' . $password . ' --role=administrator' );
WP_CLI::runcommand( 'user create ' . $username . ' ' . $email . ' --user_pass=' . $password . ' --role=administrator' . ' --skip-plugins --skip-themes' );
WP_CLI::success( 'User "' . $username . '" created.' );

if ( is_multisite() ) {
// on multisite we do more setup
WP_CLI::runcommand( 'super-admin add ' . $username );
WP_CLI::runcommand( 'super-admin add ' . $username . ' --skip-plugins --skip-themes' );
WP_CLI::success( 'User "' . $username . '" added to super-admin list.' );

$sites = get_sites();
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
$subsite_url = home_url();

WP_CLI::runcommand( 'user set-role ' . $username . ' administrator --url=' . $subsite_url );
WP_CLI::runcommand( 'user set-role ' . $username . ' administrator --url=' . $subsite_url . ' --skip-plugins --skip-themes' );

restore_current_blog();
}
Expand Down
20 changes: 11 additions & 9 deletions dev-tools/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,29 @@ else
fi

# Make sure to check the core files are there before trying to install WordPress.
echo "Waiting for core files to be copied"
echo "Waiting for WordPress core files to be copied"
i=0;
while [ ! -f /wp/wp-includes/pomo/mo.php ]
do
printf "."
sleep 0.5
i=$((i+1))
# Roughly 1 minute
# Roughly 2 minutes
if [ $i -eq 120 ]; then
echo "ERROR: WordPress core files not found. Please try to restart or destroy the environment"
echo "ERROR: Failed to copy WordPress core files in time. Please try to restart the environment."
exit 1;
fi
done

if [ -n "${LANDO_INFO}" ] && [ "$(echo "${LANDO_INFO}" | jq -r '.["vip-mu-plugins"]')" != 'null' ]; then
echo 'Waiting for mu-plugins...'
echo 'Waiting for MU-plugins to be copied'
i=0;
while [ ! -f /wp/wp-content/mu-plugins/.version ]; do
printf "."
sleep 1
i=$((i+1))
if [ $i -eq 60 ]; then
echo "ERROR: mu-plugins not found. Please try to restart or destroy the environment"
if [ $i -eq 120 ]; then
echo "ERROR: Failed to copy MU-plugins in time. Please try to restart the environment."
exit 1;
fi
done
Expand All @@ -103,14 +105,14 @@ fi

printf "Waiting for MySQL to come online"
second=0
while ! mysqladmin ping -h "${db_host}" --silent && [ "${second}" -lt 60 ]; do
while ! mysqladmin ping -h "${db_host}" --silent && [ "${second}" -lt 120 ]; do
printf "."
sleep 1
second=$((second+1))
done
echo ""
if ! mysqladmin ping -h "${db_host}" --silent; then
echo "ERROR: mysql has failed to come online"
echo "ERROR: MySQL has failed to come online. Please check the database container logs for details."
exit 1;
fi

Expand Down Expand Up @@ -144,7 +146,7 @@ fi

echo "Checking for WordPress installation..."

wp cache flush
wp cache flush --skip-plugins --skip-themes
if ! wp core is-installed --skip-plugins --skip-themes; then
echo "No installation found, installing WordPress..."

Expand Down

0 comments on commit 1c36d3b

Please sign in to comment.