• Hi

    I’m trying to disable the “Add new” button when editing a page so that other persons only can edit the content.

    But when I try to do this and press “Update” the page turns white but the changes are updated though.

    The code I’m using is the following:

    add_action('admin_menu','remove_elements');
    function remove_elements(){
        global $current_screen;
        global $typenow;
    
         if ( !current_user_can('manage_options')){
    
            if (isset($_GET['post'])) {
                $type = (get_post_type($_GET['post']));
            }
            else {
                $type = 'none';
            }
    
            if (is_edit_page() && ($type == 'page' || $type == 'none')){
                ?>
                <script>
                    // set title readonly
                    var title = document.getElementById('title');
                    if ( title != null ) { title.readOnly = "readonly"; }
                </script>
                <?php
            }
        }
    }
    
    function is_edit_page($new_edit = null){
        global $pagenow;
        //make sure we are on the backend
        if (!is_admin()) return false;
    
        if($new_edit == "edit")
            return ain_rray( $pagenow, array( 'post.php',  ) );
        elseif($new_edit == "new") //check for new post page
            return in_array( $pagenow, array( 'post-new.php' ) );
        else //check for either new or edit
            return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
    }

    I’ve used this method a couple months ago and it worked then. Normally I do a bunch in there but by testing and trying to figure out the error, I reduced it to the minimum I think

  • The topic ‘add_action(admin_menu) breaks updating page’ is closed to new replies.