How to change 'Move to Trash' to 'Move to Draft' for my blog's users?

I want that only Admin and Editor roles can use the 'Move to Trash' option in my blog, and other users will ge

I want that only Admin and Editor roles can use the 'Move to Trash' option in my blog, and other users will get the 'Move to Draft' option instead.

Like inside of the 'Quick Edit' / 'Bulk Actions' options in All posts of the Dashboard, and the Post editor side bar:

I want that only Admin and Editor roles can use the 'Move to Trash' option in my blog, and other users will get the 'Move to Draft' option instead.

Like inside of the 'Quick Edit' / 'Bulk Actions' options in All posts of the Dashboard, and the Post editor side bar:

Share Improve this question edited Sep 23, 2015 at 17:02 Gabriel 2,24810 gold badges22 silver badges24 bronze badges asked Sep 23, 2015 at 15:32 Muklesur RahamanMuklesur Rahaman 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

You can use add_filter() for post_row_actions to filter out the ones you don't want, add in the functions you do want. Like so:

<?php
/** Plugin Name: (wpse) Draft vs. Trash Posts */
add_filter( 'post_row_actions', 'my_plugin_update_actions', 10, 2 );
function my_plugin_update_actions($actions, $post) {

    $capability = 'promote_users';
    $role = 'Administrator';
    // Choose what you want to check against. Better only use one: Capability *or* role.
    if (
        current_user_can( $capability )
        OR current_user_has_role( $role )
    ) {
        unset($actions['trash']);
        $actions['draft'] = '<a class="submitdelete" title="Move this item to drafts" href="'.admin_url('post.php?post='.$post->ID.'&action=draft').'">Move To Draft</a>';
    }

    return $actions;
}

That should get you started in the right direction.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744783882a4593504.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信