$my_ad = array(); $my_ad['ID'] = $aid; $my_ad['post_status'] = 'draft'; wp_update_post($my_ad); $action_msg = __('Ad has been paused', 'appthemes'); } elseif ($d == 'restart') { $my_ad = array(); $my_ad['ID'] = $aid; $my_ad['post_status'] = 'publish'; wp_update_post($my_ad); $action_msg = __('Ad has been published', 'appthemes'); } elseif ($d == 'delete') { cp_delete_ad_listing($aid); $action_msg = __('Ad has been deleted', 'appthemes'); } elseif ($d == 'freerenew') { cp_renew_ad_listing($aid); $action_msg = __('Ad has been relisted', 'appthemes'); } elseif ($d == 'setSold') { update_post_meta($aid, 'cp_ad_sold', 'yes'); $action_msg = __('Ad has been marked as sold', 'appthemes'); } elseif ($d == 'unsetSold') { update_post_meta($aid, 'cp_ad_sold', 'no'); $action_msg = __('Ad has been unmarked as sold', 'appthemes'); } else { //echo "nothing here"; } } } ?> <?php
function template_redirect() { global $wpdb, $current_user; appthemes_auth_redirect_login(); // if not logged in, redirect to login page nocache_headers(); // check to see if we want to pause or restart the ad if (isset($_GET['action']) && !empty($_GET['action'])) { $d = trim($_GET['action']); $aid = trim($_GET['aid']); // make sure author matches ad. Prevents people from trying to hack other peoples ads $sql = $wpdb->prepare("SELECT wposts.post_author FROM {$wpdb->posts} wposts WHERE ID = %d AND post_author = %d", $aid, $current_user->ID); $checkauthor = $wpdb->get_row($sql); if ($checkauthor != null) { // author check is ok. now update ad status if ($d == 'pause') { $my_ad = array(); $my_ad['ID'] = $aid; $my_ad['post_status'] = 'draft'; wp_update_post($my_ad); $redirect_url = add_query_arg(array('paused' => 'true'), CP_DASHBOARD_URL); wp_redirect($redirect_url); exit; } elseif ($d == 'restart') { $my_ad = array(); $my_ad['ID'] = $aid; $my_ad['post_status'] = 'publish'; wp_update_post($my_ad); $redirect_url = add_query_arg(array('restarted' => 'true'), CP_DASHBOARD_URL); wp_redirect($redirect_url); exit; } elseif ($d == 'delete') { cp_delete_ad_listing($aid); $redirect_url = add_query_arg(array('deleted' => 'true'), CP_DASHBOARD_URL); wp_redirect($redirect_url); exit; } elseif ($d == 'freerenew') { cp_renew_ad_listing($aid); $redirect_url = add_query_arg(array('freerenewed' => 'true'), CP_DASHBOARD_URL); wp_redirect($redirect_url); exit; } elseif ($d == 'setSold') { update_post_meta($aid, 'cp_ad_sold', 'yes'); $redirect_url = add_query_arg(array('markedsold' => 'true'), CP_DASHBOARD_URL); wp_redirect($redirect_url); exit; } elseif ($d == 'unsetSold') { update_post_meta($aid, 'cp_ad_sold', 'no'); $redirect_url = add_query_arg(array('unmarkedsold' => 'true'), CP_DASHBOARD_URL); wp_redirect($redirect_url); exit; } } } add_action('appthemes_notices', array($this, 'show_notice')); }