• Resolved philippze

    (@philippze)


    Hallo,

    I’m using a post type ‘front page’ (and if necessary create one post of this type using ‘wp_insert_post()’). The owner of the webpage should be able to edit the front page, but it should be difficult to create additional pages of type ‘front page’. That’s why I need a top level menu item that links to an admin page where the only ‘front page’ can be edited. What’s the best way to do that?

    1.
    Is there a simple way to determine the URL instead of a callback function when adding a menu item (like with ‘add_menu_page()’)?

    2.
    Or is there a function that returns or prints the HTML code needed to display the edit-post-page (which one could use in the callback function in ‘add_menu_page()’)?

    Cheers
    Philipp

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m not sure this would work, but I would hook onto an action that triggers when the edit/create page dialog starts and check the user credentials and only allow them to create one page or edit that one page, otherwise the process dies.

    You could store the page id in usermeta, so they can only get the editor if the meta is empty or the ID to be edited matches their meta ID. There’s several security issues to iron out, but I think this would be a sound approach.

    Good luck!

    Thread Starter philippze

    (@philippze)

    thanks, bcworkz, your suggestion works. A very rough implementation looks like this:

    add_action( 'admin_init', 'forbid_front_page_creation' );
    function forbid_front_page_creation () {
    	$front_page = get_front_page ();
    	$url = $_SERVER['REQUEST_URI'];
    	if (substr_count( $url, 'post-new.php?post_type=front_page')) {
    		wp_die('Please do not create another front page. There exists one already <a href="http://localhost/www.something.de/wp-admin/post.php?post=' . $front_page->ID . '&action=edit">here</a>.');
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘top level admin page for editing a certain post’ is closed to new replies.