「レビュー待ちとして送信」実行時に管理者にメールをする
-
カスタム投稿タイプにて寄稿者が「レビュー待ちとして送信」を実行した際に管理者にお知らせメールを送信する
ということがしたいです。function mail_for_pending( $new_status, $old_status, $post ) { if ($old_status != 'pending' && $new_status == 'pending') { // ブログ名(サイト名) $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // 投稿名 $post_title = wp_specialchars_decode($post->post_title, ENT_QUOTES); //メッセージ $message_send = wp_specialchars_decode(get_field('message',$post->ID), ENT_QUOTES); // 送信先(管理者) $to = get_option('admin_email'); // 件名 $subject = "[{$blogname}] 承認待ちの投稿が投稿されました({$post_title})"; // 本文 $message = "{$authorName}様より\r\n"; $message .= "\r\n"; $message .= "{$post_type}\r\n"; $message .= "「{$post_title}」が投稿されました。確認をお願いします。\r\n"; $message .= "\r\n"; if ($message_send != '') { $message .= "メッセージ:\r\n"; $message .= "{$message_send}\r\n"; $message .= "\r\n"; } $message .= "編集および公開: \r\n"; $message .= wp_specialchars_decode(get_edit_post_link( $post->ID ), ENT_QUOTES) . "\r\n"; // メールを送信 $r = wp_mail( $to, $subject, $message ); } } add_action( 'transition_post_status', 'mail_for_pending', 10, 3 );
上記コードではカスタムフィールドの「message」の値が保存前の状態のものが送信されてしまいます。
ですのでfunction mail_for_pending( $new_status, $old_status, $post ) { if ($old_status != 'pending' && $new_status == 'pending') { // 投稿の更新 do_action("save_post_{$post->post_type}", $post->ID); // ブログ名(サイト名) $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // 投稿名 $post_title = wp_specialchars_decode($post->post_title, ENT_QUOTES); //メッセージ $message_send = wp_specialchars_decode(get_field('message',$post->ID), ENT_QUOTES); // 送信先(管理者) $to = get_option('admin_email'); // 件名 $subject = "[{$blogname}] 承認待ちの投稿が投稿されました({$post_title})"; // 本文 $message = "{$authorName}様より\r\n"; $message .= "\r\n"; $message .= "{$post_type}\r\n"; $message .= "「{$post_title}」が投稿されました。確認をお願いします。\r\n"; $message .= "\r\n"; if ($message_send != '') { $message .= "メッセージ:\r\n"; $message .= "{$message_send}\r\n"; $message .= "\r\n"; } $message .= "編集および公開: \r\n"; $message .= wp_specialchars_decode(get_edit_post_link( $post->ID ), ENT_QUOTES) . "\r\n"; // メールを送信 $r = wp_mail( $to, $subject, $message ); } } add_action( 'transition_post_status', 'mail_for_pending', 10, 3 );
「do_action(“save_post_{$post->post_type}”, $post->ID);」
上記コードを追加したのですが、どうも状況は変わらずといった感じです。
やろうとしていることは可能なのでしょうか?
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
- トピック「「レビュー待ちとして送信」実行時に管理者にメールをする」には新たに返信することはできません。