Created
September 9, 2017 03:17
-
-
Save Roshanb54/7034174713ccfb1918195aafadfbf698 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_shortcode( 'front_end_post_form', 'front_end_post_form' ); | |
| function front_end_post_form( $atts ) { | |
| ob_start();?> | |
| <script type="text/javascript"> | |
| jQuery(document).ready(function($) { | |
| $('#succes').hide(); | |
| }); | |
| </script> | |
| <?php | |
| $postTitleError = ''; | |
| $postcontentError = ''; | |
| if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) { | |
| if (trim($_POST['postTitle']) === '' || $_POST['postContent'] === '' ) { | |
| if(trim($_POST['postTitle']) === '') { | |
| $postTitleError = 'Please enter a title.'; | |
| } | |
| if(trim($_POST['postContent']) === '') { | |
| $postcontentError = 'Please enter a title.'; | |
| } | |
| }else{ | |
| $post_information = array( | |
| 'post_title' => esc_attr(strip_tags($_POST['postTitle'])), | |
| 'post_content' => esc_attr(strip_tags($_POST['postContent'])), | |
| 'post_status' => 'pending', | |
| 'post_type' => 'post' | |
| ); | |
| $post_id = wp_insert_post($post_information); | |
| // $link = get_permalink( $post_id ); | |
| ?> | |
| <script type="text/javascript"> | |
| jQuery(document).ready(function($) { | |
| $('#primaryPostForm').hide(); | |
| $('#succes').show(); | |
| }); | |
| </script> | |
| <?php | |
| } | |
| } ?> | |
| <form action="" id="primaryPostForm" method="POST" enctype="multipart/form-data"> | |
| <fieldset> | |
| <label for="postTitle"><?php _e('Post Title:', 'framework') ?></label> | |
| <input type="text" name="postTitle" id="postTitle" value="<?php if(isset($_POST['postTitle'])) echo $_POST['postTitle'];?>" class="required" /> | |
| </fieldset> | |
| <?php if($postTitleError != '') { ?> | |
| <span class="error"><?php echo $postTitleError; ?></span> | |
| <div class="clearfix"></div> | |
| <?php } ?> | |
| <fieldset> | |
| <label for="postContent"><?php _e('Content:', 'framework') ?></label> | |
| <textarea name="postContent"> </textarea> | |
| </fieldset> | |
| <?php if($postcontentError != '') { ?> | |
| <span class="error"><?php echo $postcontentError; ?></span> | |
| <div class="clearfix"></div> | |
| <?php } ?> | |
| <fieldset> | |
| <?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?> | |
| <input type="hidden" name="submitted" id="submitted" value="true" /> | |
| <button type="submit"><?php _e('Submit', 'framework') ?></button> | |
| </fieldset> | |
| </form> | |
| <div id="succes"> | |
| <h2>Post Title: <?php if(isset($_POST['postTitle'])) echo $_POST['postTitle'];?></h2> | |
| <h2>Contant: <?php if(isset($_POST['post_category'])) echo $_POST['post_category'];?></h2> | |
| </div> | |
| <?php $myvariable = ob_get_clean(); | |
| return $myvariable; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment