クイック編集からedit_postを使ってメール送信
-
クイック編集からedit_postを使ってタクソノミーを変更後、
更新ボタンからカテゴリー変更後の情報をメールのsubjectに入れて送信させようとしています。
adbance custom field(ACF)を使用してあるデータも付いていきます。そのままではカテゴリー情報はメールに渡らないので(add_action wp_insert_pos,,,t)で取得して送信させています。
クイック編集の更新はedit_postなので (add_action edit_post,,,)も使用しています。(add_action acf/save_post,,,の3つ使って送信しようとしていますが、ちゃんとsubjectに渡り送信されるのですが、2重送信になってしまいもう一つのメールはタイトルにタクソノミーが入っていない状態のメールが送られてきます。
ご教授いただけないでしょうか?
以下実際のコードです。add_action( ‘acf/save_post’, ‘updated_send_email’, 1 );
add_action(‘wp_insert_post’, ‘updated_send_email’,10,1);
add_action(‘edit_post’, ‘updated_send_email’,10,1);function updated_send_email( $post_id ) {
//最新応対のカテゴリー取得
$arg =array(
‘cat_name’ => $new_cat_name,
‘category_nicename’ => $slug,
‘category_parent’ => $parent_id,
‘taxonomy’ => ‘category’
);
$new_category_id = wp_insert_category($arg);
delete_option(“category_children”);// If this is just a revision, don’t send the email.
if ( wp_is_post_revision( $post_id ))
return;
else if ( wp_publish_post( $post_id ));$adminurl = get_edit_post_link( $id, $context );
global $post;
$defaultmess = get_post_meta($post->ID,’defaultmess’,true);$postid = get_the_ID();
$cat = get_the_category(); $cat = $cat[0];
$category =$cat->cat_name;
$product_terms = wp_get_object_terms($post->ID, ‘status’);//タームを出力
if(!empty($product_terms)){
if(!is_wp_error( $product_terms )){
foreach($product_terms as $term){
$categorystatus = $term->name;
}
}
}$statusdiscription = $term->description;
$subject = “依頼ID:{$postid}”.”_{$category}”.”/{$categorystatus}”;$post = get_post($post_id);
if ($post){
$author = get_userdata($post->post_author);
$user_email = $author->user_email;
}// radio
$field = get_field_object(‘radiocheck’);
$value = get_field(‘radiocheck’);
$label = $field[‘choices’][ $value ];$mail_address = array(‘××××@××××××.jp’, $ccaddress, $user_email);
$shinki =<<<EOS
お知らせ
{$category}
{$statusdiscription}
{$defaultmess}
———————————本文:{$maintextarea}
タグ:{$option_tag_tag}作業依頼内容URL
編集画面:{$adminurl}
IDとPASSが必要です。
EOS;
wp_mail( $mail_address, $subject, $shinki);remove_action( ‘acf/save_post’, ‘updated_send_email’, 1 );
remove_action(‘wp_insert_post’, ‘updated_send_email’,10,1);
remove_action(‘edit_post’, ‘updated_send_email’,10,1);
}
- トピック「クイック編集からedit_postを使ってメール送信」には新たに返信することはできません。