• I am a scientist trying to set up a WordPress multisite to use as my group’s laboratory notebooks. I would like to make people’s entries editable by the author for a limited period of time so that they can regularly save them while they are writing the posts to begin with, but make each post permanent and unchangeable after some specified time period, like 3 days (remember how you always have to write in ink, not erasable pencil, in a lab notebook?)

    I could do this by changing the post author to admin after a specified time period, but 1) I’m not sure how to schedule this and 2) I want to retain the original information about who authored the post.

    Does anyone have ideas about how to do this? Could custom post types or some gymnastics with user roles help? Thanks in advance for any input!

Viewing 1 replies (of 1 total)
  • Untested but try putting this in your theme’s functions.php (or even better a functionality plugin):

    function restrict_editing_published_posts( $allcaps, $cap, $args ) {
    
        // Bail out if we're not asking to edit a post ...
        if( 'edit_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;
    
        //if post is older than a day ...
        if( strtotime( $post->post_date ) < strtotime( '-1 day' ) ) {
            //Then disallow editing.
            $allcaps[$cap[0]] = FALSE;
        }
        return $allcaps;
    }
    add_filter( 'user_has_cap', 'restrict_editing_published_posts', 10, 3 );

    Taken from this post.

    Tweak the -1 day to suit your needs.

Viewing 1 replies (of 1 total)
  • The topic ‘Prevent editing of posts after 3 days’ is closed to new replies.