コード例 #1
0
ファイル: record.php プロジェクト: TakenCdosG/chefs
 /**
  * Clear associations with posts
  * @param bool[optional] $keepPosts When set to false associated wordpress posts will be deleted as well
  * @return PMXI_Import_Record
  * @chainable
  */
 public function deletePosts($keepPosts = TRUE, $is_deleted_images = 'auto', $is_delete_attachments = 'auto')
 {
     $post = new PMXI_Post_List();
     if (!$keepPosts) {
         $ids = array();
         foreach ($post->getBy('import_id', $this->id)->convertRecords() as $p) {
             $ids[] = $p->post_id;
         }
         if (!empty($ids)) {
             $this->deleteRecords($is_delete_attachments, $is_deleted_images, $ids);
         }
     }
     $this->wpdb->query($this->wpdb->prepare('DELETE FROM ' . $post->getTable() . ' WHERE import_id = %s', $this->id));
     return $this;
 }
コード例 #2
0
ファイル: record.php プロジェクト: k-hasan-19/wp-all-import
 /**
  * Clear associations with posts
  * @param bool[optional] $keepPosts When set to false associated wordpress posts will be deleted as well
  * @return PMXI_Import_Record
  * @chainable
  */
 public function deletePosts($keepPosts = TRUE, $is_deleted_images = 'auto', $is_delete_attachments = 'auto')
 {
     $post = new PMXI_Post_List();
     if (!$keepPosts) {
         $ids = array();
         foreach ($post->getBy('import_id', $this->id)->convertRecords() as $p) {
             // Remove attachments
             if ($is_delete_attachments == 'yes' or $is_delete_attachments == 'auto' and empty($this->options['is_keep_attachments'])) {
                 wp_delete_attachments($p->post_id, true, 'files');
             } else {
                 wp_delete_attachments($p->post_id, false, 'files');
             }
             // Remove images
             if ($is_deleted_images == 'yes' or $is_deleted_images == 'auto' and empty($this->options['is_keep_imgs'])) {
                 wp_delete_attachments($p->post_id, true, 'images');
             } else {
                 wp_delete_attachments($p->post_id, false, 'images');
             }
             $ids[] = $p->post_id;
         }
         if (!empty($ids)) {
             foreach ($ids as $id) {
                 do_action('pmxi_delete_post', $id);
                 if ($this->options['custom_type'] != 'import_users') {
                     wp_delete_object_term_relationships($id, get_object_taxonomies('' != $this->options['custom_type'] ? $this->options['custom_type'] : 'post'));
                 }
             }
             if ($this->options['custom_type'] == 'import_users') {
                 $sql = "delete a,b\n\t\t\t\t\tFROM " . $this->wpdb->users . " a\n\t\t\t\t\tLEFT JOIN " . $this->wpdb->usermeta . " b ON ( a.ID = b.user_id )\t\t\t\t\t\n\t\t\t\t\tWHERE a.ID IN (" . implode(',', $ids) . ");";
             } else {
                 $sql = "delete a,b,c\n\t\t\t\t\tFROM " . $this->wpdb->posts . " a\n\t\t\t\t\tLEFT JOIN " . $this->wpdb->term_relationships . " b ON ( a.ID = b.object_id )\n\t\t\t\t\tLEFT JOIN " . $this->wpdb->postmeta . " c ON ( a.ID = c.post_id )\n\t\t\t\t\tLEFT JOIN " . $this->wpdb->posts . " d ON ( a.ID = d.post_parent )\n\t\t\t\t\tWHERE a.ID IN (" . implode(',', $ids) . ");";
             }
             $this->wpdb->query($this->wpdb->prepare($sql, ''));
         }
     }
     $this->wpdb->query($this->wpdb->prepare('DELETE FROM ' . $post->getTable() . ' WHERE import_id = %s', $this->id));
     return $this;
 }
コード例 #3
0
ファイル: manage.php プロジェクト: TakenCdosG/chefs
 /**
  * Delete an import
  */
 public function delete()
 {
     $id = $this->input->get('id');
     $this->data['item'] = $item = new PMXI_Import_Record();
     if (!$id or $item->getById($id)->isEmpty()) {
         wp_redirect($this->baseUrl);
         die;
     }
     if ($this->input->post('is_confirmed')) {
         check_admin_referer('delete-import', '_wpnonce_delete-import');
         $is_deleted_images = $this->input->post('is_delete_images');
         $is_delete_attachments = $this->input->post('is_delete_attachments');
         $is_delete_import = $this->input->post('is_delete_import', false);
         $is_delete_posts = $this->input->post('is_delete_posts', false);
         if (!$is_delete_import and !$is_delete_posts) {
             wp_redirect(add_query_arg('pmxi_nt', urlencode(__('Nothing to delete.', 'wp_all_import_plugin')), $this->baseUrl));
             die;
         }
         do_action('pmxi_before_import_delete', $item, $is_delete_posts);
         $item->delete(!$is_delete_posts, $is_deleted_images, $is_delete_attachments, $is_delete_import);
         $redirect_msg = '';
         if ($is_delete_import and !$is_delete_posts) {
             $redirect_msg = __('Import deleted', 'wp_all_import_plugin');
         } elseif (!$is_delete_import and $is_delete_posts) {
             $redirect_msg = __('All associated posts deleted.', 'wp_all_import_plugin');
         } elseif ($is_delete_import and $is_delete_posts) {
             $redirect_msg = __('Import and all associated posts deleted.', 'wp_all_import_plugin');
         }
         wp_redirect(add_query_arg('pmxi_nt', urlencode($redirect_msg), $this->baseUrl));
         die;
     }
     $postList = new PMXI_Post_List();
     $this->data['associated_posts'] = count($postList->getBy(array('import_id' => $item->id)));
     $this->render();
 }