global $current_user;
$people_pages = get_posts(array('post_type' => 'people', 'posts_per_page' => 1, 'meta_query' => array(array('key' => 'wp_username', 'value' => $current_user->user_login)), 'post_status' => array('publish', 'draft')));
if (count($people_pages)) {
    $has_page = true;
    $user_page = $people_pages[0];
    if ($user_page->post_status === "publish") {
        $is_published = true;
    }
}
/*
 * If a user has no page, they see the preview, save and publish buttons
 * If a user has a page which is still draft status, they see the preview, update and publish buttons
 * If a user has a page which is published, they see the view, update button and unpublish button
 */
if (isset($_REQUEST["save"]) || isset($_REQUEST["view"]) || isset($_REQUEST["preview"]) || isset($_REQUEST["publish"]) || isset($_REQUEST["unpublish"]) || isset($_REQUEST["update"])) {
    PeoplePostType::save_extra_profile_fields($current_user->ID);
    // first check the user has a page
    if (!$has_page) {
        // only preview and publish buttons are present when a user doesn't have a page
        $post_status = isset($_REQUEST["publish"]) ? 'publish' : 'draft';
        $person_page_id = wp_insert_post(array("post_type" => "people", "post_status" => $post_status, "post_title" => $_REQUEST["firstname"] . " " . $_REQUEST["surname"], "post_author" => $current_user->ID), false);
        if ($person_page_id === 0) {
            $errors .= '<p>Failed to create user page</p>';
        } else {
            // set user ID
            update_post_meta($person_page_id, 'wp_username', $current_user->user_login);
            // get the page
            $user_page = get_post($person_page_id);
            $has_page = true;
            $is_published = $user_page->post_status == "publish" ? true : false;
        }