Reapproval for edits and deletion after post is published

Let us solve this by going with your second option. So you want to restrict users from editing published posts, this can be done by adding this to your theme’s functions.php file (please read the comments that is added):

    function restrict_editing_old_posts( $allcaps, $cap, $args ) { // Restrict users from editing post based on the age of post

// Bail out if we're not asking to edit or delete a post ...
if( ( 'edit_post' != $args[0] && 'delete_post' != $args[0] )
  // ... or user is admin 
  || ! empty( $allcaps['manage_options'] )
  // ... or user already cannot edit the post
  || empty( $allcaps['edit_posts'] ) )
    return $allcaps;

// Load the post data:
$post = get_post( $args[2] );

// Bail out if the post isn't published:
if( 'publish' != $post->post_status )
    return $allcaps;

$post_date = strtotime( $post->post_date );
//if post is older than 10 days ...
if( $post_date < strtotime( '-10 days' )
  // ... or if older than 1 days and user is not Editor
  || ( empty($allcaps['moderate_comments']) && $post_date < strtotime('-1 days') ) ) {
    $allcaps[$cap[0]] = FALSE;
}
return $allcaps;
}
add_filter( 'user_has_cap', 'restrict_editing_old_posts', 10, 3 );

With the above code, you will:

  • Restrict none-editors from removing published posts that are older than 1 day.
  • Restrist editors from removing published posts that are older than 10 days.

Then just to improve the interface, you may want to remove the Trash links. You can do this by adding this code:

// START access to Trash folder where users can delete posts permanently
function remove_trash_link( $views ) 
{
    if( !current_user_can( 'manage_options' ) )
        unset( $views['trash'] );

    return $views;
}

function block_trash_access()
{
    global $current_screen;

    if( 
        'post' != $current_screen->post_type 
        || 'trash' != $_GET['post_status'] 
    )
        return;

    if( !current_user_can( 'manage_options' ) )
    {
        wp_redirect( admin_url() . 'edit.php' ); 
        exit;
    }
}

add_filter( 'views_edit-post', 'remove_trash_link' );
add_action( 'admin_head-edit.php', 'block_trash_access' );
// END access to Trash folder

That should cover your question. As a request, please format your question accordingly to the guidelines to allow other users reading and finding it.

Leave a Comment