Ticket #32246: class-wp-ajax-response.php.2.patch
File class-wp-ajax-response.php.2.patch, 4.8 KB (added by , 9 years ago) |
---|
-
wp-includes/class-wp-ajax-response.php
30 30 /** 31 31 * Append to XML response based on given arguments. 32 32 * 33 * The arguments that can be passed in the $args parameter are below. It is 34 * also possible to pass a WP_Error object in either the 'id' or 'data' 35 * argument. The parameter isn't actually optional, content should be given 36 * in order to send the correct response. 33 * @since 2.1.0 37 34 * 38 * 'what' argument is a string that is the XMLRPC response type. 39 * 'action' argument is a boolean or string that acts like a nonce. 40 * 'id' argument can be WP_Error or an integer. 41 * 'old_id' argument is false by default or an integer of the previous ID. 42 * 'position' argument is an integer or a string with -1 = top, 1 = bottom, 43 * html ID = after, -html ID = before. 44 * 'data' argument is a string with the content or message. 45 * 'supplemental' argument is an array of strings that will be children of 46 * the supplemental element. 35 * @param string|array $args { 36 * Optional. An array or string of XML response arguments. 47 37 * 48 * @since 2.1.0 49 * 50 * @param string|array $args Override defaults. 38 * @type string $what XMLRPC response type. Used as a child element of 39 * `<response>`. Default is 'object' (`<object>`). 40 * @type bool $action Whether to use a nonce action in the responce 41 * action attribute `<response action="">`. 42 * Default is false, not to use nonces. 43 * @type int|WP_Error $id The response ID, used as the response type `id` 44 * attribute. Or `WP_Error` object if the ID does 45 * not exist. Default is '0'. 46 * @type int|false $old_id The previous response ID, used as the response 47 * type `old_id` attribute. Or false, to hide this 48 * attribute. Default is false. 49 * @type string $position The response position, used as the response type 50 * `position` attribute. Available positions: 51 * bottom = 1 ; top = -1 ; 52 * after = html ID ; before = -html ID ; 53 * Default is 1 (bottom). 54 * @type string|WP_Error $data The response content/message. Or `WP_Error` object 55 * if the ID does not exist. Default is empty response. 56 * @type array $supplemental An array of strings that will be children of the 57 * `<supplemental>` element. Default is empty array. 58 * } 51 59 * @return string XML response. 52 60 */ 53 61 public function add( $args = '' ) { 54 62 $defaults = array( 55 'what' => 'object', 'action' => false, 56 'id' => '0', 'old_id' => false, 57 'position' => 1, 58 'data' => '', 'supplemental' => array() 63 'what' => 'object', 64 'action' => false, 65 'id' => '0', 66 'old_id' => false, 67 'position' => 1, 68 'data' => '', 69 'supplemental' => array() 59 70 ); 60 71 61 72 $r = wp_parse_args( $args, $defaults ); 62 73 63 74 $position = preg_replace( '/[^a-z0-9:_-]/i', '', $r['position'] ); 64 $id = $r['id'];65 $what = $r['what'];66 $action = $r['action'];67 $old_id = $r['old_id'];68 $data = $r['data'];75 $id = $r['id']; 76 $what = $r['what']; 77 $action = $r['action']; 78 $old_id = $r['old_id']; 79 $data = $r['data']; 69 80 70 81 if ( is_wp_error( $id ) ) { 71 82 $data = $id; … … 101 112 $response = "<response_data><![CDATA[$data]]></response_data>"; 102 113 } 103 114 104 $s = '';115 $supplemental = ''; 105 116 if ( is_array( $r['supplemental'] ) ) { 106 117 foreach ( $r['supplemental'] as $k => $v ) { 107 $s .= "<$k><![CDATA[$v]]></$k>";118 $supplemental .= "<$k><![CDATA[$v]]></$k>"; 108 119 } 109 $s = "<supplemental>$s</supplemental>";120 $supplemental = "<supplemental>$supplemental</supplemental>"; 110 121 } 111 122 112 123 if ( false === $action ) { … … 113 124 $action = $_POST['action']; 114 125 } 115 126 $x = ''; 116 $x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action127 $x .= "<response action='{$action}_$id'>"; 117 128 $x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>"; 118 129 $x .= $response; 119 $x .= $s ;130 $x .= $supplemental; 120 131 $x .= "</$what>"; 121 132 $x .= "</response>"; 122 133