diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 6e357cae26..1c472e45ca 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -624,6 +624,8 @@ case 'add-comment' : die('-1'); $wp_list_table = get_list_table('comments'); + $wp_list_table->from_ajax = true; + $wp_list_table->prepare_items(); if ( !$wp_list_table->has_items() ) @@ -631,9 +633,8 @@ case 'add-comment' : $x = new WP_Ajax_Response(); foreach ( $wp_list_table->items as $comment ) { - get_comment( $comment ); ob_start(); - $wp_list_table->single_row( $comment->comment_ID, $mode, $comment_status, true, true ); + $wp_list_table->single_row( $comment ); $comment_list_item = ob_get_contents(); ob_end_clean(); $x->add( array( @@ -651,7 +652,8 @@ case 'get-comments' : if ( !current_user_can( 'edit_post', $post_ID ) ) die('-1'); - $wp_list_table = get_list_table('comments'); + $wp_list_table = get_list_table('post-comments'); + $wp_list_table->prepare_items(); if ( !$wp_list_table->has_items() ) @@ -662,7 +664,7 @@ case 'get-comments' : foreach ( $wp_list_table->items as $comment ) { get_comment( $comment ); ob_start(); - $wp_list_table->single_row( $comment->comment_ID, 'single', false, false ); + $wp_list_table->single_row( $comment ); $comment_list_item .= ob_get_contents(); ob_end_clean(); } @@ -676,6 +678,7 @@ case 'replyto-comment' : check_ajax_referer( $action, '_ajax_nonce-replyto-comment' ); $wp_list_table = get_list_table('comments'); + $wp_list_table->checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0; $comment_post_ID = (int) $_POST['comment_post_ID']; if ( !current_user_can( 'edit_post', $comment_post_ID ) ) @@ -715,16 +718,15 @@ case 'replyto-comment' : if ( ! $comment ) die('1'); $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1'; - $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0; $x = new WP_Ajax_Response(); ob_start(); if ( 'dashboard' == $mode ) { require_once( ABSPATH . 'wp-admin/includes/dashboard.php' ); - _wp_dashboard_recent_comments_row( $comment, false ); + _wp_dashboard_recent_comments_row( $comment ); } else { - $wp_list_table->single_row( $comment->comment_ID, $mode, false, $checkbox ); + $wp_list_table->single_row( $comment ); } $comment_list_item = ob_get_contents(); ob_end_clean(); @@ -753,13 +755,13 @@ case 'edit-comment' : edit_comment(); $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1'; - $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0; - $comments_listing = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : ''; + $comments_status = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : ''; - $wp_list_table = get_list_table('comments'); + $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0; + $wp_list_table = get_list_table( $checkbox ? 'comments' : 'post-comments' ); ob_start(); - $wp_list_table->single_row( $comment_id, $mode, $comments_listing, $checkbox ); + $wp_list_table->single_row( get_comment( $comment_id ) ); $comment_list_item = ob_get_contents(); ob_end_clean(); diff --git a/wp-admin/includes/default-list-tables.php b/wp-admin/includes/default-list-tables.php index 9749332387..adf983f47b 100644 --- a/wp-admin/includes/default-list-tables.php +++ b/wp-admin/includes/default-list-tables.php @@ -2015,6 +2015,11 @@ class WP_Users_Table extends WP_List_Table { class WP_Comments_Table extends WP_List_Table { + var $checkbox = true; + var $from_ajax = false; + + var $pending_count = array(); + function WP_Comments_Table() { global $mode; @@ -2091,7 +2096,7 @@ class WP_Comments_Table extends WP_List_Table { $_comment_post_ids[] = $_c->comment_post_ID; } - $_comment_pending_count = get_pending_comments_num( $_comment_post_ids ); + $this->pending_count = get_pending_comments_num( $_comment_post_ids ); $this->set_pagination_args( array( 'total_items' => $total_comments, @@ -2205,13 +2210,20 @@ class WP_Comments_Table extends WP_List_Table { } function get_columns() { - return array( - 'cb' => '', - 'author' => __( 'Author' ), - /* translators: column name */ - 'comment' => _x( 'Comment', 'column name' ), - 'response' => __( 'In Response To' ) - ); + global $mode; + + $columns = array(); + + if ( $this->checkbox ) + $columns['cb'] = ''; + + $columns['author'] = __( 'Author' ); + $columns['comment'] = _x( 'Comment', 'column name' ); + + if ( 'single' !== $mode ) + $columns['response'] = _x( 'Comment', 'column name' ); + + return $columns; } function get_sortable_columns() { @@ -2242,11 +2254,11 @@ class WP_Comments_Table extends WP_List_Table { - display_rows( $this->items ); ?> + display_rows(); ?> - display_rows( $this->extra_items ); ?> + items = $this->extra_items; $this->display_rows(); ?> display_tablenav( 'bottom' ); } - function display_rows( $items = false ) { - global $mode, $comment_status; + function single_row( $a_comment ) { + global $post, $comment, $the_comment_status; - if ( false === $items ) - $items = $this->items; + $comment = $a_comment; + $the_comment_status = wp_get_comment_status( $comment->comment_ID ); - foreach ( $items as $comment ) - $this->single_row( $comment->comment_ID, $mode, $comment_status ); + $post = get_post( $comment->comment_post_ID ); + + $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); + + echo ""; + echo $this->single_row_columns( $comment ); + echo "\n"; } - function single_row( $comment_id, $mode, $comment_status, $checkbox = true, $from_ajax = false ) { - global $comment, $post, $_comment_pending_count; - $comment = get_comment( $comment_id ); - $post = get_post( $comment->comment_post_ID ); - $the_comment_status = wp_get_comment_status( $comment->comment_ID ); - $user_can = current_user_can( 'edit_comment', $comment_id ); + function column_cb( $comment ) { + if ( $this->user_can ) + echo ""; + } + + function column_comment( $comment ) { + global $post, $comment_status, $the_comment_status; + + $user_can = $this->user_can; $comment_url = esc_url( get_comment_link( $comment->comment_ID ) ); - $author_url = get_comment_author_url(); - if ( 'http://' == $author_url ) - $author_url = ''; - $author_url_display = preg_replace( '|http://(www\.)?|i', '', $author_url ); - if ( strlen( $author_url_display ) > 50 ) - $author_url_display = substr( $author_url_display, 0, 49 ) . '...'; $ptime = date( 'G', strtotime( $comment->comment_date ) ); if ( ( abs( time() - $ptime ) ) < 86400 ) @@ -2300,178 +2314,175 @@ class WP_Comments_Table extends WP_List_Table { $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" ); } - echo ""; + echo '
'; + /* translators: 2: comment date, 3: comment time */ + printf( __( '%2$s at %3$s' ), $comment_url, + /* translators: comment date format. See http://php.net/date */ get_comment_date( __( 'Y/m/d' ) ), + /* translators: comment time format. See http://php.net/date */ get_comment_date( get_option( 'time_format' ) ) ); - list( $columns, $hidden ) = $this->get_column_headers(); - - foreach ( $columns as $column_name => $column_display_name ) { - $class = "class=\"$column_name column-$column_name\""; - - $style = ''; - if ( in_array( $column_name, $hidden ) ) - $style = ' style="display:none;"'; - - $attributes = "$class$style"; - - switch ( $column_name ) { - case 'cb': - if ( !$checkbox ) break; - echo ''; - if ( $user_can ) echo ""; - echo ''; - break; - case 'comment': - echo ""; - echo '
'; - /* translators: 2: comment date, 3: comment time */ - printf( __( '%2$s at %3$s' ), $comment_url, - /* translators: comment date format. See http://php.net/date */ get_comment_date( __( 'Y/m/d' ) ), - /* translators: comment time format. See http://php.net/date */ get_comment_date( get_option( 'time_format' ) ) ); - - if ( $comment->comment_parent ) { - $parent = get_comment( $comment->comment_parent ); - $parent_link = esc_url( get_comment_link( $comment->comment_parent ) ); - $name = get_comment_author( $parent->comment_ID ); - printf( ' | '.__( 'In reply to %2$s.' ), $parent_link, $name ); - } - - echo '
'; - comment_text(); - if ( $user_can ) { ?> - - '', 'unapprove' => '', - 'reply' => '', - 'quickedit' => '', - 'edit' => '', - 'spam' => '', 'unspam' => '', - 'trash' => '', 'untrash' => '', 'delete' => '' - ); - - if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments - if ( 'approved' == $the_comment_status ) - $actions['unapprove'] = "" . __( 'Unapprove' ) . ''; - else if ( 'unapproved' == $the_comment_status ) - $actions['approve'] = "" . __( 'Approve' ) . ''; - } else { - $actions['approve'] = "" . __( 'Approve' ) . ''; - $actions['unapprove'] = "" . __( 'Unapprove' ) . ''; - } - - if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) { - $actions['spam'] = "" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . ''; - } elseif ( 'spam' == $the_comment_status ) { - $actions['unspam'] = "" . _x( 'Not Spam', 'comment' ) . ''; - } elseif ( 'trash' == $the_comment_status ) { - $actions['untrash'] = "" . __( 'Restore' ) . ''; - } - - if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) { - $actions['delete'] = "" . __( 'Delete Permanently' ) . ''; - } else { - $actions['trash'] = "" . _x( 'Trash', 'verb' ) . ''; - } - - if ( 'trash' != $the_comment_status ) { - $actions['edit'] = "". __( 'Edit' ) . ''; - $actions['quickedit'] = '' . __( 'Quick Edit' ) . ''; - if ( 'spam' != $the_comment_status ) - $actions['reply'] = '' . __( 'Reply' ) . ''; - } - - $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); - - $i = 0; - echo '
'; - foreach ( $actions as $action => $link ) { - ++$i; - ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | '; - - // Reply and quickedit need a hide-if-no-js span when not added with ajax - if ( ( 'reply' == $action || 'quickedit' == $action ) && ! $from_ajax ) - $action .= ' hide-if-no-js'; - elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) { - if ( '1' == get_comment_meta( $comment_id, '_wp_trash_meta_status', true ) ) - $action .= ' approve'; - else - $action .= ' unapprove'; - } - - echo "$sep$link"; - } - echo '
'; - } - - echo ''; - break; - case 'author': - echo ""; comment_author(); echo '
'; - if ( !empty( $author_url ) ) - echo "$author_url_display
"; - if ( $user_can ) { - if ( !empty( $comment->comment_author_email ) ) { - comment_author_email_link(); - echo '
'; - } - echo ''; - comment_author_IP(); - echo ''; - } //current_user_can - echo ''; - break; - case 'date': - echo "" . get_comment_date( __( 'Y/m/d \a\t g:ia' ) ) . ''; - break; - case 'response': - if ( 'single' !== $mode ) { - if ( isset( $_comment_pending_count[$post->ID] ) ) { - $pending_comments = $_comment_pending_count[$post->ID]; - } else { - $_comment_pending_count_temp = get_pending_comments_num( array( $post->ID ) ); - $pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp[$post->ID]; - } - if ( $user_can ) { - $post_link = ""; - $post_link .= get_the_title( $post->ID ) . ''; - } else { - $post_link = get_the_title( $post->ID ); - } - echo "\n"; - echo ''; - if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) - echo $thumb; - echo ''; - } - break; - default: - echo "\n"; - do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID ); - echo "\n"; - break; - } + if ( $comment->comment_parent ) { + $parent = get_comment( $comment->comment_parent ); + $parent_link = esc_url( get_comment_link( $comment->comment_parent ) ); + $name = get_comment_author( $parent->comment_ID ); + printf( ' | '.__( 'In reply to %2$s.' ), $parent_link, $name ); } - echo "\n"; + + echo '
'; + comment_text(); + if ( $user_can ) { ?> + + '', 'unapprove' => '', + 'reply' => '', + 'quickedit' => '', + 'edit' => '', + 'spam' => '', 'unspam' => '', + 'trash' => '', 'untrash' => '', 'delete' => '' + ); + + if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments + if ( 'approved' == $the_comment_status ) + $actions['unapprove'] = "" . __( 'Unapprove' ) . ''; + else if ( 'unapproved' == $the_comment_status ) + $actions['approve'] = "" . __( 'Approve' ) . ''; + } else { + $actions['approve'] = "" . __( 'Approve' ) . ''; + $actions['unapprove'] = "" . __( 'Unapprove' ) . ''; + } + + if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) { + $actions['spam'] = "" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . ''; + } elseif ( 'spam' == $the_comment_status ) { + $actions['unspam'] = "" . _x( 'Not Spam', 'comment' ) . ''; + } elseif ( 'trash' == $the_comment_status ) { + $actions['untrash'] = "" . __( 'Restore' ) . ''; + } + + if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) { + $actions['delete'] = "" . __( 'Delete Permanently' ) . ''; + } else { + $actions['trash'] = "" . _x( 'Trash', 'verb' ) . ''; + } + + if ( 'trash' != $the_comment_status ) { + $actions['edit'] = "". __( 'Edit' ) . ''; + $actions['quickedit'] = '' . __( 'Quick Edit' ) . ''; + if ( 'spam' != $the_comment_status ) + $actions['reply'] = '' . __( 'Reply' ) . ''; + } + + $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); + + $i = 0; + echo '
'; + foreach ( $actions as $action => $link ) { + ++$i; + ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | '; + + // Reply and quickedit need a hide-if-no-js span when not added with ajax + if ( ( 'reply' == $action || 'quickedit' == $action ) && ! $this->from_ajax ) + $action .= ' hide-if-no-js'; + elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) { + if ( '1' == get_comment_meta( $comment_id, '_wp_trash_meta_status', true ) ) + $action .= ' approve'; + else + $action .= ' unapprove'; + } + + echo "$sep$link"; + } + echo '
'; + } + } + + function column_author( $comment ) { + global $comment_status; + + $author_url = get_comment_author_url(); + if ( 'http://' == $author_url ) + $author_url = ''; + $author_url_display = preg_replace( '|http://(www\.)?|i', '', $author_url ); + if ( strlen( $author_url_display ) > 50 ) + $author_url_display = substr( $author_url_display, 0, 49 ) . '...'; + + echo ""; comment_author(); echo '
'; + if ( !empty( $author_url ) ) + echo "$author_url_display
"; + + if ( $this->user_can ) { + if ( !empty( $comment->comment_author_email ) ) { + comment_author_email_link(); + echo '
'; + } + echo ''; + comment_author_IP(); + echo ''; + } + } + + function column_date( $comment ) { + return get_comment_date( __( 'Y/m/d \a\t g:ia' ) ); + } + + function column_response( $comment ) { + global $post; + + if ( isset( $this->pending_count[$post->ID] ) ) { + $pending_comments = $this->pending_count[$post->ID]; + } else { + $_pending_count_temp = get_pending_comments_num( array( $post->ID ) ); + $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID]; + } + + if ( current_user_can( 'edit_post', $post->ID ) ) { + $post_link = ""; + $post_link .= get_the_title( $post->ID ) . ''; + } else { + $post_link = get_the_title( $post->ID ); + } + + echo ''; + if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) + echo $thumb; + } + + function column_default( $comment, $column_name ) { + do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID ); + } +} + +class WP_Post_Comments_Table extends WP_Comments_Table { + + function get_columns() { + return array( + 'author' => __( 'Author' ), + 'comment' => _x( 'Comment', 'column name' ), + ); + } + + function get_sortable_columns() { + return array(); } } diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 0fbbccc31f..4dee81e055 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -459,10 +459,8 @@ function post_comment_meta_box($post) { } wp_nonce_field( 'get-comments', 'add_comment_nonce', false ); - add_filter('manage_edit-comments_columns', 'post_comment_meta_box_thead', 8, 1); - add_filter('manage_edit-comments_sortable_columns', '__return_empty_array', 8); - $wp_list_table = get_list_table('comments'); + $wp_list_table = get_list_table('post-comments'); ?> @@ -478,7 +476,6 @@ function post_comment_meta_box($post) {