Changeset 4187 for trunk/wp-includes/classes.php
- Timestamp:
- 09/13/2006 09:39:53 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/classes.php
r4186 r4187 710 710 } 711 711 712 class WP_Ajax_Response { 713 var $responses = array(); 714 715 function WP_Ajax_Response( $args = '' ) { 716 if ( !empty($args) ) 717 $this->add($args); 718 } 719 720 // a WP_Error object can be passed in 'id' or 'data' 721 function add( $args = '' ) { 722 if ( is_array($args) ) 723 $r = &$args; 724 else 725 parse_str($args, $r); 726 727 $defaults = array('what' => 'object', 'action' => false, 'id' => '0', 'old_id' => false, 728 'data' => '', 'supplemental' => array()); 729 730 $r = array_merge($defaults, $r); 731 extract($r); 732 733 if ( is_wp_error($id) ) { 734 $data = $id; 735 $id = 0; 736 } 737 738 $response = ''; 739 if ( is_wp_error($data) ) 740 foreach ( $data->get_error_codes() as $code ) 741 $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>"; 742 else 743 $response = "<response_data><![CDATA[$data]]></response_data>"; 744 745 $s = ''; 746 if ( (array) $supplemental ) 747 foreach ( $supplemental as $k => $v ) 748 $s .= "<$k><![CDATA[$v]]></$k>"; 749 750 if ( false === $action ) 751 $action = $_POST['action']; 752 753 $x = ''; 754 $x .= "<response action='$action_$id'>"; // The action attribute in the xml output is formatted like a nonce action 755 $x .= "<$what id='$id'" . ( false !== $old_id ? "old_id='$old_id'>" : '>' ); 756 $x .= $response; 757 $x .= $s; 758 $x .= "</$what>"; 759 $x .= "</response>"; 760 761 $this->responses[] = $x; 762 return $x; 763 } 764 765 function send() { 766 header('Content-type: text/xml'); 767 echo "<?xml version='1.0' standalone='yes'?><wp_ajax>"; 768 foreach ( $this->responses as $response ) 769 echo $response; 770 echo '</wp_ajax>'; 771 die(); 772 } 773 } 774 712 775 ?>
Note: See TracChangeset
for help on using the changeset viewer.