Switch language

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




wp_set_comment_status [ WordPress Function ]

wp_set_comment_status ( $comment_id, $comment_status, $wp_error = false )
Parameters:
  • (int) $comment_id Comment ID.
  • (string) $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'.
  • (bool) $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
Uses:
Returns:
  • (bool) False on failure or deletion and true on success.
Defined at:



Sets the status of a comment.

The 'wp_set_comment_status' action is called after the comment is handled. If the comment status is not in the list, then false is returned.

Source


<?php
function wp_set_comment_status($comment_id$comment_status$wp_error false) {
    global 
$wpdb;

    
$status '0';
    switch ( 
$comment_status ) {
        case 
'hold':
        case 
'0':
            
$status '0';
            break;
        case 
'approve':
        case 
'1':
            
$status '1';
            if ( 
get_option('comments_notify') ) {
                
$comment get_comment($comment_id);
                
wp_notify_postauthor($comment_id$comment->comment_type);
            }
            break;
        case 
'spam':
            
$status 'spam';
            break;
        case 
'trash':
            
$status 'trash';
            break;
        default:
            return 
false;
    }

    
$comment_old = clone get_comment($comment_id);

    if ( !
$wpdb->update$wpdb->comments, array('comment_approved' => $status), array('comment_ID' => $comment_id) ) ) {
        if ( 
$wp_error )
            return new 
WP_Error('db_update_error'__('Could not update comment status'), $wpdb->last_error);
        else
            return 
false;
    }

    
clean_comment_cache($comment_id);

    
$comment get_comment($comment_id);

    
do_action('wp_set_comment_status'$comment_id$comment_status);
    
wp_transition_comment_status($comment_status$comment_old->comment_approved$comment);

    
wp_update_comment_count($comment->comment_post_ID);

    return 
true;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



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