if (!nxt_untrash_post($post_id)) { nxt_die(__('Error in restoring from Trash.')); } $untrashed++; } $sendback = add_query_arg('untrashed', $untrashed, $sendback); break; case 'delete': $deleted = 0; foreach ((array) $post_ids as $post_id) { $post_del =& get_post($post_id); if (!current_user_can($post_type_object->cap->delete_post, $post_id)) { nxt_die(__('You are not allowed to delete this item.')); } if ($post_del->post_type == 'attachment') { if (!nxt_delete_attachment($post_id)) { nxt_die(__('Error in deleting...')); } } else { if (!nxt_delete_post($post_id)) { nxt_die(__('Error in deleting...')); } } $deleted++; } $sendback = add_query_arg('deleted', $deleted, $sendback); break; case 'edit': if (isset($_REQUEST['bulk_edit'])) { $done = bulk_edit_posts($_REQUEST); if (is_array($done)) {
/** * Cleanup importer. * * Removes attachment based on ID. * * @since 2.0.0 * * @param string $id Importer ID. */ function nxt_import_cleanup($id) { nxt_delete_attachment($id); }
/** * Trashes or deletes a post or page. * * When the post and page is permanently deleted, everything that is tied to it is deleted also. * This includes comments, post meta fields, and terms associated with the post. * * The post or page is moved to trash instead of permanently deleted unless trash is * disabled, item is already in the trash, or $force_delete is true. * * @since 1.0.0 * @uses do_action() on 'delete_post' before deletion unless post type is 'attachment'. * @uses do_action() on 'deleted_post' after deletion unless post type is 'attachment'. * @uses nxt_delete_attachment() if post type is 'attachment'. * @uses nxt_trash_post() if item should be trashed. * * @param int $postid Post ID. * @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false. * @return mixed False on failure */ function nxt_delete_post($postid = 0, $force_delete = false) { global $nxtdb, $nxt_rewrite; if (!($post = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->posts} WHERE ID = %d", $postid)))) { return $post; } if (!$force_delete && ($post->post_type == 'post' || $post->post_type == 'page') && get_post_status($postid) != 'trash' && EMPTY_TRASH_DAYS) { return nxt_trash_post($postid); } if ($post->post_type == 'attachment') { return nxt_delete_attachment($postid, $force_delete); } do_action('before_delete_post', $postid); delete_post_meta($postid, '_nxt_trash_meta_status'); delete_post_meta($postid, '_nxt_trash_meta_time'); nxt_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type)); $parent_data = array('post_parent' => $post->post_parent); $parent_where = array('post_parent' => $postid); if ('page' == $post->post_type) { // if the page is defined in option page_on_front or post_for_posts, // adjust the corresponding options if (get_option('page_on_front') == $postid) { update_option('show_on_front', 'posts'); delete_option('page_on_front'); } if (get_option('page_for_posts') == $postid) { delete_option('page_for_posts'); } // Point children of this page to its parent, also clean the cache of affected children $children_query = $nxtdb->prepare("SELECT * FROM {$nxtdb->posts} WHERE post_parent = %d AND post_type='page'", $postid); $children = $nxtdb->get_results($children_query); $nxtdb->update($nxtdb->posts, $parent_data, $parent_where + array('post_type' => 'page')); } else { unstick_post($postid); } // Do raw query. nxt_get_post_revisions() is filtered $revision_ids = $nxtdb->get_col($nxtdb->prepare("SELECT ID FROM {$nxtdb->posts} WHERE post_parent = %d AND post_type = 'revision'", $postid)); // Use nxt_delete_post (via nxt_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. foreach ($revision_ids as $revision_id) { nxt_delete_post_revision($revision_id); } // Point all attachments to this post up one level $nxtdb->update($nxtdb->posts, $parent_data, $parent_where + array('post_type' => 'attachment')); $comment_ids = $nxtdb->get_col($nxtdb->prepare("SELECT comment_ID FROM {$nxtdb->comments} WHERE comment_post_ID = %d", $postid)); if (!empty($comment_ids)) { do_action('delete_comment', $comment_ids); foreach ($comment_ids as $comment_id) { nxt_delete_comment($comment_id, true); } do_action('deleted_comment', $comment_ids); } $post_meta_ids = $nxtdb->get_col($nxtdb->prepare("SELECT meta_id FROM {$nxtdb->postmeta} WHERE post_id = %d ", $postid)); if (!empty($post_meta_ids)) { do_action('delete_postmeta', $post_meta_ids); $in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'"; $nxtdb->query("DELETE FROM {$nxtdb->postmeta} WHERE meta_id IN({$in_post_meta_ids})"); do_action('deleted_postmeta', $post_meta_ids); } do_action('delete_post', $postid); $nxtdb->query($nxtdb->prepare("DELETE FROM {$nxtdb->posts} WHERE ID = %d", $postid)); do_action('deleted_post', $postid); if ('page' == $post->post_type) { clean_page_cache($postid); foreach ((array) $children as $child) { clean_page_cache($child->ID); } $nxt_rewrite->flush_rules(false); } else { clean_post_cache($postid); } nxt_clear_scheduled_hook('publish_future_post', array($postid)); do_action('after_delete_post', $postid); return $post; }
function express_uploadFile($args) { global $nxtdb; global $nxt_xmlrpc_server; $blog_ID = (int) $args[0]; $username = $nxtdb->escape($args[1]); $password = $nxtdb->escape($args[2]); $data = $args[3]; $name = sanitize_file_name($data['name']); $type = $data['type']; $bits = $data['bits']; logIO('O', '(MW) Received ' . strlen($bits) . ' bytes'); if (!($user = $nxt_xmlrpc_server->login($username, $password))) { return $nxt_xmlrpc_server->error; } do_action('xmlrpc_call', 'metaWeblog.newMediaObject'); if (!current_user_can('upload_files')) { logIO('O', '(MW) User does not have upload_files capability'); return new IXR_Error(401, __('You are not allowed to upload files to this site.', 'woothemes')); } if ($upload_err = apply_filters("pre_upload_error", false)) { return new IXR_Error(500, $upload_err); } if (!empty($data["overwrite"]) && $data["overwrite"] == true) { // Get postmeta info on the object. $old_file = $nxtdb->get_row("\n\t\t\tSELECT ID\n\t\t\tFROM {$nxtdb->posts}\n\t\t\tWHERE post_title = '{$name}'\n\t\t\t\tAND post_type = 'attachment'\n\t\t"); // Delete previous file. nxt_delete_attachment($old_file->ID); // Make sure the new name is different by pre-pending the // previous post id. $filename = preg_replace("/^nxtid\\d+-/", "", $name); $name = "nxtid{$old_file->ID}-{$filename}"; } $upload = nxt_upload_bits($name, $type, $bits); if (!empty($upload['error'])) { $errorString = sprintf(__('Could not write file %1$s (%2$s)', 'woothemes'), $name, $upload['error']); logIO('O', '(MW) ' . $errorString); return new IXR_Error(500, $errorString); } // Construct the attachment array // attach to post_id 0 $post_id = 0; $attachment = array('post_title' => $name, 'post_content' => '', 'post_type' => 'attachment', 'post_parent' => $post_id, 'post_mime_type' => $type, 'guid' => $upload['url']); // Save the data $id = nxt_insert_attachment($attachment, $upload['file'], $post_id); nxt_update_attachment_metadata($id, nxt_generate_attachment_metadata($id, $upload['file'])); return apply_filters('nxt_handle_upload', array('file' => $name, 'url' => $upload['url'], 'type' => $type, 'id' => $id)); }
} if (!nxt_untrash_post($post_id)) { nxt_die(__('Error in restoring from Trash.')); } nxt_redirect(add_query_arg('untrashed', 1, $sendback)); exit; break; case 'delete': check_admin_referer('delete-' . $post_type . '_' . $post_id); if (!current_user_can($post_type_object->cap->delete_post, $post_id)) { nxt_die(__('You are not allowed to delete this item.')); } $force = !EMPTY_TRASH_DAYS; if ($post->post_type == 'attachment') { $force = $force || !MEDIA_TRASH; if (!nxt_delete_attachment($post_id, $force)) { nxt_die(__('Error in deleting.')); } } else { if (!nxt_delete_post($post_id, $force)) { nxt_die(__('Error in deleting.')); } } nxt_redirect(add_query_arg('deleted', 1, $sendback)); exit; break; case 'preview': check_admin_referer('autosave', 'autosavenonce'); $url = post_preview(); nxt_redirect($url); exit;
function cleanup() { if ($this->id) { nxt_delete_attachment($this->id); } elseif (file_exists($this->package)) { return @unlink($this->package); } return true; }