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

See #22400.

Built from https://develop.svn.wordpress.org/trunk@28430


git-svn-id: http://core.svn.wordpress.org/trunk@28257 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-05-15 15:25:14 +00:00
parent 7943f4715a
commit 11aa170e30
1 changed files with 24 additions and 16 deletions

View File

@ -61,8 +61,13 @@ class WP_Ajax_Response {
); );
$r = wp_parse_args( $args, $defaults ); $r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$position = preg_replace( '/[^a-z0-9:_-]/i', '', $position ); $position = preg_replace( '/[^a-z0-9:_-]/i', '', $r['position'] );
$id = $r['id'];
$what = $r['what'];
$action = $r['action'];
$old_id = $r['old_id'];
$data = $r['data'];
if ( is_wp_error( $id ) ) { if ( is_wp_error( $id ) ) {
$data = $id; $data = $id;
@ -73,8 +78,9 @@ class WP_Ajax_Response {
if ( is_wp_error( $data ) ) { if ( is_wp_error( $data ) ) {
foreach ( (array) $data->get_error_codes() as $code ) { foreach ( (array) $data->get_error_codes() as $code ) {
$response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message( $code ) . "]]></wp_error>"; $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message( $code ) . "]]></wp_error>";
if ( !$error_data = $data->get_error_data($code) ) if ( ! $error_data = $data->get_error_data( $code ) ) {
continue; continue;
}
$class = ''; $class = '';
if ( is_object( $error_data ) ) { if ( is_object( $error_data ) ) {
$class = ' class="' . get_class( $error_data ) . '"'; $class = ' class="' . get_class( $error_data ) . '"';
@ -86,9 +92,10 @@ class WP_Ajax_Response {
if ( is_scalar( $error_data ) ) { if ( is_scalar( $error_data ) ) {
$response .= "<![CDATA[$error_data]]>"; $response .= "<![CDATA[$error_data]]>";
} elseif ( is_array( $error_data ) ) { } elseif ( is_array( $error_data ) ) {
foreach ( $error_data as $k => $v ) foreach ( $error_data as $k => $v ) {
$response .= "<$k><![CDATA[$v]]></$k>"; $response .= "<$k><![CDATA[$v]]></$k>";
} }
}
$response .= "</wp_error_data>"; $response .= "</wp_error_data>";
} }
@ -97,15 +104,16 @@ class WP_Ajax_Response {
} }
$s = ''; $s = '';
if ( is_array($supplemental) ) { if ( is_array( $r['supplemental'] ) ) {
foreach ( $supplemental as $k => $v ) foreach ( $r['supplemental'] as $k => $v ) {
$s .= "<$k><![CDATA[$v]]></$k>"; $s .= "<$k><![CDATA[$v]]></$k>";
}
$s = "<supplemental>$s</supplemental>"; $s = "<supplemental>$s</supplemental>";
} }
if ( false === $action ) if ( false === $action ) {
$action = $_POST['action']; $action = $_POST['action'];
}
$x = ''; $x = '';
$x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action $x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action
$x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>"; $x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>";