I would like to allow a WordPress contributor to change a draft page Submitted for Review back to a draft page without giving the contributor the capability to publish pages. I have tried without success:
function post_pending ( $new_status, $old_status, $page ) {
if ( $old_status == 'draft' && $new_status != 'pending' ) {
edit_post_link();
}
}
if ( current_user_can( 'contributor' ) ) {
add_action( 'transition_post_status', 'post_pending', 10, 3 );
}
Any help would be appreciated.
I would like to allow a WordPress contributor to change a draft page Submitted for Review back to a draft page without giving the contributor the capability to publish pages. I have tried without success:
function post_pending ( $new_status, $old_status, $page ) {
if ( $old_status == 'draft' && $new_status != 'pending' ) {
edit_post_link();
}
}
if ( current_user_can( 'contributor' ) ) {
add_action( 'transition_post_status', 'post_pending', 10, 3 );
}
Any help would be appreciated.
Share Improve this question edited Nov 30, 2015 at 7:04 Mayeenul Islam 12.9k21 gold badges85 silver badges169 bronze badges asked Nov 30, 2015 at 1:58 user3166179user3166179 12 bronze badges 1- I just wanted to pop in and say that as of Wordpress 4.9 this solution still works. – Stephen Petrey Commented Dec 7, 2017 at 20:19
1 Answer
Reset to default 1This is not a permissions issue - contributors can (by default) change a post from pending to draft. To test, submit a post for review, then "quick edit" it - you'll see that you're able to change the status back to draft.
The issue is that the "save as draft" button in the UI is hidden once a post is submitted for review - let's "restore" it:
function wpse_210259_revert_to_draft_button() {
global $post;
$post_type = get_post_type_object( $post->post_type );
if ( $post->post_status === 'pending' && ! current_user_can( $post_type->cap->publish_posts ) ) {
printf(
/**
* Since there are no hooks where the original "Save Draft" button
* appears, use CSS positioning to "fake" it to give the user a
* consistent UI.
*/
'<button style="position: absolute; top: 10px; left: 10px;" class="button" type="submit" name="post_status" value="draft">%s</button>',
__( 'Save as Draft' )
);
}
}
add_action( 'post_submitbox_misc_actions', 'wpse_210259_revert_to_draft_button' );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745255718a4618942.html
评论列表(0条)