Created
April 26, 2013 23:05
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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