The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] top level admin page for editing a certain post (3 posts)

  1. philippze
    Posted 4 years ago #


    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?

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

    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()')?


  2. bcworkz
    Posted 4 years ago #

    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!

  3. philippze
    Posted 4 years ago #

    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>.');

Topic Closed

This topic has been closed to new replies.

About this Topic