Changeset 17354 for trunk/wp-admin/admin-ajax.php
- Timestamp:
- 01/22/2011 06:47:42 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/admin-ajax.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r17325 r17354 190 190 * @return die 191 191 */ 192 function _wp_ajax_delete_comment_response( $comment_id ) {192 function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { 193 193 $total = (int) @$_POST['_total']; 194 194 $per_page = (int) @$_POST['_per_page']; … … 199 199 die( (string) time() ); 200 200 201 if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one) 201 $total += $delta; 202 if ( $total < 0 ) 202 203 $total = 0; 203 204 204 if ( 0 != $total % $per_page && 1 != mt_rand( 1, $per_page ) ) // Only do the expensive stuff on a page-break, and about 1 other time per page 205 die( (string) time() ); 206 207 $post_id = 0; 208 $status = 'total_comments'; // What type of comment count are we looking for? 209 $parsed = parse_url( $url ); 210 if ( isset( $parsed['query'] ) ) { 211 parse_str( $parsed['query'], $query_vars ); 212 if ( !empty( $query_vars['comment_status'] ) ) 213 $status = $query_vars['comment_status']; 214 if ( !empty( $query_vars['p'] ) ) 215 $post_id = (int) $query_vars['p']; 216 } 217 218 $comment_count = wp_count_comments($post_id); 205 // Only do the expensive stuff on a page-break, and about 1 other time per page 206 if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) { 207 $post_id = 0; 208 $status = 'total_comments'; // What type of comment count are we looking for? 209 $parsed = parse_url( $url ); 210 if ( isset( $parsed['query'] ) ) { 211 parse_str( $parsed['query'], $query_vars ); 212 if ( !empty( $query_vars['comment_status'] ) ) 213 $status = $query_vars['comment_status']; 214 if ( !empty( $query_vars['p'] ) ) 215 $post_id = (int) $query_vars['p']; 216 } 217 218 $comment_count = wp_count_comments($post_id); 219 220 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count 221 $total = $comment_count->$status; 222 // else use the decremented value from above 223 } 224 219 225 $time = time(); // The time since the last comment count 220 226 221 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count222 $total = $comment_count->$status;223 // else use the decremented value from above224 225 $page_links = paginate_links( array(226 'base' => add_query_arg( 'apage', '%#%', $url ),227 'format' => '',228 'prev_text' => __('«'),229 'next_text' => __('»'),230 'total' => ceil($total / $per_page),231 'current' => $page232 ) );233 227 $x = new WP_Ajax_Response( array( 234 228 'what' => 'comment', 235 229 'id' => $comment_id, // here for completeness - not used 236 230 'supplemental' => array( 237 'pageLinks' => $page_links, 231 'total_items_i18n' => sprintf( _n( '1 item', '%s items', $total ), number_format_i18n( $total ) ), 232 'total_pages' => ceil( $total / $per_page ), 233 'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ), 238 234 'total' => $total, 239 235 'time' => $time … … 332 328 $status = wp_get_comment_status( $comment->comment_ID ); 333 329 330 $delta = -1; 334 331 if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { 335 332 if ( 'trash' == $status ) … … 340 337 die( (string) time() ); 341 338 $r = wp_untrash_comment( $comment->comment_ID ); 339 if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash 340 $delta = 1; 342 341 } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { 343 342 if ( 'spam' == $status ) … … 348 347 die( (string) time() ); 349 348 $r = wp_unspam_comment( $comment->comment_ID ); 349 if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam 350 $delta = 1; 350 351 } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { 351 352 $r = wp_delete_comment( $comment->comment_ID ); … … 355 356 356 357 if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts 357 _wp_ajax_delete_comment_response( $comment->comment_ID );358 _wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); 358 359 die( '0' ); 359 360 break;
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)