Make WordPress Core


Ignore:
Timestamp:
09/13/2013 10:17:51 PM (12 years ago)
Author:
wonderboymusic
Message:

Fix some undefined index notices related to Comment unit tests:

  • There are several places where a $_POST index was unchecked before setting a variable
  • In wp_notify_postauthor(), $comment was being returned null, but its properties were being accessed.
  • In check_ajax_referer(), 3 different values can be checked for nonce on $_REQUEST, but only 1 had an isset()

See #25282.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r25430 r25433  
    548548
    549549    $current = wp_get_comment_status( $comment->comment_ID );
    550     if ( $_POST['new'] == $current )
     550    if ( isset( $_POST['new'] ) && $_POST['new'] == $current )
    551551        wp_die( time() );
    552552
     
    752752        $comment_content      = trim($_POST['content']);
    753753        if ( current_user_can( 'unfiltered_html' ) ) {
     754            if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) )
     755                $_POST['_wp_unfiltered_html_comment'] = '';
     756
    754757            if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) {
    755758                kses_remove_filters(); // start with a clean slate
     
    764767        wp_die( __( 'ERROR: please type a comment.' ) );
    765768
    766     $comment_parent = absint($_POST['comment_ID']);
     769    $comment_parent = 0;
     770    if ( isset( $_POST['comment_ID'] ) )
     771        $comment_parent = absint( $_POST['comment_ID'] );
    767772    $comment_auto_approved = false;
    768773    $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
     
    785790
    786791    ob_start();
    787         if ( 'dashboard' == $_REQUEST['mode'] ) {
    788             require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
    789             _wp_dashboard_recent_comments_row( $comment );
     792    if ( isset( $_REQUEST['mode'] ) && 'dashboard' == $_REQUEST['mode'] ) {
     793        require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
     794        _wp_dashboard_recent_comments_row( $comment );
     795    } else {
     796        if ( isset( $_REQUEST['mode'] ) && 'single' == $_REQUEST['mode'] ) {
     797            $wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    790798        } else {
    791             if ( 'single' == $_REQUEST['mode'] ) {
    792                 $wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    793             } else {
    794                 $wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    795             }
    796             $wp_list_table->single_row( $comment );
     799            $wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    797800        }
    798         $comment_list_item = ob_get_contents();
    799     ob_end_clean();
     801        $wp_list_table->single_row( $comment );
     802    }
     803    $comment_list_item = ob_get_clean();
    800804
    801805    $response =  array(
     
    826830        wp_die( __( 'ERROR: please type a comment.' ) );
    827831
    828     $_POST['comment_status'] = $_POST['status'];
     832    if ( isset( $_POST['status'] ) )
     833        $_POST['comment_status'] = $_POST['status'];
    829834    edit_comment();
    830835
     
    838843
    839844    ob_start();
    840         $wp_list_table->single_row( $comment );
    841         $comment_list_item = ob_get_contents();
    842     ob_end_clean();
     845    $wp_list_table->single_row( $comment );
     846    $comment_list_item = ob_get_clean();
    843847
    844848    $x = new WP_Ajax_Response();
Note: See TracChangeset for help on using the changeset viewer.