Make WordPress Core


Ignore:
Timestamp:
10/17/2008 09:44:22 AM (18 years ago)
Author:
azaozz
Message:

Comments post-box: show comments on the currently edited post with ajax, 20 at a time

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r9216 r9225  
    441441        ) );
    442442    }
     443    $x->send();
     444    break;
     445case 'get-comments' :
     446    check_ajax_referer( $action );
     447
     448    $post_ID = (int) $_POST['post_ID'];
     449    if ( !current_user_can( 'edit_post', $post_ID ) )
     450        die('-1');
     451
     452    $start = isset($_POST['start']) ? intval($_POST['start']) : 0;
     453    $num = isset($_POST['num']) ? intval($_POST['num']) : 10;
     454
     455    list($comments, $total) = _wp_get_comment_list( false, false, $start, $num, $post_ID );
     456
     457    if ( !$comments )
     458        die('1');
     459
     460    $comment_list_item = '';
     461    $x = new WP_Ajax_Response();
     462    foreach ( (array) $comments as $comment ) {
     463        get_comment( $comment );
     464        ob_start();
     465            _wp_comment_row( $comment->comment_ID, 'single', false, false );
     466            $comment_list_item .= ob_get_contents();
     467        ob_end_clean();
     468    }
     469    $x->add( array(
     470        'what' => 'comments',
     471        'data' => $comment_list_item
     472    ) );
    443473    $x->send();
    444474    break;
Note: See TracChangeset for help on using the changeset viewer.