/** * ajax plugin api, to check info of content */ function wtb_seo_api_callback() { $json = array(); $postCopy = $_POST; // hack for create autosave if (0) { // exclude for short time, to find out // why sometimes post_preview() trows wordpress error $post_ID = (int) $_POST['post']['post_ID']; $status = get_post_status($post_ID); if ('auto-draft' != $status) { $_POST = $_POST['post']; post_preview(); } } // end of hack $wpSlot = new wtb_seo_calculator($postCopy); $json['box'] = $wpSlot->generateBox()->render(); echo json_encode($json); die; // this is required to return a proper result }
} if ($post->post_type == 'attachment') { $force = !MEDIA_TRASH; if (!wp_delete_attachment($post_id, $force)) { wp_die(__('Error in deleting.')); } } else { if (!wp_delete_post($post_id, true)) { wp_die(__('Error in deleting.')); } } wp_redirect(add_query_arg('deleted', 1, $sendback)); exit; case 'preview': check_admin_referer('update-post_' . $post_id); $url = post_preview(); wp_redirect($url); exit; default: /** * Fires for a given custom post action request. * * The dynamic portion of the hook name, `$action`, refers to the custom post action. * * @since 4.6.0 * * @param int $post_id Post ID sent with the request. */ do_action("post_action_{$action}", $post_id); wp_redirect(admin_url('edit.php')); exit;
public function form_handler() { if (isset($_POST['post_ID'])) { require_once ABSPATH . '/wp-admin/includes/post.php'; $action = isset($_POST['action']) ? $_POST['action'] : ''; if (isset($_GET['post'])) { $post_id = $post_ID = (int) $_GET['post']; } elseif (isset($_POST['post_ID'])) { $post_id = $post_ID = (int) $_POST['post_ID']; } else { $post_id = $post_ID = 0; } $post = $post_type = $post_type_object = null; if ($post_id) { $post = get_post($post_id); } if ($post) { $post_type = $post->post_type; $post_type_object = get_post_type_object($post_type); } if (isset($_POST['deletepost'])) { $action = 'delete'; } elseif (isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview']) { $action = 'preview'; } $sendback = wp_get_referer(); if (!$sendback || strpos($sendback, 'post.php') !== false || strpos($sendback, 'post-new.php') !== false) { if ('attachment' == $post_type) { $sendback = admin_url('upload.php'); } else { $sendback = admin_url('edit.php'); $sendback .= !empty($post_type) ? '?post_type=' . $post_type : ''; } } else { $sendback = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'ids'), $sendback); } switch ($action) { case 'postajaxpost': case 'post': check_admin_referer('add-' . $post_type); $post_id = 'postajaxpost' == $action ? edit_post() : write_post(); $this->redirect_post($post_id); exit; break; case 'editpost': wp_verify_nonce('update-post_' . $post_id); $post_id = edit_post(); // Session cookie flag that the post was saved if (isset($_COOKIE['wp-saving-post-' . $post_id])) { setcookie('wp-saving-post-' . $post_id, 'saved'); } $this->redirect_post($post_id); // Send user on their way while we keep working exit; break; case 'trash': check_admin_referer('trash-post_' . $post_id); if (!$post) { wp_die(__('The item you are trying to move to the Trash no longer exists.')); } if (!$post_type_object) { wp_die(__('Unknown post type.')); } if (!current_user_can('delete_post', $post_id)) { wp_die(__('You are not allowed to move this item to the Trash.')); } if ($user_id = wp_check_post_lock($post_id)) { $user = get_userdata($user_id); wp_die(sprintf(__('You cannot move this item to the Trash. %s is currently editing.'), $user->display_name)); } if (!wp_trash_post($post_id)) { wp_die(__('Error in moving to Trash.')); } wp_redirect(add_query_arg(array('trashed' => 1, 'ids' => $post_id), $sendback)); exit; break; case 'preview': check_admin_referer('update-post_' . $post_id); $url = post_preview(); wp_redirect($url); exit; break; } // end switch } }