Пример #1
0
 /**
  * Handle Ajax callback for permanent delete of post.
  */
 public function permanent_delete_post()
 {
     $post_id = (int) $_POST['post_id'];
     $action = 'delete_post_' . $post_id;
     if (!ap_verify_nonce($action) || !ap_user_can_permanent_delete()) {
         $this->something_wrong();
     }
     $post = get_post($post_id);
     wp_trash_post($post_id);
     if ($post->post_type == 'question') {
         do_action('ap_wp_trash_question', $post_id);
     } else {
         do_action('ap_wp_trash_answer', $post_id);
     }
     wp_delete_post($post_id, true);
     if ($post->post_type == 'question') {
         $this->send(array('action' => 'delete_question', 'do' => array('redirect' => ap_base_page_link()), 'message' => 'question_deleted_permanently'));
     } else {
         $current_ans = ap_count_published_answers($post->post_parent);
         $count_label = sprintf(_n('1 Answer', '%d Answers', $current_ans, 'anspress-question-answer'), $current_ans);
         $remove = !$current_ans ? true : false;
         $this->send(array('action' => 'delete_answer', 'div_id' => '#answer_' . $post_id, 'count' => $current_ans, 'count_label' => $count_label, 'remove' => $remove, 'message' => 'answer_deleted_permanently', 'view' => array('answer_count' => $current_ans, 'answer_count_label' => $count_label)));
     }
 }
Пример #2
0
function ap_post_permanent_delete_btn_html($post_id = false, $echo = false)
{
    if ($post_id === false) {
        $post_id = get_the_ID();
    }
    if (ap_user_can_permanent_delete()) {
        $action = 'delete_post_' . $post_id;
        $nonce = wp_create_nonce($action);
        $output = '<a href="#" class="delete-btn" data-action="ap_delete_post" data-query="post_id=' . $post_id . '&__nonce=' . $nonce . '&ap_ajax_action=permanent_delete_post" title="' . __('Delete permanently', 'ap') . '">' . __('Delete permanently', 'ap') . '</a>';
        if ($echo) {
            echo $output;
        } else {
            return $output;
        }
    }
}