Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




_wp_ajax_delete_comment_response [ WordPress Function ]

_wp_ajax_delete_comment_response ( $comment_id, $delta = -1 )
Parameters:
Returns:
  • (die)
Defined at:



Sends back current comment total and new page links if they need to be updated.

Contrary to normal success AJAX response ("1"), die with time() on success.

Source


<?php
function _wp_ajax_delete_comment_response$comment_id$delta = -) {
    
$total = (int) @$_POST['_total'];
    
$per_page = (int) @$_POST['_per_page'];
    
$page = (int) @$_POST['_page'];
    
$url esc_url_raw( @$_POST['_url'] );
    
// JS didn't send us everything we need to know. Just die with success message
    
if ( !$total || !$per_page || !$page || !$url )
        
wp_dietime() );

    
$total += $delta;
    if ( 
$total )
        
$total 0;

    
// Only do the expensive stuff on a page-break, and about 1 other time per page
    
if ( == $total $per_page || == mt_rand1$per_page ) ) {
        
$post_id 0;
        
$status 'total_comments'// What type of comment count are we looking for?
        
$parsed parse_url$url );
        if ( isset( 
$parsed['query'] ) ) {
            
parse_str$parsed['query'], $query_vars );
            if ( !empty( 
$query_vars['comment_status'] ) )
                
$status $query_vars['comment_status'];
            if ( !empty( 
$query_vars['p'] ) )
                
$post_id = (int) $query_vars['p'];
        }

        
$comment_count wp_count_comments($post_id);

        if ( isset( 
$comment_count->$status ) ) // We're looking for a known type of comment count
            
$total $comment_count->$status;
            
// else use the decremented value from above
    
}

    
$time time(); // The time since the last comment count

    
$x = new WP_Ajax_Response( array(
        
'what' => 'comment',
        
'id' => $comment_id// here for completeness - not used
        
'supplemental' => array(
            
'total_items_i18n' => sprintf_n'1 item''%s items'$total ), number_format_i18n$total ) ),
            
'total_pages' => ceil$total $per_page ),
            
'total_pages_i18n' => number_format_i18nceil$total $per_page ) ),
            
'total' => $total,
            
'time' => $time
        
)
    ) );
    
$x->send();
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics