WordPress: inviare delle notifiche via e-mail quando un custom post type viene modificato

WordPress: inviare delle notifiche via e-mail quando un custom post type viene modificato

In WordPress possiamo inviare delle notifiche via e-mail quando un custom post type viene modificato.

La soluzione รจ la seguente:


function my_notify_update( $post_id, $post, $update ) {
    $post_type = get_post_type( $post_id );
    if( 'my_custom_post_type' != $post_type ) {
        return;
    }
    $to = get_bloginfo( 'admin_email' );
    $subject = __( 'Post updated', 'mytextdomain' );
    $message = __( get_the_title( $post_id ) . ' has been updated', 'mytextdomain' );
    $headers = array();
    $headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <wordpress@imydomain.tld>';
    wp_mail( $to, $subject, $message, $headers );
}

add_action( 'save_post', 'my_notify_update', 10, 3 );

Torna su