Exemplo n.º 1
0
/**
 * Output chnage post status button.
 *
 * @param bool|int $post_id
 *
 * @return null|string
 */
function ap_post_change_status_btn_html($post_id = false)
{
    $post = get_post($post_id);
    if (ap_user_can_change_status($post_id)) {
        $action = 'change_post_status_' . $post_id;
        $nonce = wp_create_nonce($action);
        $status = apply_filters('ap_change_status_dropdown', array('closed' => __('Close', 'ap'), 'publish' => __('Open', 'ap'), 'moderate' => __('Moderate', 'ap'), 'private_post' => __('Private', 'ap')));
        $output = '<div class="ap-dropdown">
			<a class="ap-tip ap-dropdown-toggle" title="' . __('Change status of post', 'ap') . '" href="#" >
				' . __('Status', 'ap') . ' <i class="caret"></i>
			</a>
			<ul id="ap_post_status_toggle_' . $post_id . '" class="ap-dropdown-menu" role="menu">';
        foreach ($status as $k => $title) {
            $can = true;
            if ($k == 'closed' && (!ap_user_can_change_status_to_closed() || $post->post_type == 'answer')) {
                $can = false;
            } elseif ($k == 'moderate' && !ap_user_can_change_status_to_moderate()) {
                $can = false;
            }
            if ($can) {
                $output .= '<li class="' . $k . ($k == $post->post_status ? ' active' : '') . '">
						<a href="#" data-action="ap_change_status" data-query="post_id=' . $post_id . '&__nonce=' . $nonce . '&ap_ajax_action=change_post_status&status=' . $k . '">' . $title . '</a>
					</li>';
            }
        }
        $output .= '</ul>
		</div>';
        return $output;
    }
}
Exemplo n.º 2
0
 /**
  * Handle change post status request.
  * @since 2.1
  */
 public function change_post_status()
 {
     $post_id = (int) $_POST['post_id'];
     $status = sanitize_text_field(wp_unslash($_POST['status']));
     if (!is_user_logged_in() || !ap_verify_nonce('change_post_status_' . $post_id) || !ap_user_can_change_status($post_id)) {
         $this->send('no_permission');
     } else {
         $post = get_post($post_id);
         if (($post->post_type == 'question' || $post->post_type == 'answer') && $post->post_status != $status) {
             $update_data = array();
             if ('publish' == $status) {
                 $update_data['post_status'] = 'publish';
             } elseif ('moderate' == $status) {
                 $update_data['post_status'] = 'moderate';
             } elseif ('private_post' == $status) {
                 $update_data['post_status'] = 'private_post';
             } elseif ('closed' == $status) {
                 $update_data['post_status'] = 'closed';
             }
             // Unregister history action for edit.
             remove_action('ap_after_new_answer', array('AP_History', 'new_answer'));
             remove_action('ap_after_new_question', array('AP_History', 'new_question'));
             $update_data['ID'] = $post->ID;
             wp_update_post($update_data);
             ap_add_history(get_current_user_id(), $post_id, '', 'status_updated');
             add_action('ap_post_status_updated', $post->ID);
             ob_start();
             ap_post_status_description($post->ID);
             $html = ob_get_clean();
             $this->send(array('action' => 'status_updated', 'message' => 'status_updated', 'do' => array('remove_if_exists' => '#ap_post_status_desc_' . $post->ID, 'toggle_active_class' => array('#ap_post_status_toggle_' . $post->ID, '.' . $status), 'append_before' => '#ap_post_actions_' . $post->ID), 'html' => $html));
         }
     }
     $this->something_wrong();
 }
Exemplo n.º 3
0
 /**
  * Handle change post status request
  * @return void
  * @since 2.1
  */
 public function change_post_status()
 {
     $post_id = (int) $_POST['post_id'];
     $status = $_POST['status'];
     if (!is_user_logged_in() || !wp_verify_nonce($_POST['__nonce'], 'change_post_status_' . $post_id) || !ap_user_can_change_status($post_id)) {
         ap_send_json(ap_ajax_responce('no_permission'));
         die;
     } else {
         $post = get_post($post_id);
         if (($post->post_type == 'question' || $post->post_type == 'answer') && $post->post_status != $status) {
             $update_data = array();
             if ($status == 'publish') {
                 $update_data['post_status'] = 'publish';
             } elseif ($status == 'moderate') {
                 $update_data['post_status'] = 'moderate';
             } elseif ($status == 'private_post') {
                 $update_data['post_status'] = 'private_post';
             } elseif ($status == 'closed') {
                 $update_data['post_status'] = 'closed';
             }
             // unregister history action for edit
             remove_action('ap_after_new_answer', array('AP_History', 'new_answer'));
             remove_action('ap_after_new_question', array('AP_History', 'new_question'));
             $update_data['ID'] = $post->ID;
             wp_update_post($update_data);
             ap_add_history(get_current_user_id(), $post_id, '', 'status_updated');
             add_action('ap_post_status_updated', $post->ID);
             ob_start();
             ap_post_status_description($post->ID);
             $html = ob_get_clean();
             ap_send_json(ap_ajax_responce(array('action' => 'status_updated', 'message' => 'status_updated', 'do' => array('remove_if_exists', 'toggle_active_class', 'append_before'), 'append_before_container' => '#ap_post_actions_' . $post->ID, 'toggle_active_class_container' => '#ap_post_status_toggle_' . $post->ID, 'remove_if_exists_container' => '#ap_post_status_desc_' . $post->ID, 'active' => '.' . $status, 'html' => $html)));
             die;
         }
     }
     ap_send_json(ap_ajax_responce('something_wrong'));
     die;
 }