Locking pages in New Blog Templates still allows Admins to delete the pages.

I'm wondering if this is the default functionality, or if it is malfunctioning on my networks. I lock a number of pages to prevent the content on those pages from being accidentally deleted by admins on network sites. Not all pages are locked, just some. I just noticed that though admins can not edit these pages, they can delete them -- which defeats a big part of the purpose I had in locking them in the first place (to prevent major functioning of these template sites from being accidentally disrupted).

Is this normal functioning for locked pages in New Blog Templates? [I'm referring to the post status box on pages being marked as locked, not the template option to lock all pages.] I thought it was suppose to prevent any changes to the page, including deletion. If I am incorrect, does anyone know if there is a filter or hook or something I can tap into to get the functioning I want out of this plugin? Thanks!

  • Vaughan

    Hi,

    This is normal behaviour. locking and deleting are seperate features.

    The following code should hopefully work. You will need to create a custom mu-plugin.

    Create a file called wpmu_prevent_delete.php

    Then place the following code inside.

    <?php
    add_action('wp_trash_post', 'restrict_post_deletion', 10, 1);
    add_action('before_delete_post', 'restrict_post_deletion', 10, 1);
    function restrict_post_deletion($post_id) {
         $protect_post_ids = array(1,2,3,4);
      if( ! is_super_admin() ) {
        if( in_array($post_id, $protect_post_ids ) {
          exit('The page you were trying to delete is protected.');
        }
      }
    }

    Enter the ids of the pages/posts that you want to prevent deleting in the array(seperated by comma)

    Then upload this file to /wp-content/mu-plugins

    Hope this helps

  • Vaughan

    Hi,

    Remove the comments before the <?php.

    <?php has to be on the very first line with no whitespace in front of it.

    If you wish to add comments do it like this;

    <?php
    /* mu plugin suggested by Vaughan at WPMUDEV.
    *  prevent locked pages from being deleted by Admins on the network.
    * page editing options have already been selectively removed using the new blog templates plugin.
    */
    add_action('wp_trash_post', 'restrict_post_deletion', 10, 1);
    add_action('before_delete_post', 'restrict_post_deletion', 10, 1);
    function restrict_post_deletion($post_id) {
         $protect_post_ids = array(1359,1888,1632,2149,587,2266,1102,73,1393,898,1104,589,591,593,595,1557,597,710,1378,1562,1108,1110,599,1626,601,603,605,1106,1111,1631,1113,546,1115,2324,948,607,538,609,1569,1584,5,152,1613,110,140,571,142,156,99,158,108,88,112,1694,161,85,148,146,144,1621,154,150,167,138,172,207,944,946);
      if( ! is_super_admin() ) {
        if( in_array($post_id, $protect_post_ids ) {
          exit('This page is protected from editing and can not be deleted without contacting technical support.');
        }
      }
    }

    Hope this helps

  • Vaughan

    Hi,

    Apologies, i missed aclosing bracket on the if().

    Try the following.

    <?php
    /* mu plugin suggested by Vaughan at WPMUDEV.
    *  prevent locked pages from being deleted by Admins on the network.
    * page editing options have already been selectively removed using the new blog templates plugin.
    */
    add_action('wp_trash_post', 'restrict_post_deletion', 10, 1);
    add_action('before_delete_post', 'restrict_post_deletion', 10, 1);
    function restrict_post_deletion($post_id) {
         $protect_post_ids = array(1359,1888,1632,2149,587,2266,1102,73,1393,898,1104,589,591,593,595,1557,597,710,1378,1562,1108,1110,599,1626,601,603,605,1106,1111,1631,1113,546,1115,2324,948,607,538,609,1569,1584,5,152,1613,110,140,571,142,156,99,158,108,88,112,1694,161,85,148,146,144,1621,154,150,167,138,172,207,944,946);
      if( ! is_super_admin() ) {
        if( in_array($post_id, $protect_post_ids )) {
          exit('This page is protected from editing and can not be deleted without contacting technical support.');
        }
      }
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.