Nice, @Alexey. Here is a simplified version, that does not disallow Administrators from editing. This version is more in the style of WordPress core, as I took it from the example code on the WordPress user_has_cap filter codex page and modified it.
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;
$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 );
Ok! @Kieran and @Rarst, here it is 🙂
Nice, @Alexey. Here is a simplified version, that does not disallow Administrators from editing. This version is more in the style of WordPress core, as I took it from the example code on the WordPress user_has_cap filter codex page and modified it.