Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to disable or lock parent pages from being edited in wordpress admin? I only want the children pages to be editable.

share|improve this question

1 Answer 1

Yes there is. Save this code as plugin and activate one. Plugin will lock all pages that has children from edit.

<?php
/*
Plugin Name: Lock parent pages form edit
Plugin URI: 
Description: 
Version: 0.1
Author: Alexey Selin <alexey.a.selin@gmail.com>
Author URI: http://wordpress.stackexchange.com/users/7314/alexey
*/

function lock_parent_pages_from_edit( $capauser, $capask, $param){
    global $wpdb;
    $post = get_post( $param[2] );
    $children = get_pages('child_of='.$post->ID);
    if( count( $children ) > 0 ) {
        if( $param[0] == "edit_page" ) {
              foreach( (array) $capask as $capasuppr) {
                 if ( array_key_exists($capasuppr, $capauser) ) {
                    $capauser[$capasuppr] = 0;
                 }
              }
        }
    }
    return $capauser;
}
add_filter('user_has_cap', 'lock_parent_pages_from_edit', 100, 3 );
?>
share|improve this answer
    
This works, however not quite what I was after. I am sorry I worded this wrong. I want to lock all pages at the top level. not just ones with children. –  Shae Sep 23 '11 at 12:47
    
Nevermind, I figured it out. This is what I did: ' function lock_parent_pages_from_edit( $capauser, $capask, $param){ global $wpdb; $post = get_post( $param[2] ); if($post->post_parent == 0) { if( $param[0] == "edit_page" ) { foreach( (array) $capask as $capasuppr) { if ( array_key_exists($capasuppr, $capauser) ) { $capauser[$capasuppr] = 0; } } } } return $capauser; } add_filter('user_has_cap', 'lock_parent_pages_from_edit', 100, 3 );' –  Shae Sep 23 '11 at 13:38
    
Correction. I still want to be able to add child pages to the top level page. I just want the top level page to not be editable. Make sense? –  Shae Sep 23 '11 at 13:49
    
What is stopping you from add child pages to the top level pages? I tested your updated code on my machine, it works, and i can add child pages. –  Alexey Sep 23 '11 at 17:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.