Make WordPress Core

Changeset 28430


Ignore:
Timestamp:
05/15/2014 03:24:21 PM (9 years ago)
Author:
wonderboymusic
Message:

Eliminate use of extract() in WP_Ajax_Response::add(). Just set most of the properties to variables to avoid interpolation churn.

See #22400.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-ajax-response.php

    r21528 r28430  
    6262
    6363        $r = wp_parse_args( $args, $defaults );
    64         extract( $r, EXTR_SKIP );
    65         $position = preg_replace( '/[^a-z0-9:_-]/i', '', $position );
    6664
    67         if ( is_wp_error($id) ) {
     65        $position = preg_replace( '/[^a-z0-9:_-]/i', '', $r['position'] );
     66        $id = $r['id'];
     67        $what = $r['what'];
     68        $action = $r['action'];
     69        $old_id = $r['old_id'];
     70        $data = $r['data'];
     71
     72        if ( is_wp_error( $id ) ) {
    6873            $data = $id;
    6974            $id = 0;
     
    7176
    7277        $response = '';
    73         if ( is_wp_error($data) ) {
     78        if ( is_wp_error( $data ) ) {
    7479            foreach ( (array) $data->get_error_codes() as $code ) {
    75                 $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
    76                 if ( !$error_data = $data->get_error_data($code) )
     80                $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message( $code ) . "]]></wp_error>";
     81                if ( ! $error_data = $data->get_error_data( $code ) ) {
    7782                    continue;
     83                }
    7884                $class = '';
    79                 if ( is_object($error_data) ) {
    80                     $class = ' class="' . get_class($error_data) . '"';
    81                     $error_data = get_object_vars($error_data);
     85                if ( is_object( $error_data ) ) {
     86                    $class = ' class="' . get_class( $error_data ) . '"';
     87                    $error_data = get_object_vars( $error_data );
    8288                }
    8389
    8490                $response .= "<wp_error_data code='$code'$class>";
    8591
    86                 if ( is_scalar($error_data) ) {
     92                if ( is_scalar( $error_data ) ) {
    8793                    $response .= "<![CDATA[$error_data]]>";
    88                 } elseif ( is_array($error_data) ) {
    89                     foreach ( $error_data as $k => $v )
     94                } elseif ( is_array( $error_data ) ) {
     95                    foreach ( $error_data as $k => $v ) {
    9096                        $response .= "<$k><![CDATA[$v]]></$k>";
     97                    }
    9198                }
    9299
     
    98105
    99106        $s = '';
    100         if ( is_array($supplemental) ) {
    101             foreach ( $supplemental as $k => $v )
     107        if ( is_array( $r['supplemental'] ) ) {
     108            foreach ( $r['supplemental'] as $k => $v ) {
    102109                $s .= "<$k><![CDATA[$v]]></$k>";
     110            }
    103111            $s = "<supplemental>$s</supplemental>";
    104112        }
    105113
    106         if ( false === $action )
     114        if ( false === $action ) {
    107115            $action = $_POST['action'];
    108 
     116        }
    109117        $x = '';
    110118        $x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action
Note: See TracChangeset for help on using the changeset viewer.