Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I regularly have guest authors who post one or more articles on a non specific schedule. So I provide them with permanent contributor accounts to avoid the hassle of making them accounts and deleting them every single time. Now this is my problem:

  1. Once they submit an article for review and I publish it, they have the option by default to edit it and make changes accordingly.
  2. They also have the option to delete it.

I am looking for such a feature or way that:

  1. Every time they have to edit a post after it has been published, they have to submit it for review before changes are applied. It doesn't mean the post is taken off the website, the original post stays live on the website but the edit can only be applied after being accepted by an editor or admin.

  2. It can't be deleted or taken offline by the contributor once it has been published or permission is required to delete or take it offline by admin or editor by the contributor.

Can this be achieved? If not, what is closest thing I can do to it to safeguard my information just in case?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
    
thank you so so much ! i will do it right away but which specific guidelines if i may ask . Sorry if this is a noob question. and one more thing the functions.php file is this the one we find in wp-include folder?? –  Danny Dec 29 '12 at 21:55
    
You can find your functions.php file in your theme folder. If there doesn't exist one, you can create a new one and add this code in it. –  Christine Cooper Dec 29 '12 at 22:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.