提交以供审阅返回到草稿页

时间:2015-11-30 作者:user3166179

我想允许WordPress投稿人将提交审查的草稿页更改回草稿页,而不允许投稿人发布页面。我尝试过但没有成功:

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 );
}
任何帮助都将不胜感激。

1 个回复
SO网友:TheDeadMedic

这不是权限问题-贡献者可以(默认情况下)将帖子从挂起更改为草稿。要进行测试,请提交一篇文章供审阅,然后“快速编辑”它-您将看到您可以将状态更改回草稿。

问题是,一旦提交帖子供审阅,UI中的“另存为草稿”按钮就会被隐藏-让我们“还原”它:

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\' );

相关推荐