Claim Listing functionality – how to send email to users when their claim has been approved or denied

Unfortunately, the developers didn’t give you any hooks in their code to allow for customization without hacking it. But all is not lost – there are some hooks in WP that you could use to trigger your emails.

The ideal would be to trigger off the update_post_meta(). That function is simply a wrapper for update_metadata() which has lots of hooks in it.

Here’s an untested example of a direction you could go. Hopefully it gives you something to work off of.

/**
 * @param int    $meta_id    ID of updated metadata entry.
 * @param int    $object_id  Post ID.
 * @param string $meta_key   Meta key.
 * @param mixed  $meta_value Meta value. This will be a PHP-serialized string representation of the value if
 *                           the value is an array, an object, or itself a PHP-serialized string.
 */
add_action( 'updated_postmeta', function( $meta_id, $object_id, $meta_key, $meta_value ) {
    if ( 'ait-claim-listing' == $meta_key ) {
        if ( 'approved' == $meta_value['status'] ) {
            $email_to = $meta_value['owner'];
            $subject="Your approved email subject";
            $message="Your approved email message...";
        }

        if ( 'unclaimed' == $meta_value['status'] ) {
            $email_to = $meta_value['author'];
            $subject="Your unclaimed email subject";
            $message="Your unclaimed email message...";
        }

        $result = wp_mail( $email_to, $subject, $message );
    }
}, 10, 4 );

Keep in mind, this is untested and just a thought process based on the information in your question. You may need to make some adjustments to make it really work.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)