我使用transition_post_status
挂钩来更改private to publish
的帖子状态。这里的问题是当管理员将帖子状态从私有更改为发布时,帖子作者会进行更改。
我制作了自定义帖子类型abc
并通过前端添加了内容。我默认将状态设置为私有。因此管理员可以从私人更改为发布。因为我在functions.php中使用了钩子。
这是我用过的代码
function _transition_post_status_1($new_status, $old_status, $post) {
global $wpdb;
if ( $old_status == 'private' && $new_status == 'publish' ) {
// Reset GUID if transitioning to publish and it is empty
$post_idd = $post->ID;
$post_7 = get_post($post_idd);
$post_athr = $post_7->post_author;
$auth_maill = get_the_author_meta( 'user_email', $post_athr );
if ( '' == get_the_guid($post->ID) ) {
$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) );
wp_mail($auth_maill,"Confirmation Email","Your Artist Campaign has been approved.");
do_action('private_to_published', $post->ID); // Deprecated, use private_to_publish
}
}
add_action( 'transition_post_status','_transition_post_status_1',5, 3);