-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change email notifications to not go to blog admins (#35)
* Add a notice when the min WP version is not met * Add the email fields, just like the webhook fields * Add the messages back in the settings, ensure the email address is read from the new option * Reduce the options * Correct the name of the receptients and add more filters * Tweak the spacing for md files, and tweak the email format * Tweak the email body * Remove unused fields for each module, switch webhook to be async and batch the emails that are sent * Make the settings save code less risky
- Loading branch information
1 parent
ec2a3de
commit 358667d
Showing
8 changed files
with
249 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,18 @@ This plugin is currently developed for use on WordPress sites hosted on [WordPre | |
- [Plugin activation](#plugin-activation) | ||
- [Usage](#usage) | ||
- [Admin](#admin) | ||
- [Notifications](#notifications) | ||
- [Publish Guard](#publish-guard) | ||
- [Editorial Experience](#editorial-experience) | ||
- [Guided Status Movements](#guided-status-movements) | ||
- [Preview Links](#preview-links) | ||
- [Editorial Metadata](#editorial-metadata) | ||
- [Limitations](#limitations) | ||
- [Editorial Metadata](#editorial-metadata-1) | ||
- [Code Filters](#code-filters) | ||
- [`vw_notification_ignored_statuses`](#vw_notification_ignored_statuses) | ||
- [`vw_notification_email_recipients`](#vw_notification_email_recipients) | ||
- [`vw_notification_email_subject`](#vw_notification_email_subject) | ||
- [`vw_notification_email_message`](#vw_notification_email_message) | ||
- [`vw_notification_email_headers`](#vw_notification_email_headers) | ||
- [`vw_notification_send_to_webhook_payload`](#vw_notification_send_to_webhook_payload) | ||
- [`vw_preview_expiration_options`](#vw_preview_expiration_options) | ||
- [Development](#development) | ||
|
@@ -94,10 +97,14 @@ Note that, these statuses are also available in the quick edit experience on the | |
|
||
The plugin doesn't expect any specific configuration, so your first step is to set up statuses that reflect your workflow. You may notice that the steps are listed in a linear order. The plugin assumes a linear workflow where content is moving from creation to publish. | ||
|
||
The plugin also sends notifications when a post's status changes. By default, email notifications are turned on for the blog admin. Additional email recipients can be configured. You can also set up webhook notifications under Admin -> VIP Workflow -> Settings. | ||
|
||
You can also specify which types of content use custom statuses. If a post does not use custom statuses, it will use the standard WordPress publishing flow. | ||
|
||
### Notifications | ||
|
||
VIP Workflow has the ability to send email and/or webhook notifications when a post's status changes. By default, these are off as no email address or webhook is provided out of the box. You set up webhook and/or email notifications under Admin -> VIP Workflow -> Settings. | ||
|
||
Additional filters are available here to customize the notifications that are sent. | ||
|
||
### Publish Guard | ||
|
||
By default, VIP Workflow prevents publishing a post or page (the supported post types are configurable within settings) unless it has reached the last status on your list. This feature can be turned off under settings under the `Publish Guard` option in Admin -> VIP Workflow -> Settings. | ||
|
@@ -130,12 +137,6 @@ Anybody with a preview link (including not logged-in users) will be able to view | |
|
||
VIP Workflow adds a "Editorial Metadata" section to the post sidebar, which allows for additional data to be included with the post such as "Needs Legal Review". This can be managed under the plugin's settings, to get a visual for all of the configured editorial metadata fields. | ||
|
||
## Limitations | ||
|
||
### Editorial Metadata | ||
|
||
If a post is created as a type that supports Editorial Metadata, that metadata will remain even if the post type is modified not to support Editorial Metadata. In other words, once a post is created with Editorial Metadata fields, those fields will remain regardless of configuration changes. | ||
|
||
## Code Filters | ||
|
||
### `vw_notification_ignored_statuses` | ||
|
@@ -165,6 +166,102 @@ add_filter( 'vw_notification_ignored_statuses', function ( $ignored_statuses, $p | |
}, 10, 2 ); | ||
``` | ||
|
||
### `vw_notification_email_recipients` | ||
|
||
Change the recipients that receive an email notification, when the status of a post changes. By default, it is set to the configured email address under Admin -> VIP Workflow -> Settings. | ||
|
||
```php | ||
/** | ||
* Filter the email recipients | ||
* | ||
* @param array $email_recipients Array of email recipients | ||
* @param string $action Action being taken, eg. status-change | ||
* @param WP_Post $post Post object | ||
*/ | ||
apply_filters( 'vw_notification_email_recipients', $email_recipients, $action, $post ); | ||
``` | ||
|
||
For example, this filter can be used to send email notifications to more than just 1 recipients especially for special statuses: | ||
|
||
```php | ||
add_filter( 'vw_notification_email_recipients', function ( $email_recipients, $action, $post ) { | ||
if ( $post->post_status === 'legal-review' ) { | ||
$email_recipients[] = '[email protected]'; | ||
} | ||
|
||
return $email_recipients; | ||
}, 10, 2 ); | ||
``` | ||
|
||
### `vw_notification_email_subject` | ||
|
||
Change the subject of the email that recipients receive, when the status of a post changes. | ||
|
||
```php | ||
/** | ||
* Filter the email subject | ||
* | ||
* @param string $subject Subject of the email | ||
* @param string $action Action being taken, eg. status-change | ||
* @param WP_Post $post Post object | ||
*/ | ||
apply_filters( 'vw_notification_email_subject', $subject, $action, $post ); | ||
``` | ||
|
||
For example, this filter can be used to set a standardized subject regardless of what the status is: | ||
|
||
```php | ||
add_filter( 'vw_notification_email_subject', function ( $subject, $action, $post ) { | ||
return __( 'Content Status Update' ); | ||
}, 10, 2 ); | ||
``` | ||
|
||
### `vw_notification_email_message` | ||
|
||
Change the message of the email that recipients receive, when the status of a post changes. | ||
|
||
```php | ||
/** | ||
* Filter the email message | ||
* | ||
* @param string $message Body of the email | ||
* @param string $action Action being taken, eg. status-change | ||
* @param WP_Post $post Post object | ||
*/ | ||
apply_filters( 'vw_notification_email_message', $message, $action, $post ); | ||
``` | ||
|
||
For example, this filter can be used to replace the signature that the plugin adds to the footer of the email with a company one instead: | ||
|
||
```php | ||
add_filter( 'vw_notification_email_message', function ( $message, $action, $post ) { | ||
return str_replace( 'You are receiving this email because a notification was configured via the VIP Workflow Plugin.', 'You are receiving this email as part of ACME Corp.', $message); | ||
}, 10, 2 ); | ||
``` | ||
|
||
### `vw_notification_email_headers` | ||
|
||
Change the headers used for the email that recipients receive, when the status of a post changes. By default, they are the standard headers set by wp_mail. | ||
|
||
```php | ||
/** | ||
* Filter the email recipients | ||
* | ||
* @param array $message_headers Message headers | ||
* @param string $action Action being taken, eg. status-change | ||
* @param WP_Post $post Post object | ||
*/ | ||
apply_filters( 'vw_notification_email_headers', $message_headers, $post ); | ||
``` | ||
|
||
For example, this filter can be used to send HTML formatted email notifications instead of the default plain text formatted email notifications: | ||
|
||
```php | ||
add_filter( 'vw_notification_email_headers', function ( $message_headers, $action, $post ) { | ||
return [ 'Content-Type: text/html; charset=UTF-8' ]; | ||
}, 10, 2 ); | ||
``` | ||
|
||
### `vw_notification_send_to_webhook_payload` | ||
|
||
Change the payload sent to the webhook, when the status of a post changes. By default, it is as follows: | ||
|
@@ -182,22 +279,19 @@ Change the payload sent to the webhook, when the status of a post changes. By de | |
* Filter the payload before sending it to the webhook | ||
* | ||
* @param array $payload Payload to be sent to the webhook | ||
* @param string $action Action being taken | ||
* @param WP_User $user User who is taking the action | ||
* @param WP_Post $post Post that the action is being taken on | ||
*/ | ||
|
||
apply_filters( 'vw_notification_send_to_webhook_payload', $payload, $action, $user, $post ); | ||
apply_filters( 'vw_notification_send_to_webhook_payload', $payload ); | ||
``` | ||
|
||
For example, this filter can be used to customize the payload so that it's compatible with Slack's [incoming webhooks](https://api.slack.com/messaging/webhooks): | ||
|
||
```php | ||
add_filter( 'vw_notification_send_to_webhook_payload', function ( $payload, $action, $user, $post ) { | ||
add_filter( 'vw_notification_send_to_webhook_payload', function ( $payload ) { | ||
return [ | ||
'text' => $payload['data'], | ||
]; | ||
}, 10, 4 ); | ||
}, 10, 1 ); | ||
``` | ||
|
||
### `vw_preview_expiration_options` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.