Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8705599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:24:14+00:00 2026-06-13T03:24:14+00:00

In WordPress, how can I restrict users (based on Capabilities ) from editing their

  • 0

In WordPress, how can I restrict users (based on Capabilities) from editing their published posts after a custom amount of time.

For instance, a user that can publish_posts (authors) can not edit a their post if it is older than 3 days, and a user that can moderate_comments (editors) can not edit any posts that are older than 20 days. Obviously, admins can edit anytime.

How is such thing possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:24:15+00:00Added an answer on June 13, 2026 at 3:24 am

    This is the duplicate of a question on wordpress.stackexchange.com. I’ve copied my answer below.

    I took the example code from the WordPress user_has_cap filter codex page and modified it. Add this code to your theme functions.php:

    function restrict_editing_old_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;
    
      $post_date = strtotime( $post->post_date );
      //if post is older than 30 days ... 
      if( $post_date < strtotime( '-30 days' )
        // ... or if older than 4 days and user is not Editor
        || ( empty($allcaps['moderate_comments']) 
        && $post_date < strtotime('-4 days') ) ) {
          $allcaps[$cap[0]] = FALSE;  
      }
      return $allcaps;
    }
    add_filter( 'user_has_cap', 'restrict_editing_old_posts', 10, 3 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Querying wordpress posts according to their tags can look like this (if I pieced
How can I restrict access to a specific Wordpress page based on the user's
I want in my wordpress website that user can log in through their facebook
How can i use my own (custom) session value inside wordpress? For example: $_SESSION['myname']=4lvin
I'm trying to get the captions from images in Wordpress but I can't find
The question is quite simple : How can I restrict unregistered users to post
I'm aware that the wordpress API can be used to make posts to wordpress
I modified the code published on smbrown.wordpress.com which can extract the top tracks using
I want to make new custom page in wordpress where I can communicate with
How can add image in wordpress custom post? please any one help me.... Thanks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.