因此,我管理着一个由大约15名贡献者和5名编辑组成的博客。我想实现一个系统,每次投稿人点击“提交审核”按钮时,都会向编辑发送电子邮件进行校对。我策划了一个动作,但它似乎是在“编辑帖子”时间触发的,而不是在“提交”时间触发的。
我的解决方法是检查帖子的状态,只发送“待定”的电子邮件,但在他们点击提交之前,状态仍然是“草稿”。。。这意味着它只在他们点击submit for review的那一刻起作用。
这是我到目前为止的片段。请帮忙!
function submit_send_email() {
global $post;
if ( current_user_can(\'contributor\') && $post->post_status == \'pending\' ) {
$user_info = get_userdata ($post->post_author);
$strTo = array (\'[email protected]\');
$strSubject = \'Fstoppers: \' . $user_info->user_nicename . \' submitted a post\';
$strMessage = \'"\' . $post->post_title . \'" by \' . $user_info->user_nicename . \' was submitted a post for review at \' . wp_get_shortlink ($post->ID) . \'&preview=true. Please proof.\';
wp_mail( $strTo, $strSubject, $strMessage );
}
}
add_action(\'edit_post\',\'submit_send_email\');
更新:我尝试设置弗兰肯斯坦,让我的行动计划在15秒后运行,没有骰子。
function submit_send_email ($post) {
if ( $post->post_status == \'pending\' ) {
$user_info = get_userdata ($post->post_author);
$strTo = array (\'[email protected]\');
$strSubject = \'Fstoppers: \' . $user_info->user_nicename . \' submitted a post\';
$strMessage = \'"\' . $post->post_title . \'" by \' . $user_info->user_nicename . \' was submitted a post for review at \' . wp_get_shortlink ($post->ID) . \'&preview=true. Please proof.\';
wp_mail( $strTo, $strSubject, $strMessage );
}
}
function submit_for_review() {
global $post;
if ( current_user_can(\'contributor\') ) {
wp_schedule_single_event( time() + 15, \'submit_send_email_event\', $post );
}
}
add_action(\'submit_send_email_event\',\'submit_send_email\', 10, 1);
add_action(\'save_post\',\'submit_for_review\');
最合适的回答,由SO网友:gmazzap 整理而成
你需要Post Status Transitions 行动
function notify_me_for_pending( $post ) {
$user_info = get_userdata ($post->post_author);
$strTo = array (\'[email protected]\');
$strSubject = \'Fstoppers: \' . $user_info->user_nicename . \' submitted a post\';
$strMessage = \'"\' . $post->post_title . \'" by \' . $user_info->user_nicename . \' was submitted a post for review at \' . wp_get_shortlink ($post->ID) . \'&preview=true. Please proof.\';
wp_mail( $strTo, $strSubject, $strMessage );
}
add_action( \'draft_to_pending\', \'notify_me_for_pending\' );
add_action( \'auto-draft_to_pending\', \'notify_me_for_pending\' );
SO网友:TomC
我也遇到了类似的情况,我想出的丑陋方法是创建一个包含以下内容的文件:
require(\'/path/to/yourdomain.com/httpdocs/wp-blog-header.php\');
global $wpdb;
// Search for posts by Contributors then email the editors
$today = date(\'Y-m-d\');
$two_days_ago = date(\'Y-m-d\', strtotime("-1 days"));
// Select draft posts but don\'t include Site Admin/Editors to reduce un-necessary emails and also if they\'re in there for more than x days, assume that there\'s a reason that they\'re not published and ignore
$sql = "SELECT * FROM `wp_posts` WHERE `post_author` !=4 AND `post_author` !=1 AND `post_author` !=7 AND `post_author` !=10 AND `post_author` !=11 AND `post_author` !=12 AND `post_status` = \'pending\' AND `post_modified` > \'$two_days_ago\' ";
$result = $wpdb->get_results($sql);
if ($wpdb->num_rows > 0) {
$message_text = $wpdb->num_rows . " draft posts(s) for review. Please review here: http://yourdomain.com/wp-admin/edit.php?post_status=pending&post_type=post&orderby=date&order=desc";
$headers = \'From: Site Admin <[email protected]>\' . "\\r\\n";
wp_mail(\'[email protected]\', \'Site Admin: Draft Posts awaiting approval\', $message_text, $headers);
echo $wpdb->num_rows . " draft post(s) for approval";
} else {
echo " No posts for approval<br>";
}
然后我每隔30分钟运行一次cron,看看是否有新帖子。(我还有其他各种维护脚本在这里运行,等等)
我想这可能对你有帮助。