Edit File by line
/home/zeestwma/redstone.../wp-inclu...
File: class-wp-ajax-response.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Send XML response back to Ajax request.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 2.1.0
[5] Fix | Delete
*/
[6] Fix | Delete
#[AllowDynamicProperties]
[7] Fix | Delete
class WP_Ajax_Response {
[8] Fix | Delete
/**
[9] Fix | Delete
* Store XML responses to send.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 2.1.0
[12] Fix | Delete
* @var array
[13] Fix | Delete
*/
[14] Fix | Delete
public $responses = array();
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Constructor - Passes args to WP_Ajax_Response::add().
[18] Fix | Delete
*
[19] Fix | Delete
* @since 2.1.0
[20] Fix | Delete
*
[21] Fix | Delete
* @see WP_Ajax_Response::add()
[22] Fix | Delete
*
[23] Fix | Delete
* @param string|array $args Optional. Will be passed to add() method.
[24] Fix | Delete
*/
[25] Fix | Delete
public function __construct( $args = '' ) {
[26] Fix | Delete
if ( ! empty( $args ) ) {
[27] Fix | Delete
$this->add( $args );
[28] Fix | Delete
}
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Appends data to an XML response based on given arguments.
[33] Fix | Delete
*
[34] Fix | Delete
* With `$args` defaults, extra data output would be:
[35] Fix | Delete
*
[36] Fix | Delete
* <response action='{$action}_$id'>
[37] Fix | Delete
* <$what id='$id' position='$position'>
[38] Fix | Delete
* <response_data><![CDATA[$data]]></response_data>
[39] Fix | Delete
* </$what>
[40] Fix | Delete
* </response>
[41] Fix | Delete
*
[42] Fix | Delete
* @since 2.1.0
[43] Fix | Delete
*
[44] Fix | Delete
* @param string|array $args {
[45] Fix | Delete
* Optional. An array or string of XML response arguments.
[46] Fix | Delete
*
[47] Fix | Delete
* @type string $what XML-RPC response type. Used as a child element of `<response>`.
[48] Fix | Delete
* Default 'object' (`<object>`).
[49] Fix | Delete
* @type string|false $action Value to use for the `action` attribute in `<response>`. Will be
[50] Fix | Delete
* appended with `_$id` on output. If false, `$action` will default to
[51] Fix | Delete
* the value of `$_POST['action']`. Default false.
[52] Fix | Delete
* @type int|WP_Error $id The response ID, used as the response type `id` attribute. Also
[53] Fix | Delete
* accepts a `WP_Error` object if the ID does not exist. Default 0.
[54] Fix | Delete
* @type int|false $old_id The previous response ID. Used as the value for the response type
[55] Fix | Delete
* `old_id` attribute. False hides the attribute. Default false.
[56] Fix | Delete
* @type string $position Value of the response type `position` attribute. Accepts 1 (bottom),
[57] Fix | Delete
* -1 (top), HTML ID (after), or -HTML ID (before). Default 1 (bottom).
[58] Fix | Delete
* @type string|WP_Error $data The response content/message. Also accepts a WP_Error object if the
[59] Fix | Delete
* ID does not exist. Default empty.
[60] Fix | Delete
* @type array $supplemental An array of extra strings that will be output within a `<supplemental>`
[61] Fix | Delete
* element as CDATA. Default empty array.
[62] Fix | Delete
* }
[63] Fix | Delete
* @return string XML response.
[64] Fix | Delete
*/
[65] Fix | Delete
public function add( $args = '' ) {
[66] Fix | Delete
$defaults = array(
[67] Fix | Delete
'what' => 'object',
[68] Fix | Delete
'action' => false,
[69] Fix | Delete
'id' => '0',
[70] Fix | Delete
'old_id' => false,
[71] Fix | Delete
'position' => 1,
[72] Fix | Delete
'data' => '',
[73] Fix | Delete
'supplemental' => array(),
[74] Fix | Delete
);
[75] Fix | Delete
[76] Fix | Delete
$parsed_args = wp_parse_args( $args, $defaults );
[77] Fix | Delete
[78] Fix | Delete
$position = preg_replace( '/[^a-z0-9:_-]/i', '', $parsed_args['position'] );
[79] Fix | Delete
$id = $parsed_args['id'];
[80] Fix | Delete
$what = $parsed_args['what'];
[81] Fix | Delete
$action = $parsed_args['action'];
[82] Fix | Delete
$old_id = $parsed_args['old_id'];
[83] Fix | Delete
$data = $parsed_args['data'];
[84] Fix | Delete
[85] Fix | Delete
if ( is_wp_error( $id ) ) {
[86] Fix | Delete
$data = $id;
[87] Fix | Delete
$id = 0;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
$response = '';
[91] Fix | Delete
if ( is_wp_error( $data ) ) {
[92] Fix | Delete
foreach ( (array) $data->get_error_codes() as $code ) {
[93] Fix | Delete
$response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message( $code ) . ']]></wp_error>';
[94] Fix | Delete
$error_data = $data->get_error_data( $code );
[95] Fix | Delete
if ( ! $error_data ) {
[96] Fix | Delete
continue;
[97] Fix | Delete
}
[98] Fix | Delete
$class = '';
[99] Fix | Delete
if ( is_object( $error_data ) ) {
[100] Fix | Delete
$class = ' class="' . get_class( $error_data ) . '"';
[101] Fix | Delete
$error_data = get_object_vars( $error_data );
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
$response .= "<wp_error_data code='$code'$class>";
[105] Fix | Delete
[106] Fix | Delete
if ( is_scalar( $error_data ) ) {
[107] Fix | Delete
$response .= "<![CDATA[$error_data]]>";
[108] Fix | Delete
} elseif ( is_array( $error_data ) ) {
[109] Fix | Delete
foreach ( $error_data as $k => $v ) {
[110] Fix | Delete
$response .= "<$k><![CDATA[$v]]></$k>";
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$response .= '</wp_error_data>';
[115] Fix | Delete
}
[116] Fix | Delete
} else {
[117] Fix | Delete
$response = "<response_data><![CDATA[$data]]></response_data>";
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
$s = '';
[121] Fix | Delete
if ( is_array( $parsed_args['supplemental'] ) ) {
[122] Fix | Delete
foreach ( $parsed_args['supplemental'] as $k => $v ) {
[123] Fix | Delete
$s .= "<$k><![CDATA[$v]]></$k>";
[124] Fix | Delete
}
[125] Fix | Delete
$s = "<supplemental>$s</supplemental>";
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if ( false === $action ) {
[129] Fix | Delete
$action = $_POST['action'];
[130] Fix | Delete
}
[131] Fix | Delete
$x = '';
[132] Fix | Delete
$x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action.
[133] Fix | Delete
$x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>";
[134] Fix | Delete
$x .= $response;
[135] Fix | Delete
$x .= $s;
[136] Fix | Delete
$x .= "</$what>";
[137] Fix | Delete
$x .= '</response>';
[138] Fix | Delete
[139] Fix | Delete
$this->responses[] = $x;
[140] Fix | Delete
return $x;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Display XML formatted responses.
[145] Fix | Delete
*
[146] Fix | Delete
* Sets the content type header to text/xml.
[147] Fix | Delete
*
[148] Fix | Delete
* @since 2.1.0
[149] Fix | Delete
*/
[150] Fix | Delete
public function send() {
[151] Fix | Delete
header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) );
[152] Fix | Delete
echo "<?xml version='1.0' encoding='" . get_option( 'blog_charset' ) . "' standalone='yes'?><wp_ajax>";
[153] Fix | Delete
foreach ( (array) $this->responses as $response ) {
[154] Fix | Delete
echo $response;
[155] Fix | Delete
}
[156] Fix | Delete
echo '</wp_ajax>';
[157] Fix | Delete
if ( wp_doing_ajax() ) {
[158] Fix | Delete
wp_die();
[159] Fix | Delete
} else {
[160] Fix | Delete
die();
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function