Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function authors_dropdown_post() {
- $get_tags = get_terms('authors', 'order_by=name');
- $dropdown = '';
- $dropdown_start = '<select size="5" onclick="" onfocus="" onblur="" class="select_input" id="select_authors" name="select_authors">';
- $dropdown_start .= sprintf('<option value="">%s</option>', __('Select Authors or Type in Textbox', 'adw'));
- foreach($get_tags as $tag):
- $dropdown .= sprintf('<option onclick="sendText(document.wpuf_new_post_form.authors, \'%2$s, \');" href="javascript:void(0)" value="%1$s">%2$s</option>', get_term_link($tag->slug, 'authors'), $tag->name);
- endforeach;
- $dropdown_end = '</select>';
- echo $dropdown_start.$dropdown.$dropdown_end;
- }
- function editions_dropdown_post() {
- $get_tags = get_terms('editions', 'order_by=name');
- $dropdown = '';
- $dropdown_start = '<select size="5" onclick="" onfocus="" onblur="" class="select_input" id="select_editions" name="select_editions">';
- $dropdown_start .= sprintf('<option value="">%s</option>', __('Select Editions or Type in Textbox', 'adw'));
- foreach($get_tags as $tag):
- $dropdown .= sprintf('<option onclick="sendText(document.wpuf_new_post_form.editions, \'%2$s, \');" href="javascript:void(0)" value="%1$s">%2$s</option>', get_term_link($tag->slug, 'editions'), $tag->name);
- endforeach;
- $dropdown_end = '</select>';
- echo $dropdown_start.$dropdown.$dropdown_end;
- }
- function publishers_dropdown_post() {
- $get_tags = get_terms('publishers', 'order_by=name');
- $dropdown = '';
- $dropdown_start = '<select size="5" onclick="" onfocus="" onblur="" class="select_input" id="select_publishers" name="select_publishers">';
- $dropdown_start .= sprintf('<option value="">%s</option>', __('Select Publishers or Type in Textbox', 'adw'));
- foreach($get_tags as $tag):
- $dropdown .= sprintf('<option onfocus="" onblur="" onclick="sendText(document.wpuf_new_post_form.publishers, \'%2$s, \');" href="javascript:void(0)" value="%1$s">%2$s</option>', get_term_link($tag->slug, 'publishers'), $tag->name);
- endforeach;
- $dropdown_end = '</select>';
- echo $dropdown_start.$dropdown.$dropdown_end;
- }
- function classcat_dropdown_post() {
- $get_tags = get_terms('classcat', 'order_by=name');
- $names = wp_get_object_terms($post->ID, 'classcat');
- $dropdown = '';
- $dropdown_start = '<select size="5" onclick="" onfocus="" onblur="" class="select_input" id="select_classcat" name="select_classcat">';
- $dropdown_start .= sprintf('<option value="">%s</option>', __('Select Class/Category or Type in Textbox', 'adw'));
- foreach($get_tags as $tag):
- $dropdown .= sprintf('<option onclick="sendText(document.wpuf_new_post_form.classcat, \'%2$s, \');" href="javascript:void(0)" value="%1$s">%2$s</option>', $tag->slug, $tag->name);
- endforeach;
- $dropdown_end = '</select>';
- echo $dropdown_start.$dropdown.$dropdown_end;
- }
- function wpuf_add_post_shorcode() {
- wpuf_auth_redirect_login(); // if not logged in, redirect to login page
- nocache_headers();
- wpuf_add_post();
- add_action('wp_footer', 'wpuf_post_form_style');
- }
- add_shortcode('wpuf_addpost', 'wpuf_add_post_shorcode');
- function wpuf_add_post() {
- //validate new post submission
- if(isset($_POST['wpuf_new_post_submit'])) {
- check_admin_referer('wpuf-add-post');
- wpuf_validate_post_submit();
- }
- ?>
- <script language="JavaScript" type="text/JavaScript">
- function sendText(e, text)
- {
- e.value = e.value + text
- }
- </script>
- <form name="wpuf_new_post_form" action="" method="POST">
- <?php wp_nonce_field('wpuf-add-post') ?>
- <ul class="wpuf-post-form">
- <li>
- <label for="new-post-title">
- Title <span class="required">*</span>
- </label>
- <input type="text" name="wpuf_post_title" value="<?php echo htmlspecialchars($_POST['wpuf_post_title']);?>" id="new-post-title" minlength="2">
- <div class="clear"></div>
- </li>
- <li>
- <label for="bookid">
- Book ID <span class="required">*</span>
- </label>
- <input type="text" name="bookid" value="<?php echo htmlspecialchars($_POST['bookid']);?>" id="bookid" minlength="2">
- <div class="clear"></div>
- </li>
- <li>
- <label for="authors">
- Authors:
- </label>
- <div class="input_boxes">
- <input type="text" name="authors" value="<?php echo htmlspecialchars($_POST['authors']);?>" id="authors"><br /><?php authors_dropdown_post(); ?></div>
- <div class="clear"></div>
- </li>
- <li>
- <label for="publishers">
- Publishers:
- </label>
- <div class="input_boxes">
- <input type="text" name="publishers" value="<?php echo htmlspecialchars($_POST['publishers']);?>" id="publishers"><br /><?php publishers_dropdown_post(); ?></div>
- <div class="clear"></div>
- </li>
- <li>
- <label for="classcat">
- Category/Class:
- </label><div class="input_boxes">
- <input type="text" name="classcat" value="<?php echo htmlspecialchars($_POST['classcat']);?>" id="classcat"><br /><?php classcat_dropdown_post(); ?></div>
- <div class="clear"></div>
- </li>
- <li>
- <label for="editions">
- Editions:
- </label><div class="input_boxes">
- <input type="text" name="editions" value="<?php echo htmlspecialchars($_POST['editions']);?>" id="editions"><br /><?php editions_dropdown_post(); ?></div>
- <div class="clear"></div>
- </li>
- <li>
- <label for="dates">
- Listed Date:
- </label>
- <input type="text" name="dates" id="dates" value="<?php the_time('j, M, Y'); ?>" onfocus="if (this.value == '<?php the_time('j, M, Y'); ?>') {this.value = '<?php the_time('j, M, Y'); ?>';}" onblur="if (this.value == '') {this.value = '<?php the_time('j, M, Y'); ?>';}" />
- <div class="clear"></div>
- </li>
- <li>
- <label for="new-post-desc">
- Description <span class="required">*</span>
- </label>
- <textarea name="wpuf_post_content" id="new-post-desc" cols="40" rows="8"></textarea>
- <div class="clear"></div>
- </li>
- <li>
- <label> </label>
- <input class="wpuf_submit" type="submit" name="wpuf_new_post_submit" value="Post!">
- </li>
- </ul>
- </form>
- <?php
- }
- function wpuf_validate_post_submit() {
- global $userdata;
- $errors = array();
- $title = trim($_POST['wpuf_post_title']);
- $content = trim($_POST['wpuf_post_content']);
- //$tags = wpuf_clean_tags($_POST['wpuf_post_tags']);
- $cat = trim($_POST['cat']);
- $authors = wpuf_clean_tags($_POST['authors']);
- $publishers = wpuf_clean_tags($_POST['publishers']);
- $editions = wpuf_clean_tags($_POST['editions']);
- $classcat = wpuf_clean_tags($_POST['classcat']);
- $dates = wpuf_clean_tags($_POST['dates']);
- if (empty($title)) {
- $errors[] = "Empty post title";
- } else {
- $title = trim(strip_tags($title));
- }
- if (empty($content)) {
- $errors[] = "Empty post content";
- } else {
- $content = trim($content);
- }
- if (!empty($tags)) {
- $tags = explode(',', $tags);
- }
- if (!empty($authors)) {
- $authors = explode(',', $authors);
- }
- if (!empty($publishers)) {
- $publishers = explode(',', $publishers);
- }
- if (!empty($editions)) {
- $editions = explode(',', $editions);
- }
- if (!empty($classcat)) {
- $classcat = explode(',', $classcat);
- }
- $post_status = (get_option('wpuf_post_status')) ? get_option('wpuf_post_status') : 'publish';
- if (!$errors) {
- $my_post = array(
- 'post_title' => $title,
- 'post_content' => $content,
- 'post_status' => $post_status,
- 'post_author' => $userdata->ID,
- 'post_category' => array($cat),
- 'post_type' => 'library',
- 'authors' => $authors,
- 'editions' => $editions,
- 'classcat' => $classcat,
- 'dates' => $dates,
- 'publishers' => $publishers,
- 'tags_input' => $tags
- );
- $post_id = wp_insert_post($my_post);
- if ($post_id) {
- add_post_meta($post_id, 'bookid', $_POST['bookid']);
- echo '<div class="success">Post Published succesfully.</div>';
- //send mail notification
- if(get_option('wpuf_notify') == 'yes') {
- wpuf_notify_post_mail();
- }
- }
- } else {
- echo wpuf_error_msg($errors);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement