Forums

[resolved] Can an Admin specify that a page can't be deleted by an Editor? (5 posts)

  1. tonto24
    Member
    Posted 1 year ago #

    Hey all,

    I've setup a static page as my homepage. The project has a number of editors that can add, edit and delete pages but I want to make sure they can't delete the page chosen as the homepage. Is that possible?

    Thanks
    tonto

  2. Mark / t31os
    Moderator
    Posted 1 year ago #

    Untested, but maybe something like..

    add_action('delete_post','no_remove_front_page');
    function no_remove_front_page( $_the_post_id ) {
    	global $post;
    	if ( 'page' != $post->post_type)
    		return;
    	if ( get_option('page_on_front') == $_the_post_id )
    		// If the ID matches the front page ID, kill the delete post action.
    		wp_die('Cannot delete the front page, sorry!');
    	return;
    }

    Would need to be tested though..

  3. tonto24
    Member
    Posted 1 year ago #

    Cool, thanks for that! I'll try it out.

  4. tonto24
    Member
    Posted 1 year ago #

    That worked perfectly, I also added in another test for a static posts page. Thanks again!

    add_action('trash_post','no_remove_req_page');
    function no_remove_req_page( $_the_post_id ) {
    global $post;
    if ( 'page' != $post->post_type)
    return;
    if ( get_option('page_on_front') == $_the_post_id )
    // If the ID matches the front page ID, kill the delete post action.
    wp_die('Cannot delete the front page, sorry!');
    elseif(get_option('page_for_posts') == $_the_post_id)
    wp_die('Cannot delete the news page, sorry!');
    return;
    }

  5. Mark / t31os
    Moderator
    Posted 1 year ago #

    Happy i could help... :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags