Make WordPress Core

Changeset 11997


Ignore:
Timestamp:
10/05/2009 01:49:19 AM (15 years ago)
Author:
azaozz
Message:

Add conditional to handle get_comment_meta() return value, make #comment_id required arg for wp_trash_comment() and wp_untrash_comment(), see #4529

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r11992 r11997  
    854854 * @return mixed False on failure
    855855 */
    856 function wp_trash_comment($comment_id = 0) {
    857     if (EMPTY_TRASH_DAYS == 0)
     856function wp_trash_comment($comment_id) {
     857    if ( EMPTY_TRASH_DAYS == 0 )
    858858        return wp_delete_comment($comment_id);
    859859
    860     if (!$comment = get_comment($comment_id))
     860    if ( !$comment = get_comment($comment_id) )
    861861        return false;
    862862
    863863    do_action('trash_comment', $comment_id);
    864864
    865     add_comment_meta($comment_id,'_wp_trash_meta_status', $comment->comment_approved);
    866     add_comment_meta($comment_id,'_wp_trash_meta_time', time() );
     865    add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved);
     866    add_comment_meta($comment_id, '_wp_trash_meta_time', time() );
    867867
    868868    wp_set_comment_status($comment_id, 'trash');
     
    883883 * @return mixed False on failure
    884884 */
    885 function wp_untrash_comment($comment_id = 0) {
     885function wp_untrash_comment($comment_id) {
     886    if ( ! (int)$comment_id )
     887        return false;
     888
    886889    do_action('untrash_comment', $comment_id);
    887890
    888     $comment = array('comment_ID'=>$comment_id, 'comment_approved'=>'0');
    889 
    890     //Either set comment_approved to the value in comment_meta or worse case to false which will mean moderation
    891     $comment['comment_approved'] = get_comment_meta($comment_id, '_wp_trash_meta_status', true);
     891    $comment = array('comment_ID'=>$comment_id);
     892
     893    $status = get_comment_meta($comment_id, '_wp_trash_meta_status', true);
     894    if ( false === $status || '' === $status )
     895        $status = '0';
     896
     897    $comment['comment_approved'] = $status;
    892898
    893899    delete_comment_meta($comment_id, '_wp_trash_meta_time');
    894900    delete_comment_meta($comment_id, '_wp_trash_meta_status');
    895    
     901
    896902    wp_update_comment($comment);
    897        
     903
    898904    do_action('untrashed_comment', $comment_id);
    899905
Note: See TracChangeset for help on using the changeset viewer.