Exemple #1
0
 public function ap_load_edit_form()
 {
     $nonce = sanitize_text_field($_POST['nonce']);
     $post_id = sanitize_text_field($_POST['id']);
     $type = sanitize_text_field($_POST['type']);
     if (wp_verify_nonce($nonce, $type . '-' . $post_id)) {
         $post = get_post($post_id);
         if (ap_user_can_edit_question($post_id) && $post->post_type == 'question') {
             ob_start();
             ap_edit_question_form($post_id);
             $html = ob_get_clean();
             $result = array('action' => true, 'type' => 'question', 'message' => __('Form loaded.', 'ap'), 'html' => $html);
         } elseif (ap_user_can_edit_answer($post_id) && $post->post_type == 'answer') {
             ob_start();
             ap_edit_answer_form($post_id);
             $html = ob_get_clean();
             $result = array('action' => true, 'type' => 'answer', 'message' => __('Form loaded.', 'ap'), 'html' => $html);
         } else {
             $result = array('action' => false, 'message' => __('You do not have permission to edit this question.', 'ap'));
         }
     } else {
         $result = array('action' => false, 'message' => __('Something went wrong, please try again.', 'ap'));
     }
     die(json_encode($result));
 }
Exemple #2
0
/**
 * Post actions buttons
 * @return 	string
 * @param  array $disable
 * @return void
 * @since 	2.0
 */
function ap_post_actions_buttons($disable = array())
{
    global $post;
    if (!$post->post_type == 'question' || !$post->post_type == 'answer') {
        return;
    }
    $actions = array();
    /**
     * Select answer button
     * @var string
     */
    if ($post->post_type == 'answer') {
        $actions['select_answer'] = ap_select_answer_btn_html($post->ID);
    }
    /**
     * Comment button
     */
    if (ap_user_can_comment()) {
        $actions['comment'] = ap_comment_btn_html();
    }
    $actions['status'] = ap_post_change_status_btn_html($post->ID);
    /**
     * edit question link
     */
    if (ap_user_can_edit_question($post->ID) && $post->post_type == 'question') {
        $actions['dropdown']['edit_question'] = ap_edit_post_link_html();
    }
    if (ap_user_can_edit_ans($post->ID) && $post->post_type == 'answer') {
        $actions['dropdown']['edit_answer'] = ap_edit_post_link_html();
    }
    if (is_user_logged_in()) {
        $actions['dropdown']['flag'] = ap_flag_btn_html();
    }
    if (is_super_admin() && $post->post_type == 'question') {
        $actions['dropdown']['featured'] = ap_featured_post_btn();
    }
    if (ap_user_can_delete($post->ID) && $post->post_status != 'trash') {
        $actions['dropdown']['delete'] = ap_post_delete_btn_html();
    }
    if (ap_user_can_delete($post->ID)) {
        $actions['dropdown']['permanent_delete'] = ap_post_permanent_delete_btn_html();
    }
    /**
     * FILTER: ap_post_actions_buttons
     * For filtering post actions buttons
     * @var 	string
     * @since 	2.0
     */
    $actions = apply_filters('ap_post_actions_buttons', $actions);
    if (!empty($actions) && count($actions) > 0) {
        echo '<ul id="ap_post_actions_' . $post->ID . '" class="ap-q-actions ap-ul-inline clearfix">';
        foreach ($actions as $k => $action) {
            if (!empty($action) && $k != 'dropdown' && !in_array($k, $disable)) {
                echo '<li class="ap-post-action ap-action-' . $k . '">' . $action . '</li>';
            }
        }
        if (!empty($actions['dropdown'])) {
            echo '<li class="ap-post-action dropdown">';
            echo '<div id="ap_post_action_' . $post->ID . '" class="ap-dropdown">';
            echo '<a class="apicon-ellipsis more-actions ap-tip ap-dropdown-toggle" title="' . __('More action', 'ap') . '" href="#"></a>';
            echo '<ul class="ap-dropdown-menu">';
            foreach ($actions['dropdown'] as $sk => $sub) {
                echo '<li class="ap-post-action ap-action-' . $sk . '">' . $sub . '</li>';
            }
            echo '</ul>';
            echo '</div>';
            echo '</li>';
        }
        echo '</ul>';
    }
}
Exemple #3
0
 /**
  * Process edit question form
  * @return void
  * @since 2.0.1
  */
 public function edit_question()
 {
     global $ap_errors, $validate;
     // return if user do not have permission to edit this question
     if (!ap_user_can_edit_question($this->fields['edit_post_id'])) {
         return;
     }
     $post = get_post($this->fields['edit_post_id']);
     $user_id = get_current_user_id();
     $status = 'publish';
     if (ap_opt('edit_question_status') == 'moderate' || ap_opt('edit_question_status') == 'point' && ap_get_points($user_id) < ap_opt('mod_answer_point')) {
         $status = 'moderate';
     }
     if (isset($this->fields['is_private']) && $this->fields['is_private']) {
         $status = 'private_post';
     }
     $question_array = array('ID' => $post->ID, 'post_author' => $post->post_author, 'post_title' => $this->fields['title'], 'post_name' => sanitize_title($this->fields['title']), 'post_content' => apply_filters('ap_form_contents_filter', $this->fields['description']), 'post_status' => $status);
     /**
      * FILTER: ap_pre_update_question
      * Can be used to modify $args before updating question
      * @var array
      * @since 2.0.1
      */
     $question_array = apply_filters('ap_pre_update_question', $question_array);
     $post_id = wp_update_post($question_array);
     if ($post_id) {
         $this->redirect = get_permalink($post_id);
         $this->result = array('action' => 'edited_question', 'message' => 'question_updated', 'do' => array('redirect' => $this->redirect));
     }
     $this->process_image_uploads($post->ID, $post->post_author);
 }
