Family Best Time >> Electronics

How to block WordPress updates and removal after a set period

Managing WordPress website with multiple authors can be tricky at times. There are plugins to manage the editorial workflow, but you may find situations where you need specific solutions for better control of your WordPress site. We recently helped a user find such a solution. They wanted to block WordPress updates and deletion after a set period of time for all users (including editors) after a set period of time. For example, if a published post is 30 days old or older, editors cannot edit or delete it. Only admins can modify that post. In this article, we will show you how to block post editing, updating and deleting after a set period of time in WordPress.

How to block WordPress updates and removal after a set period

All you need to do is add the following code to your theme's functions.php file or a site-specific plugin.

 función wpbeginner_restrict_editing ($ allcaps, $ cap, $ args) // Bail out si no estamos pidiendo editar o eliminar una publicación ... if ('edit_post'! = $ args [0] && 'delete_post'! = $ args [0] //… o el usuario es admin ||! Empty ($ allcaps ['manage_options']) //… o el usuario ya no puede editar la publicación || empty ($ allcaps ['edit_posts'))) return $ allcaps; // Cargar los datos de la publicación: $ post = get_post ($ args [2]); // Saltar si la publicación no está publicada: if ('publish'! = $ Post-> post_status) devuelve $ allcaps; // si la publicación tiene más de 30 días. Cámbielo para satisfacer sus necesidades si (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 ); 

This function checks if the user has the ability to edit or delete posts. After that the status of the publication is checked. If a post is published and is older than 30 days, the user's ability to edit and delete the post is removed. If a post is published but is not older than 30 days, users with the ability to edit posts can still edit it. Note:Admins can edit and delete posts anytime they want.

We hope this article has helped anyone who wants to block post editing, updating and deleting in WordPress after a set period of time. Would you ever do this on your site? What use cases can you see for something like this? Let us know in the comments below.

Source:
Smhmic