I recently tried to make a form for users that are logged in to be able to add a post from the frontend to their profiles. The problems I have found are the following:
- ANYBODY can post from it, even if they are not logged in. This creates the post but in backend it is not assigned to an author.
- I don't have a way of uploading media even when adding the setting "media_buttons" to the wp_editor.
- The content I type into the text area does not save, only the Title.
Here is the code I used:
<div class="col-sm-12"> <!-- New Post Form --> <form action="" id="primaryPostForm" method="POST"> <fieldset> <label for="postTitle"><?php _e('Post Title:', 'framework') ?></label> <input type="text" name="postTitle" id="postTitle" class="required" /> </fieldset> <?php $content = ''; $editor_id = 'mycustomeditor'; wp_editor( $content, $editor_id, $settings = array( 'media_buttons' => true, 'wpautop' => true, 'textarea_name' => 'product_info_content', 'editor_class' => 'requiredField' ) ); ?> <fieldset> <input type="hidden" name="submitted" id="submitted" value="true" /> <button type="submit"><?php _e('Add Post', 'framework') ?></button> </fieldset> </form> <!--// New Post Form --> <?php $post_information = array( 'post_title' => wp_strip_all_tags( $_POST['postTitle'] ), 'post_content' => $product_info_content, 'post_type' => 'post', 'post_status' => 'publish' ); wp_insert_post( $post_information ); ?> </div>
Please help with the listed problems. I want to be able to upload media and ONLY the logged in users must be able to post from the form.