Beispiel #1
0
 public function delete_comment()
 {
     $args = $args = explode('-', sanitize_text_field($_REQUEST['args']));
     if (!ap_user_can_delete_comment($args[0])) {
         $result = array('status' => false, 'message' => __('You do not have permission to delete this comment', 'ap'));
         die(json_encode($result));
     }
     $action = 'delete-comment-' . $args[0];
     if (wp_verify_nonce($args[1], $action)) {
         $comment = get_comment($args[0]);
         $delete = wp_delete_comment($args[0], true);
         if ($delete) {
             $post_type = get_post_type($comment->comment_post_ID);
             do_action('ap_after_delete_comment', $comment, $post_type);
             if ($post_type == 'question') {
                 ap_do_event('delete_comment', $comment, 'question');
             } elseif ($post_type == 'answer') {
                 ap_do_event('delete_comment', $comment, 'answer');
             }
         }
         $result = array('status' => true, 'message' => __('Comment deleted successfully', 'ap'));
         die(json_encode($result));
     }
     die;
 }
Beispiel #2
0
function ap_comment_actions_buttons()
{
    global $comment;
    $post = get_post($comment->comment_post_ID);
    if (!$post->post_type == 'question' || !$post->post_type == 'answer') {
        return;
    }
    $actions = array();
    if (ap_user_can_edit_comment(get_comment_ID())) {
        $nonce = wp_create_nonce('edit_comment_' . get_comment_ID());
        $actions['edit'] = '<a class="comment-edit-btn" href="#" data-toggle="#li-comment-' . get_comment_ID() . '" data-action="load_comment_form" data-query="ap_ajax_action=load_comment_form&comment_ID=' . get_comment_ID() . '&__nonce=' . $nonce . '">' . __('Edit', 'ap') . '</a>';
    }
    if (ap_user_can_delete_comment(get_comment_ID())) {
        $nonce = wp_create_nonce('delete_comment');
        $actions['delete'] = '<a class="comment-delete-btn" href="#" data-toggle="#li-comment-' . get_comment_ID() . '" data-action="delete_comment" data-query="ap_ajax_action=delete_comment&comment_ID=' . get_comment_ID() . '&__nonce=' . $nonce . '">' . __('Delete', 'ap') . '</a>';
    }
    /**
     * FILTER: ap_comment_actions_buttons
     * For filtering post actions buttons
     * @var 	string
     * @since 	2.0
     */
    $actions = apply_filters('ap_comment_actions_buttons', $actions);
    if (!empty($actions) && count($actions) > 0) {
        foreach ($actions as $k => $action) {
            echo '<span class="ap-comment-action ap-action-' . $k . '">' . $action . '</span>';
        }
    }
}
Beispiel #3
0
 /**
  * Ajax action for deleting comment.
  *
  * @since 2.0.0
  */
 public function delete_comment()
 {
     $comment_id = (int) $_POST['comment_ID'];
     if (isset($_POST['comment_ID']) && ap_user_can_delete_comment($comment_id) && wp_verify_nonce($_POST['__nonce'], 'delete_comment')) {
         $comment = get_comment($comment_id);
         if (time() > get_comment_date('U', (int) $_POST['comment_ID']) + (int) ap_opt('disable_delete_after') && !is_super_admin()) {
             ap_send_json(ap_ajax_responce(array('message_type' => 'warning', 'message' => sprintf(__('This post was created %s, its locked hence you cannot delete it.', 'anspress-question-answer'), ap_human_time(get_comment_date('U', (int) $_POST['comment_ID']))))));
             return;
         }
         do_action('ap_unpublish_comment', $comment);
         $delete = wp_delete_comment((int) $_POST['comment_ID'], true);
         if ($delete) {
             do_action('ap_after_deleting_comment', $comment);
             $count = get_comment_count($comment->comment_post_ID);
             $this->send(array('action' => 'delete_comment', 'comment_ID' => (int) $_POST['comment_ID'], 'message' => 'comment_delete_success', 'message' => 'comment_delete_success', 'view' => array('comments_count_' . $comment->comment_post_ID => '(' . $count['approved'] . ')', 'comment_count_label_' . $comment->comment_post_ID => sprintf(_n('One comment', '%d comments', $count['approved'], 'anspress-question-answer'), $count['approved']))));
         }
         $this->something_wrong();
     }
     $this->send('no_permission');
 }
Beispiel #4
0
    function ap_comment($comment)
    {
        $GLOBALS['comment'] = $comment;
        ?>
		<li <?php 
        comment_class();
        ?>
 id="li-comment-<?php 
        comment_ID();
        ?>
">
			<!-- comment #<?php 
        comment_ID();
        ?>
 -->
			<article id="comment-<?php 
        comment_ID();
        ?>
" class="comment">
				<div class="ap-avatar">
					<a href="<?php 
        echo ap_user_link($comment->user_id);
        ?>
">
					<?php 
        echo get_avatar($comment, ap_opt('avatar_size_qcomment'));
        ?>
					</a>
				</div>
				<div class="comment-content">
					<?php 
        if ('0' == $comment->comment_approved) {
            ?>
						<p class="comment-awaiting-moderation"><?php 
            _e('Your comment is awaiting moderation.', 'ap');
            ?>
</p>
					<?php 
        }
        ?>
										
					<p class="ap-comment-texts">
						<?php 
        echo get_comment_text();
        ?>
						<?php 
        printf(' - <time datetime="%1$s">%2$s %3$s</time>', get_comment_time('c'), ap_human_time(get_comment_time('U')), __('ago', 'ap'));
        ?>
					</p>
					<div class="comment-meta">
						<?php 
        if (ap_user_can_edit_comment(get_comment_ID())) {
            echo '<a class="comment-edit-btn" href="#" data-button="ap-edit-comment" data-args="' . get_comment_ID() . '-' . wp_create_nonce('comment-' . get_comment_ID()) . '"><i class="aicon-pencil"></i> ' . __('Edit', 'ap') . '</a>';
        }
        if (ap_user_can_delete_comment(get_comment_ID())) {
            echo '<a class="comment-delete-btn" href="#" data-button="ap-delete-comment" data-confirm="' . __('Are you sure? It cannot be undone!', 'ap') . '" data-args="' . get_comment_ID() . '-' . wp_create_nonce('delete-comment-' . get_comment_ID()) . '"><i class="aicon-close"></i> ' . __('Delete', 'ap') . '</a>';
        }
        ?>
					</div>					
				</div>
			</article>
		<?php 
    }