Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chuckreynolds
Created April 26, 2013 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckreynolds/5471017 to your computer and use it in GitHub Desktop.
Save chuckreynolds/5471017 to your computer and use it in GitHub Desktop.
Block WordPress Post Updates and Deletion After a Set Period. ganked from here as may need this in future.... http://www.wpbeginner.com/wp-tutorials/how-to-block-wordpress-post-updates-and-deletion-after-a-set-period/
function wpbeginner_restrict_editing( $allcaps, $cap, $args ) {
// 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;
//if post is older than 30 days. Change it to meet your needs
if( strtotime( $post->post_date ) < strtotime( '-30 day' ) ) {
//Then disallow editing.
$allcaps[$cap[0]] = FALSE;
}
return $allcaps;
}
add_filter( 'user_has_cap', 'wpbeginner_restrict_editing', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment