wp/wp-includes/class-wp-ajax-response.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-includes/class-wp-ajax-response.php	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/class-wp-ajax-response.php	Mon Oct 14 18:28:13 2019 +0200
@@ -23,8 +23,9 @@
 	 * @param string|array $args Optional. Will be passed to add() method.
 	 */
 	public function __construct( $args = '' ) {
-		if ( !empty($args) )
-			$this->add($args);
+		if ( ! empty( $args ) ) {
+			$this->add( $args );
+		}
 	}
 
 	/**
@@ -63,36 +64,39 @@
 	 */
 	public function add( $args = '' ) {
 		$defaults = array(
-			'what' => 'object', 'action' => false,
-			'id' => '0', 'old_id' => false,
-			'position' => 1,
-			'data' => '', 'supplemental' => array()
+			'what'         => 'object',
+			'action'       => false,
+			'id'           => '0',
+			'old_id'       => false,
+			'position'     => 1,
+			'data'         => '',
+			'supplemental' => array(),
 		);
 
 		$r = wp_parse_args( $args, $defaults );
 
 		$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'];
+		$id       = $r['id'];
+		$what     = $r['what'];
+		$action   = $r['action'];
+		$old_id   = $r['old_id'];
+		$data     = $r['data'];
 
 		if ( is_wp_error( $id ) ) {
 			$data = $id;
-			$id = 0;
+			$id   = 0;
 		}
 
 		$response = '';
 		if ( is_wp_error( $data ) ) {
 			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 ) ) {
 					continue;
 				}
 				$class = '';
 				if ( is_object( $error_data ) ) {
-					$class = ' class="' . get_class( $error_data ) . '"';
+					$class      = ' class="' . get_class( $error_data ) . '"';
 					$error_data = get_object_vars( $error_data );
 				}
 
@@ -106,7 +110,7 @@
 					}
 				}
 
-				$response .= "</wp_error_data>";
+				$response .= '</wp_error_data>';
 			}
 		} else {
 			$response = "<response_data><![CDATA[$data]]></response_data>";
@@ -123,13 +127,13 @@
 		if ( false === $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 .=	"<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>";
-		$x .=		$response;
-		$x .=		$s;
-		$x .=	"</$what>";
-		$x .= "</response>";
+		$x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>";
+		$x .= $response;
+		$x .= $s;
+		$x .= "</$what>";
+		$x .= '</response>';
 
 		$this->responses[] = $x;
 		return $x;
@@ -145,12 +149,14 @@
 	public function send() {
 		header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) );
 		echo "<?xml version='1.0' encoding='" . get_option( 'blog_charset' ) . "' standalone='yes'?><wp_ajax>";
-		foreach ( (array) $this->responses as $response )
+		foreach ( (array) $this->responses as $response ) {
 			echo $response;
+		}
 		echo '</wp_ajax>';
-		if ( wp_doing_ajax() )
+		if ( wp_doing_ajax() ) {
 			wp_die();
-		else
+		} else {
 			die();
+		}
 	}
 }