summaryrefslogtreecommitdiffstats
path: root/wp-includes/classes.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-09-14 15:04:44 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-09-14 15:04:44 +0000
commitb1d917d5d377c88241aa233d4c6403213afa05df (patch)
treec2cbc61fa1ca5297a5dd065d8a6ef7c5a855061b /wp-includes/classes.php
parent0594b4fefe09d84f0ed8ba46a6a0bb8f925027ea (diff)
downloadwordpress-mu-b1d917d5d377c88241aa233d4c6403213afa05df.tar.gz
wordpress-mu-b1d917d5d377c88241aa233d4c6403213afa05df.tar.xz
wordpress-mu-b1d917d5d377c88241aa233d4c6403213afa05df.zip
WP Merge to rev #4191
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@753 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/classes.php')
-rw-r--r--wp-includes/classes.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/wp-includes/classes.php b/wp-includes/classes.php
index a23442c..5437ed9 100644
--- a/wp-includes/classes.php
+++ b/wp-includes/classes.php
@@ -709,4 +709,67 @@ class Walker_CategoryDropdown extends Walker {
}
}
+class WP_Ajax_Response {
+ var $responses = array();
+
+ function WP_Ajax_Response( $args = '' ) {
+ if ( !empty($args) )
+ $this->add($args);
+ }
+
+ // a WP_Error object can be passed in 'id' or 'data'
+ function add( $args = '' ) {
+ if ( is_array($args) )
+ $r = &$args;
+ else
+ parse_str($args, $r);
+
+ $defaults = array('what' => 'object', 'action' => false, 'id' => '0', 'old_id' => false,
+ 'data' => '', 'supplemental' => array());
+
+ $r = array_merge($defaults, $r);
+ extract($r);
+
+ if ( is_wp_error($id) ) {
+ $data = $id;
+ $id = 0;
+ }
+
+ $response = '';
+ if ( is_wp_error($data) )
+ foreach ( $data->get_error_codes() as $code )
+ $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
+ else
+ $response = "<response_data><![CDATA[$data]]></response_data>";
+
+ $s = '';
+ if ( (array) $supplemental )
+ foreach ( $supplemental as $k => $v )
+ $s .= "<$k><![CDATA[$v]]></$k>";
+
+ if ( false === $action )
+ $action = $_POST['action'];
+
+ $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'>" : '>' );
+ $x .= $response;
+ $x .= $s;
+ $x .= "</$what>";
+ $x .= "</response>";
+
+ $this->responses[] = $x;
+ return $x;
+ }
+
+ function send() {
+ header('Content-type: text/xml');
+ echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
+ foreach ( $this->responses as $response )
+ echo $response;
+ echo '</wp_ajax>';
+ die();
+ }
+}
+
?>