最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - Sending current featured image to email

programmeradmin0浏览0评论

I am trying to send the featured image with other details by email to admin. Everything is working well except that the featured image is sent to email only when the post is edited from admin. If edited from frontend all the details are sent except the image.

I don't know why.

Here's the code:

// send email on creation or update of a campaign
 add_action( 'save_post', 'campaign_updated_send_email' );
 function campaign_updated_send_email( $post_id ) { 
    //check post type is product
    $ptype = get_post_type( $post_id );
    if ( $ptype === 'product') {
    //verify campaign/product is not a revision 
    if ( !wp_is_post_revision( $post_id ) ) { 
         $post_title = get_the_title( $post_id ); 
         $post_url = get_permalink( $post_id ); 
         
    //get the post status
    $mypoststatus = get_post_status( $post_id );
    // get the campaign image
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $loop->post->ID ), 'single-post-thumbnail' );




         $subject = '[Campaign updated:]'.$post_title; 
         $message = "A campaign has been updated2:\n\n";


        $message = "<a href='". $post_url. "'><img src=".$image[0]." width=250></a>\n\n";
         $message .= "<br><a href='". $post_url. "'><h3>" .$post_title. "</h3></a><h3>Current Status:<U>".$mypoststatus."</U></h3>\n\n"; 
        $headers = array('Content-Type: text/html; charset=UTF-8');
         //send email to admin 
         wp_mail( get_option( 'admin_email' ), $subject, $message, $headers); 
   } 
}
} 
发布评论

评论列表(0)

  1. 暂无评论