function write_here_form() { ob_start(); ?> <div class="write-here write"> <?php write_here_show_error_messages(); ?> <form id="new_post" name="new_post" method="post" action="" enctype="multipart/form-data"> <label for="wh_image_upload">Featured Image</label> <input type="file" name="wh_image_upload" id="wh_image_upload" multiple="false" /> <label for="title">Title</label> <input type="text" id="title" name="title" /> <label for="wh_content">Content</label> <?php $content = ''; $editor_id = 'wh_content'; wp_editor($content, $editor_id); ?> <label for="cat">Category</label> <?php wp_dropdown_categories('show_option_none=Category&taxonomy=category&hide_empty=0'); ?> <label for="post_tags">Tags</label> <input type="text" id="post_tags" name="post_tags" /> <label for="date">Date</label> <div id="timestampdiv" class="hide-if-js"><?php write_here_time(0, 0, 5); ?> </div> <input type="submit" value="Publish" id="submit" name="submit" /> <input type="hidden" name="action" value="write_here_new_post" /> <?php wp_nonce_field('new-post', 'new-post-nonce'); ?> </form> </div> <?php return ob_get_clean(); }
function write_here_edit_form() { $nonce = $_REQUEST['_wpnonce']; if (!wp_verify_nonce($nonce)) { // This nonce is not valid. die('Security check'); } else { $post_id = $_REQUEST['post']; if ($post_id) { $post_to_edit = get_post($post_id); // Get existing tags for the post function get_existing_tags($post_id) { $tags = wp_get_post_tags($post_id); $iflast = $tags; foreach ($tags as $tag) { echo $tag->name; if (next($iflast)) { echo ', '; } } } ?> <div class="write-here edit"> <?php write_here_show_error_messages(); ?> <form id="edit_post" name="edit_post" method="post" action="" enctype="multipart/form-data"> <label for="wh_image_upload">Featured Image</label> <?php //http://wordpress.stackexchange.com/questions/36361/delete-attachment-from-front-end if (get_the_post_thumbnail($post_id)) { $attachment_id = get_post_thumbnail_id($post_id); ?> <div class="wh-f-img"> <?php echo get_the_post_thumbnail($post_id, 'thumbnail', array('class' => 'file-' . $attachment_id . '')); ?> <p id="rm_fi"><a class="remImage" name="<?php echo $attachment_id; ?> " href=""><?php _e('Delete'); ?> </a></p> <input type="hidden" id="att_remove" name="att_remove[]" value="<?php echo $attachment_id; ?> " /> <input type="hidden" name="nonce" id="nonce" value="<?php echo wp_create_nonce('delete_attachment'); ?> " /> <script type="text/javascript"> var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?> '; </script> </div> <input type="file" name="wh_image_upload" id="wh_image_upload" multiple="false" style="display: none;" /> <?php } else { ?> <input type="file" name="wh_image_upload" id="wh_image_upload" multiple="false" /> <?php } ?> <label for="title">Title</label> <input type="text" id="title" name="title" value="<?php echo $post_to_edit->post_title; ?> " /> <label for="wh_content">Content</label> <?php $content = $post_to_edit->post_content; $editor_id = 'wh_content'; wp_editor($content, $editor_id); ?> <label for="cat">Category</label> <?php $cat = wp_get_post_terms($post_to_edit->ID, 'category'); if ($cat) { wp_dropdown_categories('show_option_none=Category&taxonomy=category&selected=' . $cat[0]->term_id); } else { wp_dropdown_categories('show_option_none=Category&taxonomy=category&hide_empty=0'); } ?> <label for="post_tags">Tags</label> <input type="text" id="post_tags" name="post_tags" value="<?php get_existing_tags($post_id); ?> " /> <label for="date">Date</label> <div id="timestampdiv" class="hide-if-js"><?php write_here_time_edit(0, 0, 5); ?> </div> <input type="submit" value="Update" id="submit" name="submit" /> <input type="hidden" name="action" value="write_here_edit_post" /> <input type="hidden" name="pid" value="<?php echo $post_to_edit->ID; ?> " /> <?php wp_nonce_field('edit-post', 'edit-post-nonce'); ?> </form> </div> <?php } else { echo "It need post to edit."; } // post_id close } //nonce close }