Exemple #4
0
/**
 * Returns edit post button html.
 *
 * @param bool         $echo
 * @param int | object $post_id_or_object
 *
 * @return null|string
 *
 * @since 2.0.1
 */
function ap_edit_post_link_html($echo = false, $post_id_or_object = false)
{
    if (!is_object($post_id_or_object)) {
        $post_id_or_object = get_post($post_id_or_object);
    }
    $post = $post_id_or_object;
    $edit_link = ap_post_edit_link($post);
    $output = '';
    if ($post->post_type == 'question' && ap_user_can_edit_question($post->ID)) {
        $output = "<a href='{$edit_link}' data-button='ap-edit-post' title='" . __('Edit this question', 'ap') . "' class='apEditBtn'>" . __('Edit', 'ap') . '</a>';
    } elseif ($post->post_type == 'answer' && ap_user_can_edit_ans($post->ID)) {
        $output = "<a href='{$edit_link}' data-button='ap-edit-post' title='" . __('Edit this answer', 'ap') . "' class='apEditBtn'>" . __('Edit', 'ap') . '</a>';
    }
    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
}
Exemple #5
0
 /**
  * Output edit page template
  */
 public function edit_page()
 {
     $post_id = (int) sanitize_text_field(get_query_var('edit_post_id'));
     if (!ap_user_can_edit_question($post_id)) {
         echo '<p>' . esc_attr__('You don\'t have permission to access this page.', 'ap') . '</p>';
         return;
     } else {
         global $editing_post;
         $editing_post = get_post($post_id);
         // Include theme file.
         include ap_get_theme_location('edit.php');
     }
 }
function ap_edit_q_btn_html()
{
    $post_id = get_the_ID();
    if (ap_user_can_edit_question($post_id)) {
        $action = 'question-' . $post_id;
        $nonce = wp_create_nonce($action);
        $edit_link = add_query_arg(array('edit_q' => $post_id, 'nonce' => $nonce), get_permalink(ap_opt('base_page')));
        //$args = json_encode(array('action' => 'ap_load_edit_form', 'id'=> $post_id, 'nonce' => $nonce, 'type' => 'question'));
        echo "<a href='{$edit_link}' data-button='ap-edit-post' title='" . __('Edit this question', 'ap') . "'>" . __('Edit', 'ap') . "</a>";
    }
    return;
}