Skip to content

Commit f831a9d

Browse files
authored
Merge pull request #42 from Xieyt/master
feat: block emails
2 parents ffa677a + a2720f4 commit f831a9d

File tree

4 files changed

+108
-15
lines changed

4 files changed

+108
-15
lines changed

000-block-emails.php

Lines changed: 18 additions & 0 deletions
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+
?>

Dockerfile

Lines changed: 1 addition & 1 deletion
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

README.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,46 @@ jobs:
4646
define GitHub branch mapping. Only the GitHub branches mapped in `hosts.yml` will be deployed, rest will be filtered
4747
out. Here is a sample [hosts.yml](https://github.com/rtCamp/wordpress-skeleton/blob/main/.github/hosts.yml).
4848

49+
## Inventory file Variables
50+
51+
### Mandatory
52+
53+
| Variable | Default | Possible Values | Purpose |
54+
|---------------|---------|----------------------------------------------------------------|--------------------------------|
55+
| `user` | null | valid username. eg: `root` | Username for ssh. |
56+
| `deploy_path` | null | valid path. eg: `/opt/easyengine/sites/example.com/app/htdocs` | path where action will deploy. |
57+
| `hostname` | null | hostname. eg: `example.com` | hostname for ssh. |
58+
59+
60+
### Optional
61+
62+
| Variable | Default | Possible Values | Description |
63+
|---------------------------------|------------------|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
64+
| `block_emails` | null | true | If set to true, this will enable email blocking functionality. |
65+
| `block_emails_plugin_path` | null | Accept relative path from wp-content directory, eg: `custom-mu-plugins` | If you have set the `MU_PLUGIN_DIR` constant in your wp-config.php file to specify a custom path for mu-plugins, you can use this variable to install Block Emails into your custom mu-plugins directory. |
66+
| `block_emails_plugin_file_name` | 000-block-emails | String without the .php extension. | If you wish to modify the loading position of this plugin within the mu-plugins loading phase. |
67+
| `WP_VERSION` | null | Any valid WordPress version | If you specify a WordPress version, then that speicifc WordPress version will be downloaded, instead of latest WordPress version. **Note:** Please use double quotes while giving value to this variable. This will have higher priority then the one defined in workflow file. |
68+
69+
4970
## Environment Variables
5071

5172
This GitHub action's behavior can be customized using following environment variables:
5273

53-
Variable | Default | Possible Values | Purpose
54-
------------------|---------|---------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
55-
`MU_PLUGINS_URL` | null | vip, any git repo url | If value is `vip`, then action will clone [VIP's MU plugins](https://github.com/Automattic/vip-mu-plugins-public) as `mu-plugins` folder. If you want to specifiy a non-VIP mu-plugins repo, you can provide a publicly accessible mu-plugins repo URL as the value.
56-
`WP_VERSION` | latest | Any valid WordPress version | If you specify a WordPress version, then that speicifc WordPress version will be downloaded, instead of latest WordPress version. **Note:** Please use double quotes while giving value to this variable. Also, `WP_VERSION`, if defined in hosts.yml will have higher priority then the one defined in workflow file.
57-
`WP_MINOR_UPDATE` | null | `true` / `false` | If set to `true`, latest minor version of `WP_VERSION` will be taken.
58-
`JUMPHOST_SERVER` | null | Hostname/IP address of the jumphost server | If the deployment server is not directly accessible, and needs a jumphost, then this method should be used. (Note: The `SSH_PRIVATE_KEY` env variable should have access to the jumphost as well as deployment server for this to work. Also, this method does not work with vault.)
59-
`SUBMODULE_DEPLOY_KEY` | null | Read access deploy key created in the submodule repo's deploy keys. | Only required for privated submodule repo. For now only one private submodule deploy key is allowed. All public submodules in repo will be fetched by default without the need of this env variable. (To create a deploy key go to: Settings > Deploy Keys > Add deploy key)
60-
`SKIP_WP_TASKS` | null | `true`/`false` | If set to `true`, WordPress specific deplyment tasks will skipped.
61-
`PHP_VERSION` | 7.4 | Valid PHP version | Determines the cachetool version compatible to use for purging opcache.
62-
`NPM_VERSION` | null | Valid NPM Version | NPM Version. If not specified, latest version will be used.
63-
`NODE_VERSION` | null | Valid Node Version | If not specified, default version built into action will be used.
64-
`NODE_BUILD_DIRECTORY` | null | path to valid directory on repository. | Build directory. Generally root directory or directory like frontend.
65-
`NODE_BUILD_COMMAND` | null | `npm run build` or similar command. | Command used to to build the dependencies needed on deployment.
66-
`NODE_BUILD_SCRIPT` | null | path to valid shell script | Custom or predefined script to run after compilation.
74+
| Variable | Default | Possible Values | Purpose |
75+
| ------------------ | --------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
76+
| `MU_PLUGINS_URL` | null | vip, any git repo url | If value is `vip`, then action will clone [VIP's MU plugins](https://github.com/Automattic/vip-mu-plugins-public) as `mu-plugins` folder. If you want to specifiy a non-VIP mu-plugins repo, you can provide a publicly accessible mu-plugins repo URL as the value. |
77+
| `WP_VERSION` | latest | Any valid WordPress version | If you specify a WordPress version, then that speicifc WordPress version will be downloaded, instead of latest WordPress version. **Note:** Please use double quotes while giving value to this variable. Also, `WP_VERSION`, if defined in hosts.yml will have higher priority then the one defined in workflow file. |
78+
| `WP_MINOR_UPDATE` | null | `true` / `false` | If set to `true`, latest minor version of `WP_VERSION` will be taken. |
79+
| `JUMPHOST_SERVER` | null | Hostname/IP address of the jumphost server | If the deployment server is not directly accessible, and needs a jumphost, then this method should be used. (Note: The `SSH_PRIVATE_KEY` env variable should have access to the jumphost as well as deployment server for this to work. Also, this method does not work with vault.) |
80+
| `SUBMODULE_DEPLOY_KEY` | null | Read access deploy key created in the submodule repo's deploy keys. | Only required for privated submodule repo. For now only one private submodule deploy key is allowed. All public submodules in repo will be fetched by default without the need of this env variable. (To create a deploy key go to: Settings > Deploy Keys > Add deploy key) |
81+
| `SKIP_WP_TASKS` | null | `true`/`false` | If set to `true`, WordPress specific deplyment tasks will skipped. |
82+
| `PHP_VERSION` | 7.4 | Valid PHP version | Determines the cachetool version compatible to use for purging opcache. |
83+
| `NPM_VERSION` | null | Valid NPM Version | NPM Version. If not specified, latest version will be used. |
84+
| `NODE_VERSION` | null | Valid Node Version | If not specified, default version built into action will be used. |
85+
| `NODE_BUILD_DIRECTORY` | null | path to valid directory on repository. | Build directory. Generally root directory or directory like frontend. |
86+
| `NODE_BUILD_COMMAND` | null | `npm run build` or similar command. | Command used to to build the dependencies needed on deployment. |
87+
| `NODE_BUILD_SCRIPT` | null | path to valid shell script | Custom or predefined script to run after compilation. |
88+
| `BLOCK_EMAILS` | null | true | If set to true, this will enable email blocking functionality. |
6789

6890
All node related variables are completely optional. You can use them if your site needs to have node dependencies built.
6991

main.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,58 @@ 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+
282+
hosts_block_email_dir=$(shyaml get-value "$GITHUB_BRANCH.block_emails_plugin_path" < "$hosts_file" 2>/dev/null || exit 0)
283+
284+
if [[ -n "$hosts_block_email_dir" ]]; then
285+
BLOCK_EMAIL_DIR="$HTDOCS/wp-content/$hosts_block_email_dir"
286+
elif [[ -d "$HTDOCS/wp-content/client-mu-plugins" ]]; then
287+
BLOCK_EMAIL_DIR="$HTDOCS/wp-content/client-mu-plugins"
288+
elif [[ -d "$HTDOCS/wp-content/mu-plugins" ]]; then
289+
BLOCK_EMAIL_DIR="$HTDOCS/wp-content/mu-plugins"
290+
else
291+
BLOCK_EMAIL_DIR="$HTDOCS/wp-content/mu-plugins"
292+
mkdir -p "$BLOCK_EMAIL_DIR"
293+
fi
294+
295+
# remove traling slash
296+
BLOCK_EMAIL_DIR="${BLOCK_EMAIL_DIR%/}"
297+
298+
# using this naming convention by default to load this plugin first in mu-plugin loading phase.
299+
BLOCK_EMAIL_PLUGIN_NAME="000-block-emails.php"
300+
301+
hosts_block_email_file_name=$(shyaml get-value "$GITHUB_BRANCH.block_emails_plugin_file_name" < "$hosts_file" 2>/dev/null || exit 0)
302+
303+
if [[ -n "$hosts_block_email_file_name" ]]; then
304+
BLOCK_EMAIL_PLUGIN_NAME="${hosts_block_email_file_name}.php"
305+
fi
306+
307+
BLOCK_EMAIL_PLUGIN_PATH="$BLOCK_EMAIL_DIR/$BLOCK_EMAIL_PLUGIN_NAME"
308+
309+
if [[ -d "$BLOCK_EMAIL_DIR" ]]; then
310+
rsync -av "/000-block-emails.php" "$BLOCK_EMAIL_PLUGIN_PATH"
311+
echo -e "\033[34mEMAIL BLOCK [ACTIVATED]: $BLOCK_EMAIL_PLUGIN_PATH \033[0m"
312+
else
313+
echo -e "\033[31mEMAIL BLOCK [PATH ERROR]: $BLOCK_EMAIL_DIR doesn't exist.\033[0m"
314+
315+
fi
316+
fi
317+
318+
}
319+
320+
269321
function main() {
270322

271323
init_checks
@@ -279,6 +331,7 @@ function main() {
279331
maybe_run_node_build
280332
maybe_install_submodules
281333
setup_wordpress_files
334+
block_emails
282335
deploy
283336
fi
284337
}

0 commit comments

Comments
 (0)