Create Post Using Form on WP Dashboard

Finally got this working! This is just a basic test to get the form working, but if anyone else is working on a similar issue, this is how I got it to work. Another important thing, to keep the “Headers already sent” error away, make sure that there are NO errors i.e. all fields are complete so no error message is sent back.

function add_new_post() {
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "add_new_post") {

// Do some minor form validation to make sure there is content
if (isset ($_POST['title'])) {
        $title =  $_POST['title'];
} else {
        echo 'Please enter a  title';
}
if (isset ($_POST['description'])) {
        $description = $_POST['description'];
} else {
        echo 'Please enter the content';
}

// Add the content of the form to $post as an array
$new_post = array(
        'post_title'    => $title,
        'post_content'  => $description,
        'post_status'   => 'publish',           // Choose: publish, preview, future, draft, etc.
        'post_type' => 'post'  //'post',page' or use a custom post type if you want to
);
//save the new post
$pid = wp_insert_post($new_post);
wp_redirect(admin_url()); 
//insert taxonomies
    }
}

add_action ( 'init', 'add_new_post');

function InvoiceRegisterContent() {

?>
    <form id="new_post" class="form-content" name="new_post" method="post" action="" />
        <input type="hidden" name="title" value="test" />
        <input type="hidden" name="description" value="test" />
        <input type="hidden" name="action" value="add_new_post" />
        <input type="submit" value="Register" class="button" name="submit" />   
    </form>
<?php 
}
?>