post status - Submitted for Review back to a Draft page

I would like to allow a WordPress contributor to change a draft page Submitted for Review back to a draft page without g

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
Add a comment  | 

1 Answer 1

Reset to default 1

This 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

相关推荐

  • post status - Submitted for Review back to a Draft page

    I would like to allow a WordPress contributor to change a draft page Submitted for Review back to a draft page without g

    4小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信