gravitysmtp_managed_email_types

Description

The gravitysmtp_managed_email_types allows developers to modify or extend the list of managed email types by adding their own custom types.

Usage

add_filter( 'gravitysmtp_managed_email_types', 'your_function_name', 10, 1 );

Parameters

  • $email_types array
    An array of objects, each representing a managed email type.
ComponentsDescription
keyIt should be a unique slug for this email type. The slug doesn’t have any specific requirements except that it must be unique amongst the registered email types.
labelA short, descriptive label for this email type that will be displayed on the Email Management screen.
categoryA human-readable string that defines which category this email type belongs to. The category value is a group header within the Email Management screen.
descriptionA string of detailed information about what this email type is, the recipient(s), and which actions trigger the email. The description is displayed under the email label on the Email Management screen.
disable_callbackMust be a callable method. This is the method that is fired when this email is blocked. The callback should be whatever functionality is required to effectively stop the email from sending. Note: For WordPress Core emails, this is typically done by removing an action or returning false on a filter. The actual callback will vary based on the email type being handled.

Examples

Register Custom Managed Emails.

add_filter( 'gravitysmtp_managed_email_types', function ( $email_types ) {
        $custom_emails = [
            [
                'key' => 'new_user_welcome_email',
                'label' => 'New User Welcome Email',
                'category' => 'Custom Email Notifications',
                'description' => 'Sent to new users upon successful registration.',
                'filter' => 'wp_new_user_notification_email',
            ],
            [
                'key' => 'comment_moderation_email',
                'label' => 'Comment Moderation Email',
                'category' => 'Custom Email Notifications',
                'description' => 'Sent to site moderators when a comment is held for moderation.',
                'filter' => 'notify_moderator',
            ],
        ];

        foreach ( $custom_emails as $email ) {
            $email_types[] = new \Gravity_Forms\Gravity_SMTP\Email_Management\Managed_Email(
                key: $email['key'],
                label: $email['label'],
                category: $email['category'],
                description: $email['description'],
                disable_callback: function () use ( $email ) {
                    add_filter( $email['filter'], '__return_false' );
                }
            );
        }

    return $email_types;
}, 10, 1 );
Image showing Custom Email Notifications

Since

This filter was added in Gravity SMTP 1.3

Source Code

This filter is located in class Email_Stopper in /class-email-stopper.php.