我正在使用一个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);