Skip to content

Commit 1d5278b

Browse files
committed
feat: block emails
1 parent ffa677a commit 1d5278b

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

Diff for: 000-block-emails.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Plugin Name: Block Emails
4+
* Description: Blocks sending of emails when using wp_mail function to send emails.
5+
* Author: rtCamp
6+
* Author URI: https://rtcamp.com
7+
* License: GPL2
8+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
9+
* Version: 1.0
10+
*/
11+
12+
// Comment this code if you don't want to disable emails altogether.
13+
if ( ! function_exists( 'wp_mail' ) ) {
14+
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
15+
return true;
16+
}
17+
}
18+
?>

Diff for: Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ RUN curl -sL https://deb.nodesource.com/setup_16.x | bash && \
4646
apt install -y nodejs && \
4747
rm -rf /var/lib/apt/lists/*
4848

49-
COPY deploy.php hosts.yml /
49+
COPY deploy.php hosts.yml 000-block-emails.php /
5050
COPY *.sh /
5151
RUN chmod +x /*.sh
5252

Diff for: main.sh

+55-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Exit on error
4-
set -e
4+
set -ex
55

66
hosts_file="$GITHUB_WORKSPACE/.github/hosts.yml"
77
export 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+
269322
function 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

Comments
 (0)