Anonymous Postings

This is a repost of a question asked on stackoverflow, and was referred to this site:

My client wants to create a form on his new WP site that when filled out and submitted will be submitted to his admin post queue to approve and if he approves gets posted on his site in the “blog” (which is actually a bunch of guitar like tabs). The form would be custom and have custom fields. Below is the form, but in the old design before I did a refresh on it.

Read More

So, how hard would this be? He does not want it in the WP admin panel which i began to do, but outside in a page like /contribute

Related posts

Leave a Reply

2 comments

  1. you can use plugins fro the front-end posting:

    Or you can create the form yourself

        <!-- New Post Form -->
    <div id="postbox">
    <form id="new_post" name="new_post" method="post" action="">
    <p><label for="title">Title</label><br />
    <input type="text" id="title" value="" tabindex="1" size="20" name="title" />
    </p>
    <p><label for="description">Description</label><br />
    <textarea id="description" tabindex="3" name="description" cols="50" rows="6"></textarea>
    </p>
    <p><?php wp_dropdown_categories( 'show_option_none=Category&tab_index=4&taxonomy=category' ); ?></p>
    <p><label for="post_tags">Tags</label>
    <input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p>
    <p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
    <input type="hidden" name="action" value="new_post" />
    <?php wp_nonce_field( 'new-post' ); ?>
    </form>
    </div>
    <!--// New Post Form -->
    

    and process it

       if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  ($_POST['action']== 'new_post')) {
    
        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';
        }
        $tags = $_POST['post_tags'];
    
        $new_post = array(
            'post_title'    => $title,
            'post_content'  => $description,
            'post_category' => $_POST['cat'],  
            'tags_input'    => $tags,
            'post_status'   => 'draft'
        );
        wp_insert_post($new_post);  
    
    }
    

    And make sure to check for nonce and sanitization of the form fields.

    UPDATE

    According to your gist code and comment change your function to this:

     if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && ($_POST['action']== 'new_post')) {
            $has_errors = false;
            if (isset ($_POST['title'])) {
                $title = $_POST['title'];
            } else {
                echo 'Please enter a title';
                $has_errors = true;
            }
            if (isset ($_POST['performer'])) {
                $performer = $_POST['preformer'];
            } else {
                echo 'Please enter a performer';
                $has_errors = true;
            }
            if (isset ($_POST['composer'])) {
              $composer = $_POST['composer'];
            } else {
                echo 'Please enter a composer';
                $has_errors = true;
            }
            if (isset ($_POST['tablature'])) {
                $tablature = $_POST['tablature'];
            } else {
                echo 'Please enter the content';
                $has_errors = true;
            }
            $tags = $_POST['post_tags'];
            if (!$has_errors){
            //save <title>  by: <preformer>
            $title .= " by: " .$performer;
    
            //save Composed by: <composer> Performed by: <performer> <tablature>
            $content = "<h4>Composed by: ". $composer."</h4><br/><h4>Performed by: ".$performer."</h4><br/>".$tablature;
    
            $new_post = array(
                'post_title' => $title,
                'post_content' => $content,
                'post_category' => $_POST['cat'],
                'tags_input' => $tags,
                'post_status' => 'draft'
            );
            $pid = wp_insert_post($new_post);
    
    
            //save email and submmiter as post meta in custom fields
            update_post_meta($pid, 'submiter_email', urldecode($_POST['email']));
            update_post_meta($pid, 'submiter_name', urldecode($_POST['submitter']));
        }
    }