寄稿者が投稿を作成したら、編集者へメール通知したい
-
寄稿者が投稿を作成したら、編集者へメール通知したいのですが、うまくいきません。
導入したいサイトが2サイトあり、1つはうまくいきました。
そのfunction.phpに記載したものをコピペしてきたのですが、できませんでした。そもそも、うまくいった方は、投稿画面でボタンが「公開」になっており、
押すと「編集者へ通知します」のようなメッセージが出ます。うまくいっていない方は、ボタンが「レビュー待ちで送信」になっており、
押すと下書き保存にはなりますが、メール通知はされません。どちらもプラグインは使用せず、function.phpのみです。
ご教授お願い致します。/* 寄稿ががメディアアップできる&他ユーザーの画像は非表示 --------------------------------------- */ if ( current_user_can('contributor') && !current_user_can('upload_files') ){ add_action('admin_init', 'allow_contributor_uploads'); } function allow_contributor_uploads() { $contributor = get_role('contributor'); $contributor->add_cap('upload_files'); } function display_only_self_uploaded_medias( $query ) { if ( $user = wp_get_current_user() ) { $query['author'] = $user->ID; } return $query; } add_action( 'ajax_query_attachments_args', 'display_only_self_uploaded_medias' ); /* 寄稿が記事を書いたら編集者へメール --------------------------------------- */ function adminmail_pending( $new_status, $old_status, $post ) { if ( $old_status != 'pending' && $new_status == 'pending' ) { $blogname = get_option('blogname'); $post_title = $post->post_title; $subject = $blogname." にて承認待ちの記事が投稿されています(".$post_title.")"; $message = "記事".$post_title."が承認待ちです。\r\n"; $message .= "\r\n"; $message .= "記事の承認URLは下記となります: \r\n"; $message .= wp_specialchars_decode(get_edit_post_link( $post->ID ), ENT_QUOTES) . "\r\n"; //編集者のメールアドレスを取得し編集者全員にメールを送ります $args= array('role' => 'editor'); $users= get_users($args); $editor_mails=array(); if(sizeof($users)>0){ foreach($users as $user){ $mail= esc_html($user->user_email); array_push($editor_mails,$mail); } } if(sizeof($editor_mails)>0){ for($i=0; $i<sizeof($editor_mails); $i++){ $to = $editor_mails[$i]; $r = wp_mail( $to, $subject, $message ); } } } } add_action( 'transition_post_status', 'adminmail_pending', 10, 3 );
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
- トピック「寄稿者が投稿を作成したら、編集者へメール通知したい」には新たに返信することはできません。