Make WordPress Core


Ignore:
Timestamp:
05/15/2014 06:36:17 AM (12 years ago)
Author:
wonderboymusic
Message:

Eliminate the use of extract() in wp_update_comment(). All unit tests pass.

See #22400.

File:
1 edited

Legend:

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

    r28324 r28427  
    18061806        // First, get all of the original fields
    18071807        $comment = get_comment($commentarr['comment_ID'], ARRAY_A);
    1808         if ( empty( $comment ) )
     1808        if ( empty( $comment ) ) {
    18091809                return 0;
    1810 
     1810        }
    18111811        // Escape data pulled from DB.
    18121812        $comment = wp_slash($comment);
     
    18201820
    18211821        // Now extract the merged array.
    1822         extract(wp_unslash($commentarr), EXTR_SKIP);
     1822        $data = wp_unslash( $commentarr );
    18231823
    18241824        /**
     
    18291829         * @param string $comment_content The comment data.
    18301830         */
    1831         $comment_content = apply_filters( 'comment_save_pre', $comment_content );
    1832 
    1833         $comment_date_gmt = get_gmt_from_date($comment_date);
    1834 
    1835         if ( !isset($comment_approved) )
    1836                 $comment_approved = 1;
    1837         else if ( 'hold' == $comment_approved )
    1838                 $comment_approved = 0;
    1839         else if ( 'approve' == $comment_approved )
    1840                 $comment_approved = 1;
    1841 
    1842         $data = compact( 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_parent' );
     1831        $data['comment_content'] = apply_filters( 'comment_save_pre', $data['comment_content'] );
     1832
     1833        $data['comment_date_gmt'] = get_gmt_from_date( $data['comment_date'] );
     1834
     1835        if ( ! isset( $data['comment_approved'] ) ) {
     1836                $data['comment_approved'] = 1;
     1837        } else if ( 'hold' == $data['comment_approved'] ) {
     1838                $data['comment_approved'] = 0;
     1839        } else if ( 'approve' == $data['comment_approved'] ) {
     1840                $data['comment_approved'] = 1;
     1841        }
     1842
     1843        $comment_ID = $data['comment_ID'];
     1844        $comment_post_ID = $data['comment_post_ID'];
     1845        $keys = array( 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_parent' );
     1846        $data = wp_array_slice_assoc( $data, $keys );
    18431847        $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
    18441848
    1845         clean_comment_cache($comment_ID);
    1846         wp_update_comment_count($comment_post_ID);
     1849        clean_comment_cache( $comment_ID );
     1850        wp_update_comment_count( $comment_post_ID );
    18471851        /**
    18481852         * Fires immediately after a comment is updated in the database.
Note: See TracChangeset for help on using the changeset viewer.