Ejemplo n.º 1
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
 }
Ejemplo n.º 2
0
/**
 * Delete function for attachment post type
 * 
 * @since 0.1.0
 * @param int $post_id The global post id.
 */
function cartopress_delete_attachment($post_id)
{
    $post_type = get_post_type($post_id);
    if ('attachment' === $post_type) {
        cartopress_sync::cartodb_delete($post_id);
    } else {
        return;
    }
}