这个wp_update_post
钩子将调用同一操作两次,作为save_post_{$post->post_type}
在此函数中调用。我想补充一下remove_action( \'save_post_tribe_events\', \'set_to_pending\');
之前wp_update_post( $post );
和add_action( \'save_post_tribe_events\', \'set_to_pending\', 10, 3 );
工作后:)
function set_to_pending($id, $post, $update){
$the_post = print_r($post, true);
$the_post_author = $post->post_author;
$the_post_url = get_edit_post_link($id);
$the_post_url = wp_specialchars_decode($the_post_url);
if($the_post_author ==1 || $the_post_author == 2) {
} else {
if (defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE ) {
return;
}
if (wp_is_post_revision($id)) {
return;
}
if (wp_is_post_autosave($id)) {
return;
}
// if new post
if (!$update) {
return;
}
if($post->post_status == \'trash\') {
return;
}
$post->post_status = \'pending\';
remove_action( \'save_post_tribe_events\', \'set_to_pending\');
wp_update_post( $post );
$times = did_action(\'save_post_tribe_events\');
if( $times === 1){
wp_mail(\'[email protected]\', \'Pending Event\', $the_post_url);
}
//Add action here to prevent sending mail twice
add_action( \'save_post_tribe_events\', \'set_to_pending\', 10, 3 );
}
}
add_action( \'save_post_tribe_events\', \'set_to_pending\', 10, 3 );