Esempio n. 1
0
function puma_ajax_comment_callback()
{
    $comment = wp_handle_comment_submission(wp_unslash($_POST));
    if (is_wp_error($comment)) {
        $data = $comment->get_error_data();
        if (!empty($data)) {
            fa_ajax_comment_err($comment->get_error_message());
        } else {
            exit;
        }
    }
    $user = wp_get_current_user();
    do_action('set_comment_cookies', $comment, $user);
    $GLOBALS['comment'] = $comment;
    //这里修改成你的评论结构
    ?>
    <li <?php 
    comment_class();
    ?>
>
        <article class="comment-body">
            <footer class="comment-meta">
                <div class="comment-author vcard">
                    <?php 
    echo get_avatar($comment, $size = '48');
    ?>
                    <b class="fn">
                        <?php 
    echo get_comment_author_link();
    ?>
                    </b>
                </div>
                <div class="comment-metadata">
                    <?php 
    echo get_comment_date();
    ?>
                </div>
            </footer>
            <div class="comment-content">
                <?php 
    comment_text();
    ?>
            </div>
        </article>
    </li>
    <?php 
    die;
}
Esempio n. 2
0
 /**
  * @ticket 34997
  */
 public function test_comment_submission_sends_all_expected_parameters_to_preprocess_comment_filter()
 {
     $user = self::factory()->user->create_and_get(array('role' => 'author'));
     wp_set_current_user($user->ID);
     $post = self::factory()->post->create_and_get();
     $data = array('comment_post_ID' => $post->ID, 'comment' => 'Comment');
     add_filter('preprocess_comment', array($this, 'filter_preprocess_comment'));
     $comment = wp_handle_comment_submission($data);
     remove_filter('preprocess_comment', array($this, 'filter_preprocess_comment'));
     $this->assertNotWPError($comment);
     $this->assertEquals(array('comment_post_ID' => $post->ID, 'comment_author' => $user->display_name, 'comment_author_email' => $user->user_email, 'comment_author_url' => $user->user_url, 'comment_content' => $data['comment'], 'comment_type' => '', 'comment_parent' => '0', 'user_ID' => $user->ID, 'user_id' => $user->ID), $this->preprocess_comment_data);
 }
 public function test_submitting_comment_with_no_comment_content_returns_error()
 {
     $error = 'require_valid_comment';
     $post = self::factory()->post->create_and_get();
     $data = array('comment_post_ID' => $post->ID, 'comment' => '', 'author' => 'Comment Author', 'email' => '*****@*****.**');
     $comment = wp_handle_comment_submission($data);
     $this->assertWPError($comment);
     $this->assertSame($error, $comment->get_error_code());
 }
/**
 * Handles Comment Post to WordPress and prevents duplicate comment posting.
 *
 * @package WordPress
 */
if ('POST' != $_SERVER['REQUEST_METHOD']) {
    header('Allow: POST');
    header('HTTP/1.1 405 Method Not Allowed');
    header('Content-Type: text/plain');
    exit;
}
/** Sets up the WordPress Environment. */
require dirname(__FILE__) . '/wp-load.php';
nocache_headers();
$comment = wp_handle_comment_submission(wp_unslash($_POST));
if (is_wp_error($comment)) {
    $data = $comment->get_error_data();
    if (!empty($data)) {
        wp_die($comment->get_error_message(), $data);
    } else {
        exit;
    }
}
$user = wp_get_current_user();
/**
 * Perform other actions when comment cookies are set.
 *
 * @since 3.4.0
 *
 * @param WP_Comment $comment Comment object.
 /**
  * @ticket 36901
  */
 public function test_comments_flood_user_is_admin()
 {
     $user = self::factory()->user->create_and_get(array('role' => 'administrator'));
     wp_set_current_user($user->ID);
     $post = self::factory()->post->create_and_get(array('post_status' => 'publish'));
     $data = array('comment_post_ID' => $post->ID, 'comment' => 'Did I say that?', 'author' => 'Repeat myself', 'email' => '*****@*****.**');
     $first_comment = wp_handle_comment_submission($data);
     $data['comment'] = 'Wow! I am quick!';
     $second_comment = wp_handle_comment_submission($data);
     $this->assertNotWPError($second_comment);
     $this->assertEquals($post->ID, $second_comment->comment_post_ID);
 }