function cp_add_new_listing($advals, $renew_id = false) { global $wpdb, $cp_options; $new_tags = ''; $ad_length = ''; $attach_id = ''; $the_attachment = ''; // check to see if html is allowed if (!$cp_options->allow_html) { $post_content = appthemes_filter($advals['post_content']); } else { $post_content = wp_kses_post($advals['post_content']); } // tags are tricky and need to be put into an array before saving the ad if (!empty($advals['tags_input'])) { $new_tags = explode(',', $advals['tags_input']); } // put all the new ad elements into an array // these are the minimum required fields for WP (except tags) $new_ad = array(); $new_ad['post_title'] = appthemes_filter($advals['post_title']); $new_ad['post_content'] = trim($post_content); $new_ad['post_status'] = 'pending'; // no longer setting final status until after images are set $new_ad['post_author'] = $advals['user_id']; $new_ad['post_type'] = APP_POST_TYPE; if ($renew_id) { $new_ad['ID'] = $renew_id; $new_ad['post_date'] = current_time('mysql'); $new_ad['post_date_gmt'] = current_time('mysql', 1); $post_id = wp_update_post($new_ad); } else { // insert the new ad $post_id = wp_insert_post($new_ad); } //set the custom post type categories wp_set_post_terms($post_id, appthemes_filter($advals['cat']), APP_TAX_CAT, false); //set the custom post type tags wp_set_post_terms($post_id, $new_tags, APP_TAX_TAG, false); // the unique order ID we created becomes the ad confirmation ID // we will use this for payment systems and for activating the ad // later if need be. it needs to start with cp_ otherwise it won't // be loaded in with the ad so let's give it a new name $advals['cp_sys_ad_conf_id'] = $advals['oid']; // get the ad duration and first see if ad packs are being used // if so, get the length of time in days otherwise use the default // prune period defined on the CP settings page if (isset($advals['pack_duration'])) { $ad_length = $advals['pack_duration']; } else { $ad_length = $cp_options->prun_period; } // set the ad listing expiration date and put into a session $ad_expire_date = appthemes_mysql_date(current_time('mysql'), $ad_length); $advals['cp_sys_expire_date'] = $ad_expire_date; $advals['cp_sys_ad_duration'] = $ad_length; // if renew ad - delete all old post meta and unmark ad as featured if ($renew_id) { unstick_post($renew_id); $custom_field_keys = get_post_custom_keys($renew_id); foreach ($custom_field_keys as $custom_key) { delete_post_meta($renew_id, $custom_key); } } // now add all the custom fields into WP post meta fields foreach ($advals as $meta_key => $meta_value) { if (appthemes_str_starts_with($meta_key, 'cp_') && !is_array($advals[$meta_key])) { add_post_meta($post_id, $meta_key, wp_kses_post($meta_value), true); } if (appthemes_str_starts_with($meta_key, 'cp_') && is_array($advals[$meta_key])) { foreach ($advals[$meta_key] as $checkbox_value) { add_post_meta($post_id, $meta_key, wp_kses_post($checkbox_value)); } } } // if they checked the box for a featured ad, then make the post sticky if (isset($advals['featured_ad'])) { stick_post($post_id); } if (isset($advals['attachment'])) { $the_attachment = $advals['attachment']; // associate the already uploaded images to the new ad and create multiple image sizes $attach_id = cp_associate_images($post_id, $the_attachment, true); } if (isset($advals['app_attach_id'])) { $attachments = $advals['app_attach_id']; $titles = isset($advals['app_attach_title']) ? $advals['app_attach_title'] : array(); // associate the already uploaded images to the new ad and update titles $attach_id = appthemes_plupload_associate_images($post_id, $attachments, $titles, true); } // set the thumbnail pic on the WP post //cp_set_ad_thumbnail($post_id, $attach_id); //last step is to publish the ad when its appropriate to publish immediately $final_status = cp_set_post_status($advals); if ($final_status == 'publish') { $final_post = array(); $final_post['ID'] = $post_id; $final_post['post_status'] = $final_status; $update_result = wp_update_post($final_post); } cp_action_add_new_listing($post_id); // kick back the post id in case we want to use it return $post_id; }
function cp_add_new_listing($advals) { global $wpdb; $new_tags = ''; $ad_length = ''; $attach_id = ''; $the_attachment = ''; // tags are tricky and need to be put into an array before saving the ad if (!empty($advals['tags_input'])) { $new_tags = explode(',', $advals['tags_input']); } // put all the new ad elements into an array // these are the minimum required fields for WP (except tags) $new_ad = array(); $new_ad['post_title'] = appthemes_filter($advals['post_title']); $new_ad['post_content'] = trim($advals['post_content']); $new_ad['post_status'] = 'pending'; // no longer setting final status until after images are set $new_ad['post_author'] = 0; if (!empty($_SESSION['anonym']) && $_SESSION['anonym'] != '') { $new_ad['post_author'] = 0; } else { $new_ad['post_author'] = $advals['user_id']; } $new_ad['post_type'] = APP_POST_TYPE; // make sure the WP sanitize_post function doesn't strip out embed & other html if (get_option('cp_allow_html') == 'yes') { $new_ad['filter'] = true; } //print_r($new_ad).' <- new ad array<br>'; // insert the new ad $post_id = wp_insert_post($new_ad); //set the custom post type categories wp_set_post_terms($post_id, appthemes_filter($advals['cat']), APP_TAX_CAT, false); //set the custom post type tags wp_set_post_terms($post_id, $new_tags, APP_TAX_TAG, false); //$location = get_field('location'); //**************************************EKLEME********************************************** // Google Maps ten Pozisyon Seçilmiþse O pozisyonu kaydeder seçimemiþse adresten bulur if (!empty($_SESSION['kordinat']) && $_SESSION['kordinat'] != '') { $category = get_the_terms($post_id, 'ad_cat'); $address1 = explode('|', $_SESSION['kordinat']); $address2 = explode(',', $address1[1]); cp_add_geocode($post_id, $category[0]->name, $address2[0], $address2[1]); $_SESSION['kordinat'] = ''; } else { $_SESSION['kordinat'] == 'yok'; } //************************************************************************************ // the unique order ID we created becomes the ad confirmation ID // we will use this for payment systems and for activating the ad // later if need be. it needs to start with cp_ otherwise it won't // be loaded in with the ad so let's give it a new name $advals['cp_sys_ad_conf_id'] = $advals['oid']; // get the ad duration and first see if ad packs are being used // if so, get the length of time in days otherwise use the default // prune period defined on the CP settings page if (isset($advals['pack_duration'])) { $ad_length = $advals['pack_duration']; } else { $ad_length = get_option('cp_prun_period'); } // set the ad listing expiration date and put into a session $ad_expire_date = date_i18n('m/d/Y H:i:s', strtotime('+' . $ad_length . ' days')); // don't localize the word 'days' $advals['cp_sys_expire_date'] = $ad_expire_date; $advals['cp_sys_ad_duration'] = $ad_length; // now add all the custom fields into WP post meta fields foreach ($advals as $meta_key => $meta_value) { if (appthemes_str_starts_with($meta_key, 'cp_') && !is_array($advals[$meta_key])) { add_post_meta($post_id, $meta_key, $meta_value, true); } if (appthemes_str_starts_with($meta_key, 'cp_') && is_array($advals[$meta_key])) { foreach ($advals[$meta_key] as $checkbox_value) { add_post_meta($post_id, $meta_key, $checkbox_value); } } } // if they checked the box for a featured ad, then make the post sticky if (isset($advals['featured_ad'])) { stick_post($post_id); } if (isset($advals['attachment'])) { $the_attachment = $advals['attachment']; // associate the already uploaded images to the new ad and create multiple image sizes $attach_id = cp_associate_images($post_id, $the_attachment, true); } // set the thumbnail pic on the WP post //cp_set_ad_thumbnail($post_id, $attach_id); //last step is to publish the ad when its appropriate to publish immediately $final_status = cp_set_post_status($advals); if ($final_status == 'publish') { $final_post = array(); $final_post['ID'] = $post_id; $final_post['post_status'] = $final_status; $update_result = wp_update_post($final_post); } // kick back the post id in case we want to use it return $post_id; }
/** * Updating listing. * * @param object $order * @param object $checkout * * return void */ public function update_listing($order, $checkout) { global $cp_options; $listing = $this->get_listing_obj(); // save internal data foreach ($this->posted_fields as $field_key => $field_value) { if (appthemes_str_starts_with($field_key, 'cp_sys_')) { update_post_meta($listing->ID, $field_key, wp_kses_post($field_value)); } } // update listing status $listing_args = array('ID' => $listing->ID, 'post_status' => cp_set_post_status($this->posted_fields), 'post_author' => get_current_user_id(), 'post_date' => current_time('mysql'), 'post_date_gmt' => current_time('mysql', 1)); $listing_id = wp_update_post($listing_args); do_action('cp_update_listing', $listing->ID, $order, $checkout); }