Exemplo n.º 1
0
 /**
  * Delete row from CartoDB
  * 
  * AJAX handler for removing all geo data. Deletes both CartoDB record and all geo data stored in wp_postmeta.
  *
  * @since 0.1.0
  * @return string $message Reponse message indicating success or error
  */
 public static function cartopress_delete_row()
 {
     // checks the referer to ensure authorized access
     if (!isset($_POST['cartopress_delete_row_nonce']) || !wp_verify_nonce($_POST['cartopress_delete_row_nonce'], 'cartopress_delete_row_nonce')) {
         die('Unauthorized access denied.');
     }
     $post_id = $_POST['post_id'];
     $sql_delete = 'DELETE FROM ' . CARTOPRESS_TABLE . ' WHERE cp_post_id = ' . $post_id;
     $results = cartopress_sync::update_cartodb($sql_delete, CARTOPRESS_APIKEY, CARTOPRESS_USERNAME, true);
     if ($results && $results->total_rows == 1) {
         $message = "success";
     } else {
         $message = "An unknown error occured: " . $results;
     }
     delete_post_meta($post_id, '_cp_post_geo_data');
     die(print_r($message, true));
 }
Exemplo n.º 2
0
 /**
  * Handle the custom Bulk Action
  * 
  * Uses switch/case to either delete from CartoDB, restore to CartoDB, or update postmeta with CartoDB data. Does not effect any WordPress core data. Based on the post http://wordpress.stackexchange.com/questions/29822/custom-bulk-action
  * 
  * @since 0.1.0
  */
 function custom_bulk_action()
 {
     global $typenow;
     $pagenow;
     $post_type = $typenow;
     if ($post_type == 'post' || $post_type == 'page') {
         // get the action
         $wp_list_table = _get_list_table('WP_Posts_List_Table');
         // depending on your resource type this could be WP_Users_List_Table, WP_Comments_List_Table, etc
         $action = $wp_list_table->current_action();
         $allowed_actions = array("cartopress_delete", "cartopress_restore", "cartopress_update");
         if (!in_array($action, $allowed_actions)) {
             return;
         }
         // security check
         check_admin_referer('bulk-posts');
         // make sure ids are submitted.  depending on the resource type, this may be 'media' or 'ids'
         if (isset($_REQUEST['post'])) {
             $post_ids = array_map('intval', $_REQUEST['post']);
         }
         if (empty($post_ids)) {
             return;
         }
         // this is based on wp-admin/edit.php
         $sendback = remove_query_arg(array('cartopress_deleted', 'cartopress_restored', 'cartopress_updated', 'untrashed', 'deleted', 'ids'), wp_get_referer());
         if (!$sendback) {
             $sendback = admin_url("edit.php?post_type={$post_type}");
         }
         $pagenum = $wp_list_table->get_pagenum();
         $sendback = add_query_arg('paged', $pagenum, $sendback);
         switch ($action) {
             case 'cartopress_delete':
                 $sql_distinct = 'SELECT DISTINCT cp_post_id FROM ' . CARTOPRESS_TABLE;
                 $cartopress_ids = cartopress_sync::update_cartodb($sql_distinct, CARTOPRESS_APIKEY, CARTOPRESS_USERNAME, true);
                 $cartopress_ids = $cartopress_ids->rows;
                 $temp = array();
                 foreach ($cartopress_ids as $key => $value) {
                     array_push($temp, $value->cp_post_id);
                 }
                 $deleted = 0;
                 foreach ($post_ids as $post_id) {
                     if (in_array($post_id, $temp)) {
                         cartopress_sync::cartodb_delete($post_id);
                         $deleted++;
                     } else {
                         return false;
                     }
                 }
                 $sendback = add_query_arg(array('cartopress_deleted' => $deleted, 'ids' => join(',', $post_ids)), $sendback);
                 break;
             case 'cartopress_restore':
                 $restored = 0;
                 foreach ($post_ids as $post_id) {
                     cartopress_sync::cartodb_sync($post_id);
                     $restored++;
                 }
                 $sendback = add_query_arg(array('cartopress_restored' => $restored, 'ids' => join(',', $post_ids)), $sendback);
                 break;
             case 'cartopress_update':
                 $updated = 0;
                 foreach ($post_ids as $post_id) {
                     cartopress_sync::cartopress_update_postmeta($post_id);
                     $updated++;
                 }
                 $sendback = add_query_arg(array('cartopress_updated' => $updated, 'ids' => join(',', $post_ids)), $sendback);
                 break;
             default:
                 return;
         }
         $sendback = remove_query_arg(array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback);
         wp_redirect($sendback);
         exit;
     }
     //end
 }