[wp-hackers] the home.php problem: does it asks for a, posts.php?

Jackson Whelan jw at jacksonwhelan.com
Wed Aug 29 13:21:11 UTC 2012


On 8/29/12 8:58 AM, Ryann Micua wrote:
> Would it be possible to make it so that deleting an important page 
> (such as a page assigned as the front page or blog) triggers a warning 
> popup or something? would that at least decrease the chances of 
> important pages being deleted?
I've had good luck with this snippet, dropped in mu-plugins or 
functions.php, for preventing these "oops" moments.

    add_action( 'wp_trash_post', 'prevent_oops' );
    add_action( 'before_delete_post', 'prevent_oops' );

    function prevent_oops( $postid ) {

         if( $postid == get_option( 'page_on_front' ) || $postid ==
    get_option( 'page_for_posts' ) ) {
             wp_die( 'You are trying to delete a very important page.' );
             exit;
         }

    }

Not as slick as it could be, but gets the job done, and could be 
augmented to check for a post meta flag that would allow other pages to 
be 'protected' from deletion.
> And yes, I just had a client do this to me 3 months a go.. it's not nice.
Been there done that, not nice at all.

Hope that helps.

- Jackson

-- 

*Jackson Whelan* / WordPress Web Design & Development

Pittsford, Vermont / 802.483.4050
jacksonwhelan.com <http://jacksonwhelan.com?s=e> / jw at jacksonwhelan.com 
<mailto:jw at jacksonwhelan.com>



More information about the wp-hackers mailing list