11#! /usr/bin/env bash
22
33# Exit on error
4- set -e
4+ set -ex
55
66hosts_file=" $GITHUB_WORKSPACE /.github/hosts.yml"
77export PATH=" $PATH :$COMPOSER_HOME /vendor/bin"
@@ -266,6 +266,59 @@ function deploy() {
266266 dep deploy " $GITHUB_BRANCH "
267267}
268268
269+ function block_emails() {
270+
271+ hosts_block_email=$( shyaml get-value " $GITHUB_BRANCH .block_emails" < " $hosts_file " 2> /dev/null || exit 0)
272+
273+ if [[ -n " $hosts_block_email " ]]; then
274+ BLOCK_EMAILS=" $hosts_block_email "
275+ fi
276+
277+ if [[ -n " $BLOCK_EMAILS " ]]; then
278+
279+ # priority: 1. hosts.yml 2. vip 3. WP
280+ echo -e " \033[34mSETUP EMAIL BLOCKING\033[0m"
281+ if [[ -d " $HTDOCS /wp-content/client-mu-plugins" ]]; then
282+ BLOCK_EMAIL_DIR=" $HTDOCS /wp-content/client-mu-plugins"
283+ elif [[ -d " $HTDOCS /wp-content/mu-plugins" ]]; then
284+ BLOCK_EMAIL_DIR=" $HTDOCS /wp-content/mu-plugins"
285+ fi
286+
287+ hosts_block_email_dir=$( shyaml get-value " $GITHUB_BRANCH .block_emails_plugin_path" < " $hosts_file " 2> /dev/null || exit 0)
288+
289+ if [[ -n " $hosts_block_email_dir " ]]; then
290+ BLOCK_EMAIL_DIR=" $HTDOCS /wp-content/$hosts_block_email_dir "
291+ elif [[ -n " $BLOCK_EMAILS_PLUGIN_PATH " ]]; then
292+ BLOCK_EMAIL_DIR=" $HTDOCS /wp-content/$BLOCK_EMAILS_PLUGIN_PATH "
293+ fi
294+
295+ BLOCK_EMAIL_DIR=" ${BLOCK_EMAIL_DIR%/ } "
296+
297+ # using this naming convention by default to load this plugin first in mu-plugin loading phase.
298+ BLOCK_EMAIL_PLUGIN_NAME=" 000-block-emails.php"
299+
300+ hosts_block_email_file_name=$( shyaml get-value " $GITHUB_BRANCH .block_emails_plugin_file_name" < " $hosts_file " 2> /dev/null || exit 0)
301+
302+ if [[ -n " $hosts_block_email_file_name " ]]; then
303+ BLOCK_EMAIL_PLUGIN_NAME=" ${hosts_block_email_file_name} .php"
304+ elif [[ -n " $BLOCK_EMAILS_PLUGIN_FILE_NAME " ]]; then
305+ BLOCK_EMAIL_PLUGIN_NAME=" ${BLOCK_EMAILS_PLUGIN_FILE_NAME} .php"
306+ fi
307+
308+ BLOCK_EMAIL_PLUGIN_PATH=" $BLOCK_EMAIL_DIR /$BLOCK_EMAIL_PLUGIN_NAME "
309+
310+ if [[ -d " $BLOCK_EMAIL_DIR " ]]; then
311+ rsync -av " /000-block-emails.php" " $BLOCK_EMAIL_PLUGIN_PATH "
312+ echo -e " \033[34mEMAIL BLOCK [Activated]: $BLOCK_EMAIL_PLUGIN_PATH \033[0m"
313+ else
314+ echo -e " \033[31mEMAIL BLOCK [PATH ERROR]: $BLOCK_EMAIL_DIR doesn't exist.\033[0m"
315+
316+ fi
317+ fi
318+
319+ }
320+
321+
269322function main() {
270323
271324 init_checks
@@ -279,6 +332,7 @@ function main() {
279332 maybe_run_node_build
280333 maybe_install_submodules
281334 setup_wordpress_files
335+ block_emails
282336 deploy
283337 fi
284338}
0 commit comments