Skip to content

Commit

Permalink
Change email notifications to not go to blog admins (#35)
Browse files Browse the repository at this point in the history
* 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
ingeniumed authored Sep 18, 2024
1 parent ec2a3de commit 358667d
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 245 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ indent_size = 2

[*.md]
trim_trailing_whitespace = false
indent_size = 2
indent_style = space

[*.txt]
end_of_line = crlf
126 changes: 110 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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:
Expand All @@ -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`
Expand Down
11 changes: 0 additions & 11 deletions class-workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,12 @@ public function action_admin_init() {
* Register a new module
*/
public function register_module( $name, $args = [] ) {

// A title and name is required for every module
if ( ! isset( $args['title'], $name ) ) {
return false;
}

$defaults = [
'title' => '',
'short_description' => '',
'extended_description' => '',
'slug' => '',
'post_type_support' => '',
'default_options' => [],
'options' => false,
'configure_page_cb' => false,
'configure_link_text' => __( 'Configure', 'vip-workflow' ),
'autoload' => true, // autoloading a module will remove the ability to enable or disable it
];
if ( isset( $args['messages'] ) ) {
$args['messages'] = array_merge( (array) $args['messages'], $defaults['messages'] );
Expand Down
1 change: 0 additions & 1 deletion modules/custom-status/custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function __construct() {
$this->module_url = $this->get_module_url( __FILE__ );
// Register the module with VIP Workflow
$args = [
'title' => __( 'Workflow Config', 'vip-workflow' ),
'module_url' => $this->module_url,
'slug' => 'custom-status',
'configure_page_cb' => 'print_configure_view',
Expand Down
Loading

0 comments on commit 358667d

Please sign in to comment.