add_menu_page Callback Function: Skip page content?

I want to have a menu item that will, on-click, add a page with certain arguments.

In it’s simplicity, I have:

Read More
function av_subscribe_create_menu(){
// Create top-level menu
add_menu_page( 'Add Comment Feed', 'Add Comment Feed', 'manage_options', __FILE__, 
    'av_subscribe_create_feed_page', '' );
}
add_action( 'admin_menu', 'av_subscribe_create_menu' );

function av_subscribe_create_feed_page(){

    $page = array(
      'post_type' => 'page',
      'post_status' => 'publish',
      'post_parent' => 13570
    );

    $new_page_id = wp_insert_post($page, false);

}

This doesn’t work and even if it did, I don’t believe it would take me to the Edit screen. Is there a way you can use a function to add a post and go directly to the edit screen?

Also, bonus question: If you do not specify a title, but you specify the post_status as publish, will this automatically create a slug for you? I don’t want an auto-generated slug of some gibberish. Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. add_action( 'admin_menu', 'av_subscribe_create_menu' );
    
    function av_subscribe_create_menu()
    {
        $hook = add_menu_page(
            'Add Comment Feed',
            'Add Comment Feed',
            'manage_options',
            'av-create-feed', // Don't use __FILE__ as the slug, keep it short 'n sweet!
            '__return_true' // We need a callback otherwise WP won't properly handle the page, though it's never seen
        );
    
    
        if ( $hook ) // Current user has the right caps
            add_action( "load-$hook", 'av_subscribe_create_feed_page' ); // This runs before header output 
    }
    
    function av_subscribe_create_feed_page()
    {
        $page_id = wp_insert_post( array(
            'post_status' => 'publish',
            'post_parent' => 13570,
            'post_title' => 'My Title',
            'post_type' => 'page',
        ));
    
        if ( $edit_url = get_edit_post_link( $page_id, 'raw' ) )
            wp_redirect( $edit_url );
        else
            wp_redirect( admin_url( "edit.php?post_type=page" ) ); // Fallback
    
        exit;
    }
    

    If you do not specify a title, but you specify the post_status as publish, will this automatically create a slug for you?

    It certainly will! Check the source code for wp_insert_post().