function sf_save_directory_item() { if ('POST' == $_SERVER['REQUEST_METHOD'] && isset($_REQUEST['form_key']) && $_REQUEST['form_key'] == 'frontend_edit_listing') { //LISTING ID if (isset($_REQUEST['listing_id'])) { $listing_id = $_REQUEST['listing_id']; } //TITLE if (isset($_REQUEST['directory_title'])) { $title = $_REQUEST['directory_title']; } //DESCRIPTION if (isset($_REQUEST['directory_description'])) { $description = $_REQUEST['directory_description']; } //CATEGORY if (isset($_REQUEST['directory-cat'])) { $category = $_REQUEST['directory-cat']; } //LOCATION if (isset($_REQUEST['directory-loc'])) { $location = $_REQUEST['directory-loc']; } //ADDRESS if (isset($_REQUEST['sf_directory_address'])) { $address = $_REQUEST['sf_directory_address']; } //LATITUDE if (isset($_REQUEST['sf_directory_lat_coord'])) { $latitude = $_REQUEST['sf_directory_lat_coord']; } //LONGITUDE if (isset($_REQUEST['sf_directory_lng_coord'])) { $longitude = $_REQUEST['sf_directory_lng_coord']; } //PIN LINK if (isset($_REQUEST['sf_directory_pin_link'])) { $pin_link = $_REQUEST['sf_directory_pin_link']; } //PIN BUTTON TEXT if (isset($_REQUEST['sf_directory_pin_button_text'])) { $pin_button_text = $_REQUEST['sf_directory_pin_button_text']; } $dir_post = array('ID' => $listing_id, 'post_title' => $title, 'post_content' => $description); //Add Taxonomy terms(Location/Category) wp_set_object_terms($listing_id, (int) $category, 'directory-category', false); wp_set_object_terms($listing_id, (int) $location, 'directory-location', false); //Update listing post fields wp_update_post($dir_post); update_post_meta($listing_id, 'sf_directory_address', $address); update_post_meta($listing_id, 'sf_directory_lat_coord', $latitude); update_post_meta($listing_id, 'sf_directory_lng_coord', $longitude); update_post_meta($listing_id, 'sf_directory_pin_button_text', $pin_button_text); update_post_meta($listing_id, 'sf_directory_pin_link', $pin_link); //Proccess Images if ($_FILES) { $post_id = $_REQUEST['listing_id']; foreach ($_FILES as $file => $array) { if ($array['name'] != '') { $newupload = sf_insert_attachment($file, $post_id); if ($file == 'pin_image') { update_post_meta($post_id, 'sf_directory_map_pin', $newupload); } else { update_post_meta($post_id, '_thumbnail_id', $newupload); } } } } } }
function sf_create_directory_item() { if (!is_admin()) { if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['dirtype'] == 'directory') { // Do some minor form validation to make sure there is content if (isset($_POST['directory_title'])) { $title = $_POST['directory_title']; } if (isset($_POST['directory_description'])) { $description = $_POST['directory_description']; } $sf_directory_address = trim($_POST['sf_directory_address']); $sf_directory_lat_coord = trim($_POST['sf_directory_lat_coord']); $sf_directory_lng_coord = trim($_POST['sf_directory_lng_coord']); $sf_directory_pin_link = trim($_POST['sf_directory_pin_link']); $sf_directory_pin_button_text = trim($_POST['sf_directory_pin_button_text']); // Get the array of selected categories as multiple cats can be selected $category = $_POST['directory-cat']; $location = $_POST['directory-loc']; // Add the content of the form to $post as an array $post = array('post_title' => wp_strip_all_tags($title), 'post_content' => $description, 'post_status' => 'pending', 'post_type' => 'directory'); $post_id = wp_insert_post($post); // Pass the value of $post to WordPress the insert function // Add Custom meta fields add_post_meta($post_id, 'sf_directory_address', $sf_directory_address); add_post_meta($post_id, 'sf_directory_lat_coord', $sf_directory_lat_coord); add_post_meta($post_id, 'sf_directory_lng_coord', $sf_directory_lng_coord); add_post_meta($post_id, 'sf_directory_pin_link', $sf_directory_pin_link); add_post_meta($post_id, 'sf_directory_pin_button_text', $sf_directory_pin_button_text); //Add Taxonomy terms(Location/Category) wp_set_object_terms($post_id, (int) $category, 'directory-category', true); wp_set_object_terms($post_id, (int) $location, 'directory-location', true); //Proccess Images if ($_FILES) { foreach ($_FILES as $file => $array) { $newupload = sf_insert_attachment($file, $post_id); if ($file == 'pin_image') { update_post_meta($post_id, 'sf_directory_map_pin', $newupload); } else { update_post_meta($post_id, '_thumbnail_id', $newupload); } } } //Send notification email to admin $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $itemlink = get_edit_post_link($post_id, ""); $message = sprintf(__('There is a new directory entry pending review, you can view it here:', 'swiftframework') . ' %s', $itemlink) . "\r\n\r\n"; @wp_mail(get_option('admin_email'), sprintf(__('[%s] New directory entry pending review.', 'swiftframework'), $blogname), $message); //Success Message echo "<h3>" . __("Thank you for your submission, your entry is pending review.", "swiftframework") . "</h3>"; exit; } else { //Dropdown translation text $choosecatmsg = __('Choose a Category', 'swiftframework'); $chooselocmsg = __('Choose a Location', 'swiftframework'); //Directory Category $argscat = array('id' => 'directory-cat', 'name' => 'directory-cat', 'show_option_none' => $choosecatmsg, 'tab_index' => 4, 'taxonomy' => 'directory-category'); //Directory Location $argsloc = array('id' => 'directory-loc', 'name' => 'directory-loc', 'show_option_none' => $chooselocmsg, 'tab_index' => 4, 'taxonomy' => 'directory-location'); ?> <!-- Front End Form display --> <div class="directory-submit-wrap"> <form id="add-directory-entry" name="add-directory-entry" method="post" action="" enctype="multipart/form-data"> <p class="directory-error"> <label class="directory_error_form"><span> <?php _e("Please fill all the fields", "swiftframework"); ?> </span></label> </p> <!-- Title --> <p><label for="directory_title"><?php _e("Title", "swiftframework"); ?> </label><br/> <input type="text" id="directory_title" value="" tabindex="1" size="20" name="directory_title"/></p> <!-- Description --> <p><label for="description"><?php _e("Description", "swiftframework"); ?> </label><br/> <textarea id="directory_description" tabindex="3" name="directory_description" cols="50" rows="6"></textarea></p> <!-- Directory Category --> <p> <label for="description"><?php _e("Category", "swiftframework"); ?> </label> <?php wp_dropdown_categories($argscat); ?> </p> <!-- Directory Location --> <p> <label for="description"><?php _e("Location", "swiftframework"); ?> </label> <?php wp_dropdown_categories($argsloc); ?> </p> <!-- Address --> <p> <label for="sf_directory_address"><?php _e("Address", "swiftframework"); ?> </label> <input type="text" value="" tabindex="5" size="16" name="sf_directory_address" id="sf_directory_address"/> <a href="#" id="sf_directory_calculate_coordinates" class="read-more-button hide-if-no-js"><?php _e("Generate Coordinates", "swiftframework"); ?> </a> </p> <!-- Latitude Coordinate --> <p><label for="sf_directory_lat_coord"><?php _e("Latitude Coordinate", "swiftframework"); ?> </label> <input type="text" value="" tabindex="5" size="16" name="sf_directory_lat_coord" id="sf_directory_lat_coord"/></p> <!-- Longitude Coordinate --> <p><label for="sf_directory_lng_coord"><?php _e("Longitude Coordinate", "swiftframework"); ?> </label> <input type="text" value="" tabindex="5" size="16" name="sf_directory_lng_coord" id="sf_directory_lng_coord"/></p> <!-- Pin Image --> <label for="file"><?php _e("Pin Image", "swiftframework"); ?> </label> <p><input type="file" name="pin_image" id="pin_image"></p> <!-- Directory Featured Image --> <label for="file"><?php _e("Featured Image", "swiftframework"); ?> </label> <p><input type="file" name="featured_image" id="featured_image"></p> <!-- Pin Link Button --> <p><label for="sf_directory_pin_link"><?php _e("Pin Link", "swiftframework"); ?> </label> <input type="text" value="" tabindex="5" size="16" name="sf_directory_pin_link" id="sf_directory_pin_link"/></p> <!-- Pin Button Text --> <p><label for="sf_directory_pin_button_text"><?php _e("Pin Button Text", "swiftframework"); ?> </label> <input type="text" value="" tabindex="5" size="16" name="sf_directory_pin_button_text" id="sf_directory_pin_button_text"/></p> <!-- Post type --> <input type="hidden" name="dirtype" id="dirtype" value="directory"/> <input type="hidden" name="action" value="postdirectory"/> <p><input type="submit" value="<?php _e("Create", "swiftframework"); ?> " id="directory-submit" name="directory-submit"/></p> </form> </div> <?php } } }