/** * Adds tax_query param to WP_Query * * The tax_query is added only if it is in $_GET['advert_category'] * * @param array $args WP_Query args * @return array Modified WP_Query args */ function search_by_category_query($args) { if (!adverts_request("advert_category")) { return $args; } $args["tax_query"] = array(array('taxonomy' => 'advert_category', 'field' => 'term_id', 'terms' => adverts_request("advert_category"))); return $args; }
/** * wp-admin / Classifieds / Options panel logic. * * This functions is being executed when wp-admin / Classifieds / Options panel * is being loaded. It either generates list of available modules or loads module, * depending on $_REQUEST 'disabled', 'enabled' and 'module' params. * * @global $_REQUEST * * @uses adverts_config() * @uses adverts_config_set() * @uses adverts_config_save() * @uses adverts_request() * * @since 0.1 * @return void */ function adverts_admin_page_extensions() { // We are on one of Adverts admin pages, load default Adverts admin styles. wp_enqueue_style('adverts-admin'); // Load modules config $module = adverts_config('module'); $module_groups = array(array("title" => __("Modules", "adverts"), "modules" => array("core" => array("title" => __("Core", "adverts"), "text" => __("Here you can configure most basic Adverts options, applicable on any site.", "adverts"), "type" => "static", "plugin" => null), "payments" => array("title" => __("Payments", "adverts"), "text" => __("Charge users for posting classified ads on your site.", "adverts"), "type" => "", "plugin" => null), "wc-payments" => array("title" => __("WooCommerce Payments", "adverts"), "text" => __("Use WooCommerce to charge users for posting classifieds.", "adverts"), "type" => "", "plugin" => "wpadverts-wc/wpadverts-wc.php", "purchase_url" => "http://wpadverts.com/extensions/woocommerce-integration/"))), array("title" => __("Features", "adverts"), "modules" => array("featured" => array("title" => __("Featured Ads", "adverts"), "text" => __("Allow users to post Ads displayed always at the top of the list.", "adverts"), "type" => "", "plugin" => null), "wpadverts-mal" => array("title" => __("Maps And Locations", "adverts"), "text" => __("Locations Taxonomy, Google Maps integration and more.", "adverts"), "type" => "", "plugin" => "wpadverts-mal/wpadverts-mal.php", "purchase_url" => "http://wpadverts.com/extensions/maps-and-locations/"))), array("title" => __("Payment Gateways", "adverts"), "modules" => array("bank-transfer" => array("title" => __("Bank Transfer", "adverts"), "text" => __("Allow users to pay for ad posting using direct bank transfer or cash payments.", "adverts"), "type" => "", "plugin" => null), "paypal-standard" => array("title" => __("PayPal Standard", "adverts"), "text" => __("PayPal Payments Standard, allow users to pay for ads via PayPal.", "adverts"), "type" => "", "plugin" => "wpadverts-paypal-standard/wpadverts-paypal-standard.php", "purchase_url" => "http://wpadverts.com/extensions/paypal-payments-standard/")))); if (adverts_request('enable')) { // User is trying to enable module $enable = adverts_request('enable'); $module[$enable] = 0.5; // Save config adverts_config_set('config.module', $module); adverts_config_save('config'); wp_redirect(add_query_arg(array('enable' => false, 'noheader' => false, 'module' => $enable))); exit; } if (adverts_request('disable')) { // User is trying to disable module $disable = adverts_request('disable'); if (isset($module[$disable])) { unset($module[$disable]); } // Save config adverts_config_set('config.module', $module); adverts_config_save('config'); wp_redirect(remove_query_arg(array('disable', 'noheader'))); exit; } if (adverts_request('module')) { // Load module (based on $_GET[module]) panel $name = adverts_request('module'); $module_current = null; $module_key = null; foreach ($module_groups as $group) { foreach ($group["modules"] as $key => $tmp) { if ($key == $name) { $module_current = $tmp; $module_key = $key; break 2; } } } if ($module_current === null) { esc_html_e(sprintf(__("Module [%s] does not exist.", "adverts"), $name)); return; } if ($module_current["plugin"]) { include_once dirname(ADVERTS_PATH) . '/' . dirname($module_current["plugin"]) . '/includes/admin-module-options.php'; } else { include_once ADVERTS_PATH . 'addons/' . $module_key . '/includes/admin-module-options.php'; } } else { // Display modules list template include ADVERTS_PATH . 'admin/options.php'; } }
/** * Applies search by taxonomy if taxonomy param is present in $_GET. * * This function uses alt_term_links_config() to check if any of the registered * taxonomies param is in the current ($_GET] url. If it is then search by * this taxonomy is applied to [adverts_list] WP_Query. * * @since 1.0 * @access public * @param array $args [adverts_list] WP_Query arguments * @return array Customized WP_Query args. */ function alt_term_links_search($args) { foreach (alt_term_links_config() as $conf) { $var = adverts_request($conf["param"]); if (!empty($var)) { $args["tax_query"] = _alt_term_links_search_apply($conf, $var, $args["tax_query"]); } } return $args; }
/** * Adds search by price params to WP_Query * * The query is modified only if $_GET['price_min'] or $_GET['price_max'] * is greater than 0. * * @param array $args WP_Query args * @return array Modified WP_Query args */ function search_by_price_query($args) { if (adverts_request('price_min')) { $args["meta_query"][] = array('key' => 'adverts_price', 'value' => adverts_filter_money(adverts_request('price_min')), 'compare' => '>=', 'type' => 'DECIMAL(12,2)'); } if (adverts_request('price_max')) { $args["meta_query"][] = array('key' => 'adverts_price', 'value' => adverts_filter_money(adverts_request('price_max')), 'compare' => '<=', 'type' => 'DECIMAL(12,2)'); } return $args; }
/** * AJAX Function renders payment form in [adverts_add] third step. * * This function renders a proper payment form based on $_REQUEST['gateway'] value * and echos it to the browser as a JSON code. * * @since 0.1 * @return void */ function adext_payments_ajax_render() { $gateway_name = adverts_request('gateway'); $gateway = adext_payment_gateway_get($gateway_name); $listing_id = adverts_request("listing_id"); $response = null; $data = array(); $data["page_id"] = adverts_request("page_id"); $data["listing_id"] = adverts_request("listing_id"); $data["object_id"] = adverts_request("object_id"); $data["payment_for"] = "post"; $data["gateway_name"] = $gateway_name; $data["bind"] = array(); foreach (adverts_request('form', array()) as $item) { $data["bind"][$item["name"]] = $item["value"]; } $form = new Adverts_Form(); $form->load($gateway["form"]["payment_form"]); $form->bind($data["bind"]); if (isset($data["bind"]) && !empty($data["bind"])) { $isValid = $form->validate(); if ($isValid) { $pricing = get_post($data["listing_id"]); $price = get_post_meta($listing_id, "adverts_price", true); $payment_data = array('post_title' => $form->get_value("adverts_person"), 'post_content' => '', 'post_status' => 'pending', 'post_type' => 'adverts-payment'); $meta = array("pricing" => array("post_title" => $pricing->post_title, "visible" => get_post_meta($pricing->ID, "adverts_visible", true))); $payment_id = wp_insert_post($payment_data); update_post_meta($payment_id, 'adverts_person', $form->get_value('adverts_person')); update_post_meta($payment_id, 'adverts_email', $form->get_value('adverts_email')); update_post_meta($payment_id, '_adverts_user_ip', adverts_get_ip()); update_post_meta($payment_id, '_adverts_user_id', wp_get_current_user()->ID); update_post_meta($payment_id, '_adverts_object_id', $data["object_id"]); update_post_meta($payment_id, '_adverts_pricing_id', $data["listing_id"]); update_post_meta($payment_id, '_adverts_payment_gateway', $data["gateway_name"]); update_post_meta($payment_id, '_adverts_payment_for', $data["payment_for"]); update_post_meta($payment_id, '_adverts_payment_paid', "0"); update_post_meta($payment_id, '_adverts_payment_total', $price); update_post_meta($payment_id, '_adverts_payment_meta', $meta); $data["price"] = $price; $data["form"] = $form->get_values(); $data["payment_id"] = $payment_id; $data = apply_filters("adverts_payments_order_create", $data); $response = call_user_func($gateway["callback"]["render"], $data); } } if ($response === null) { ob_start(); include ADVERTS_PATH . 'templates/form.php'; $html_form = ob_get_clean(); $response = array("result" => 0, "html" => $html_form, "execute" => null); } echo json_encode($response); exit; }
/** * Sets default values for Bank Transfer form * * This function checks if current payment form is Bank Transfer. If so and * the $data is empty then we set default values for contact person and email fields. * * @param Adverts_Form $form Instance of form. * @param array $data User submitted form values ( key => value ) * @return Adverts_Form Modified instance of form. */ function adext_bank_transfer_form_bind_defaults(Adverts_Form $form, $data) { $scheme = $form->get_scheme(); if ($scheme["name"] != "adverts-bank-transfer") { return $form; } if (empty($data) && adverts_request("action") == "adext_payments_render") { $ad = get_post(adverts_request("object_id")); $form->set_value("adverts_person", get_post_meta($ad->ID, "adverts_person", true)); $form->set_value("adverts_email", get_post_meta($ad->ID, "adverts_email", true)); } return $form; }
/** * Renders Payments History List and Edit Page. * * The page is rendered in wp-admin / Classifieds / Payments History panel * * @global wpdb $wpdb * @global wp_locale $wp_locale * * @since 0.1 * @return void */ function adext_payments_page_history() { global $wpdb, $wp_locale; wp_enqueue_style('adverts-admin'); $flash = Adverts_Flash::instance(); if (adverts_request("add")) { // Do nothing currently users cannot add pricing manually. } elseif (adverts_request("edit")) { // Display payment edit page. $payment = get_post(adverts_request("edit")); $form = new Adverts_Form(); $form->load(Adverts::instance()->get("form_payments_history")); $form->bind(Adverts_Post::to_array($payment)); $gateway_name = get_post_meta($payment->ID, '_adverts_payment_gateway', true); $gateway = adext_payment_gateway_get($gateway_name); if (!$gateway) { $msg = sprintf(__("Payment Method [%s] assigned to this Payment does not exist or was disabled.", "adverts"), $gateway_name); $flash->add_error($msg); } if (isset($_POST) && !empty($_POST)) { $form->bind(stripslashes_deep($_POST)); $valid = $form->validate(); if ($valid) { $status_new = $form->get_value("post_status"); $status_old = $payment->post_status; $post_id = Adverts_Post::save($form, $payment); if (is_numeric($post_id) && $post_id > 0 && $status_old != $status_new) { do_action("adverts_payment_" . $status_new, $payment); $text = __('<strong>%1$s</strong> changed payment status to <strong>%2$s</strong>', 'adverts'); $message = sprintf($text, wp_get_current_user()->user_login, $status_new); adext_payments_log($post_id, $message); $payment = get_post($post_id); } if (is_wp_error($post_id)) { $flash->add_error($post_id->get_error_message()); } elseif ($post_id === 0) { $flash->add_error(__("There was an error while saving pricing in database.", "adverts")); } else { $flash->add_info(__("Payment updated.", "adverts")); } } else { $flash->add_error(__("There are errors in your form.", "adverts")); } } include ADVERTS_PATH . 'addons/payments/admin/payment-history-edit.php'; } elseif (adverts_request('delete')) { // Delete Payment $post = get_post(adverts_request('delete')); $i = 0; if (!$post || $post->post_type != 'adverts-payment') { wp_die(__('Adverts Payment with given ID does not exist.', 'adverts')); } foreach (get_children($post) as $child) { wp_delete_attachment($child->ID, true); $i++; } $flash->add_info(sprintf(_n("1 Payment deleted.", "%s Payments deleted.", $i, "adverts"), $i)); wp_delete_post($post->ID, true); wp_redirect(remove_query_arg(array('delete', 'noheader', 'pg'))); exit; } elseif (adverts_request('filter_action')) { // Apply filters and return to payments history list $url = remove_query_arg(array('delete', 'noheader', 'pg')); $url = add_query_arg(array('month' => adverts_request('month')), $url); wp_redirect($url); exit; } elseif (adverts_request('action') || adverts_request('action2')) { // Apply bulk actions and return to payments history list $action = adverts_request('action'); if (empty($action)) { $action = adverts_request('action2'); } $item = adverts_request('item'); foreach ($item as $id) { if ($action == "delete") { foreach (get_children($id) as $child) { wp_delete_attachment($child->ID, true); } wp_delete_post($id, true); $flash->add_info(__("Payments deleted.", "adverts")); } elseif (stripos($action, "set-status-") === 0) { $status_old = get_post_status($id); $status_new = str_replace("set-status-", "", $action); $status_obj = get_post_status_object($status_new); if ($status_old != $status_new) { wp_update_post(array("ID" => $id, "post_status" => $status_new)); do_action("adverts_payment_" . $status_new, $payment); } $flash->add_info(sprintf(__("Status for selected Payments was changed to: %s"), $status_obj->label)); } } wp_redirect(remove_query_arg(array('delete', 'noheader', 'pg'))); exit; } else { // Display Payments History $status_list = array("pending" => 0, "completed" => 0, "failed" => 0, "refunded" => 0); foreach ($status_list as $k => $v) { $sql = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = %s AND post_type = 'adverts-payment'"; $status_list[$k] = (int) $wpdb->get_var($wpdb->prepare($sql, $k)); } $sql = "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM {$wpdb->posts} WHERE post_type = %s ORDER BY post_date DESC"; $months_list = $wpdb->get_results($wpdb->prepare($sql, 'adverts-payment')); $months = array(); foreach ($months_list as $m) { $months[] = array("value" => $m->year . "-" . $m->month, "label" => sprintf(__('%1$s %2$d'), $wp_locale->get_month($m->month), $m->year)); } $month = adverts_request("month", ""); $filter = adverts_request("status", ""); $loop_params = array('post_type' => 'adverts-payment', 'posts_per_page' => 20, 'paged' => adverts_request('pg', 1)); if ($filter) { $loop_params['post_status'] = $filter; } if ($month == "this-month") { $before = date('Y-m-d H:i:s', strtotime('last day of this month', current_time('timestamp'))); $after = date('Y-m-d H:i:s', strtotime('first day of this month', current_time('timestamp'))); $loop_params['date_query'] = array(array('before' => $before, 'after' => $after, 'inclusive' => true)); } elseif ($month == "last-month") { $before = date('Y-m-d H:i:s', strtotime('last day of last month', current_time('timestamp'))); $after = date('Y-m-d H:i:s', strtotime('first day of last month', current_time('timestamp'))); $loop_params['date_query'] = array(array('before' => $before, 'after' => $after, 'inclusive' => true)); } elseif (!empty($month)) { $time = strtotime($month . "-10"); $before = date('Y-m-d', strtotime('last day of this month', $time)); $after = date('Y-m-d H:i:s', strtotime('first day of this month', $time)); $loop_params['date_query'] = array(array('before' => '', 'after' => '', 'inclusive' => true)); } $loop = new WP_Query($loop_params); include ADVERTS_PATH . 'addons/payments/admin/payment-history-list.php'; } }
/** * Delete Advert * * This action is executed by ad poster in the frontend (from the [adverts_manage] shortcode). * * No Priv * Action: adverts_delete * * @since 0.1 * @return void */ function adverts_delete() { $id = adverts_request("id"); $post = get_post($id); // check if post exists if (!$post) { echo 1; exit; } // check if current user is post author if ($post->post_author != get_current_user_id()) { echo 2; exit; } // check if post is an advert if ($post->post_type != 'advert') { echo 3; exit; } $param = array('post_parent' => $id, 'post_type' => 'attachment'); $children = get_posts($param); // also delete all uploaded files if (is_array($children)) { foreach ($children as $attch) { wp_delete_attachment($attch->ID, true); } } wp_delete_post($id, true); if (adverts_request("redirect_to")) { wp_redirect(adverts_request("redirect_to")); } exit; }
/** * Adds "author" param to [adverts_list] WP_Query. * * This function filters Ads by "author" param (provided in $_GET['posted_by']), * it is applied using "adverts_list_query" filter * * @see adverts_list_query filter in wpadverts/includes/shortcodes.php * * @param string $pbase Default pagination base * @since 1.0 * @return string Updated pagination base */ function ads_by_author_query($args) { $args["author"] = intval(adverts_request("posted_by")); return $args; }
/** * Form gallery field renderer * * Prints (to browser) HTML for for gallery field. * * @param array $field Should be an empty array * @since 0.1 * @return void */ function adverts_field_gallery($field) { include_once ADVERTS_PATH . "includes/gallery.php"; wp_enqueue_script('adverts-gallery'); $post_id = adverts_request("_post_id", adverts_request("advert_id")); $post = $post_id > 0 ? get_post($post_id) : null; adverts_gallery_content($post, array("button_class" => "adverts-button", "post_id_input" => "#_post_id")); }
/** * Sets menu_order in WP_Post when updating Advert. * * @see wp_insert_post_data filter * * @param array $data WP_Post data to be saved * @param array $postarr $_POST data submitted using form * @since 1.0.3 * @return array Updated WP_Post data */ function adext_featured_post_data($data, $postarr) { global $pagenow; $nonce = 'adext_featured_nonce'; $nonce_action = '_adext_is_featured_nonce'; if (!in_array($pagenow, array("post.php", "post-new.php"))) { return $data; } if (!isset($_POST[$nonce_action]) || !wp_verify_nonce($_POST[$nonce_action], $nonce)) { return $data; } if ($data["post_type"] != 'advert') { return $data; } if (defined("DOING_AJAX") && DOING_AJAX) { return $data; } $data["menu_order"] = intval(adverts_request("_is_featured")); return $data; }
/** * Forces featured image when adding new Ad using [adverts_add]. * * @uses force_featured_image() * * @param string $content Page content * @return string */ function force_featured_image_add($content) { $post_id = adverts_request("_post_id", null); force_featured_image($post_id); return $content; }
/** * Payment action * * This function is executed when "payment" action is run shortcode_adverts_add * * @see shortcode_adverts_add() * @since 1.0 * * $param string $content * @param Adverts_Form $form * @return null */ function adext_payments_action_payment($content, Adverts_Form $form) { $info[] = __("Thank you for submitting your ad!", "adverts"); $error = array(); wp_enqueue_script('adext-payments'); $adverts_flash = array("error" => $error, "info" => $info); $post_id = adverts_request("_post_id"); $post = get_post($post_id); wp_update_post(array("ID" => $post_id, "post_status" => "advert-pending")); if (!is_user_logged_in() && get_post_meta($post_id, "_adverts_account", true) == 1) { adverts_create_user_from_post_id($post_id, true); } $listing_id = get_post_meta($post_id, "payments_listing_type", true); $listing = get_post($listing_id); $price = get_post_meta($listing_id, 'adverts_price', true); ob_start(); include ADVERTS_PATH . 'addons/payments/templates/add-payment.php'; return ob_get_clean(); }
/** * Adds tax_query param to WP_Query * * The tax_query is added only if it is in $_GET['advert_example'] * * @param array $args WP_Query args * @return array Modified WP_Query args */ function custom_taxonomies_query($args) { if (!adverts_request("advert_example")) { return $args; } $args["tax_query"] = array(array('taxonomy' => 'advert_example', 'field' => 'term_id', 'terms' => adverts_request("advert_example"))); return $args; }
?> </td> <?php do_action('adext_payment_list_tbody', $item); ?> </tr> <?php } ?> </tbody> </table> <div class="tablenav"> <div class="tablenav-pages"> <?php echo paginate_links(array('base' => remove_query_arg('pg') . "%_%", 'format' => '&pg=%#%', 'prev_text' => __('«'), 'next_text' => __('»'), 'current' => max(1, adverts_request('pg', 1)), 'total' => $loop->max_num_pages)); ?> </div> <div class="alignleft actions"> <select name="action2" id="wpjb-action2"> <option selected="selected" value=""><?php _e("Bulk Actions", "adverts"); ?> </option> <?php foreach (array("pending", "completed", "failed", "refunded") as $status) { ?> <option value="set-status-<?php echo $status;
<?php // Exit if accessed directly if (!defined('ABSPATH')) { exit; } if (adverts_request('adaction') == null) { adext_payments_page_options(); } else { adext_payments_page_pricing(); }
/** * Generates HTML for ad edit form (in [adverts_manage] shortcode) * * @param array $atts Shortcode attributes * @since 0.1 * @return void * @access private */ function _adverts_manage_edit($atts) { wp_enqueue_style('adverts-frontend'); wp_enqueue_style('adverts-icons'); wp_enqueue_style('adverts-icons-animate'); wp_enqueue_script('adverts-frontend'); wp_enqueue_script('adverts-auto-numeric'); extract(shortcode_atts(array('name' => 'default', 'moderate' => false), $atts)); include_once ADVERTS_PATH . 'includes/class-html.php'; include_once ADVERTS_PATH . 'includes/class-form.php'; $form = new Adverts_Form(Adverts::instance()->get("form")); $valid = null; $error = array(); $info = array(); $bind = array(); $action = apply_filters('adverts_action', adverts_request("_adverts_action", ""), __FUNCTION__); $post_id = adverts_request("advert_id", null); // $post_id hijack attempt protection here! $post = get_post($post_id); if ($post === null) { $error[] = __("Ad does not exist.", "adverts"); adverts_flash(array("error" => $error)); return; } if ($post->post_author != get_current_user_id()) { $error[] = __("You do not own this Ad.", "adverts"); adverts_flash(array("error" => $error)); return; } $slist = apply_filters("adverts_sh_manage_list_statuses", array('publish', 'expired', 'pending', 'draft')); if (!in_array($post->post_status, $slist)) { $error[] = sprintf(__("Incorrect post status [%s].", "adverts"), $post->post_status); adverts_flash(array("error" => $error)); return; } foreach ($form->get_fields() as $f) { $bind[$f["name"]] = get_post_meta($post_id, $f["name"], true); } $bind["_adverts_action"] = "update"; $bind["_post_id"] = $post_id; $bind["post_title"] = $post->post_title; $bind["post_content"] = $post->post_content; $bind["advert_category"] = array(); $terms = get_the_terms($post_id, 'advert_category'); if (is_array($terms)) { foreach ($terms as $term) { $bind["advert_category"][] = $term->term_id; } } $form->bind($bind); if ($action == "update") { $form->bind((array) stripslashes_deep($_POST)); $valid = $form->validate(); if ($valid) { $post_id = Adverts_Post::save($form, $post_id); if (is_wp_error($post_id)) { $error[] = $post_id->get_error_message(); } else { $info[] = __("Post has been updated.", "adverts"); } } else { $error[] = __("Cannot update. There are errors in your form.", "adverts"); } } $adverts_flash = array("error" => $error, "info" => $info); // adverts/templates/manage-edit.php include apply_filters("adverts_template_load", ADVERTS_PATH . 'templates/manage-edit.php'); }
/** * AJAX License validation * * This function is executed from /wp-admin/admin-ajax.php it handles * license key validation. * * @see wp_ajax_adverts_license_validate_$slug action * @see self::connect() * * @access public * @since 1.0 * @return void */ public function validate_license() { $license = trim(adverts_request("license")); $update = false; $response = new stdClass(); $response->status = 200; $response->error = ""; $response->message = ""; if (!empty($license)) { $request = $this->remote("license", array("license" => $license)); if ($request === false) { $response->status = 400; $response->message = __("Cannot connect to remote server. Please try again later.", "adverts"); } elseif ($request->result == 1) { $update = true; } else { $response->status = $request->result; $response->message = $request->message; } } else { $license = null; $update = true; } if ($update) { $config = adverts_config('config.license'); $config[$this->slug] = $license; adverts_config_set('config.license', $config); adverts_config_save('config'); } $transient = get_site_transient("update_plugins"); if ($update && $license === null && isset($transient->response[$this->plugin])) { unset($transient->checked[$this->plugin]); unset($transient->response[$this->plugin]); set_site_transient("update_plugins", $transient); } echo json_encode($response); exit; }
/** * AJAX action mal_sync * * @global wpdb $wpdb * @since 1.0 * @access public * @return void */ function mal_sync_ajax() { global $wpdb; $x = 4; $offset = absint(adverts_request("offset")); $completed = 0; $query = new WP_Query(array('post_type' => 'advert', 'posts_per_page' => $x, 'offset' => $offset)); $total = $query->found_posts; $posts = array(); if ($total <= $offset + $x) { $completed = 1; } foreach ($query->posts as $post) { $geo_type = null; $meta_lat = number_format(get_post_meta($post->ID, "_adverts_mal_latitude", true), "15", ".", ""); $meta_lng = number_format(get_post_meta($post->ID, "_adverts_mal_longitude", true), "15", ".", ""); $terms = wp_get_post_terms($post->ID, "advert_location"); $term_lat = null; $term_lng = null; if (isset($terms[0])) { $term_lat = number_format(get_term_meta($terms[0]->term_id, "_wpadverts_mal_geo_lat", true), "15", ".", ""); $term_lng = number_format(get_term_meta($terms[0]->term_id, "_wpadverts_mal_geo_lng", true), "15", ".", ""); } $latlng = wpadverts_mal_get_latlng($post->ID); if ($meta_lat && $meta_lng) { $geo_type = "autocomplete"; $geo_update = mal_sync_ajax_update($post->ID, $meta_lat, $meta_lng, $latlng, "post"); } elseif ($term_lat && $term_lng) { $geo_type = "dropdown"; $geo_update = mal_sync_ajax_update($post->ID, $term_lat, $term_lng, $latlng, "term"); } else { $geo_type = "none"; $geo_update = mal_sync_ajax_delete($post->ID); } $posts[] = array("ID" => $post->ID, "post_title" => $post->post_title, "admin_url" => admin_url(sprintf("post.php?post=%d&action=edit", $post->ID)), "update_type" => $geo_update["type"], "update_message" => $geo_update["message"]); } if ($completed) { // cleanup DB $wpdb->query("DELETE FROM {$wpdb->prefix}mal_latlng WHERE (SELECT `ID` FROM {$wpdb->prefix}posts WHERE `post_id` = `ID`) IS NULL"); } echo json_encode(array("total" => $total, "offset" => $offset + $x, "completed" => $completed, "posts" => $posts)); exit; }