Make WordPress Core

Ticket #32246: class-wp-ajax-response.php.2.patch

File class-wp-ajax-response.php.2.patch, 4.8 KB (added by ramiy, 9 years ago)
  • wp-includes/class-wp-ajax-response.php

     
    3030        /**
    3131         * Append to XML response based on given arguments.
    3232         *
    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
    3734         *
    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.
    4737         *
    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         * }
    5159         * @return string XML response.
    5260         */
    5361        public function add( $args = '' ) {
    5462                $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()
    5970                );
    6071
    6172                $r = wp_parse_args( $args, $defaults );
    6273
    6374                $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'];
    6980
    7081                if ( is_wp_error( $id ) ) {
    7182                        $data = $id;
     
    101112                        $response = "<response_data><![CDATA[$data]]></response_data>";
    102113                }
    103114
    104                 $s = '';
     115                $supplemental = '';
    105116                if ( is_array( $r['supplemental'] ) ) {
    106117                        foreach ( $r['supplemental'] as $k => $v ) {
    107                                 $s .= "<$k><![CDATA[$v]]></$k>";
     118                                $supplemental .= "<$k><![CDATA[$v]]></$k>";
    108119                        }
    109                         $s = "<supplemental>$s</supplemental>";
     120                        $supplemental = "<supplemental>$supplemental</supplemental>";
    110121                }
    111122
    112123                if ( false === $action ) {
     
    113124                        $action = $_POST['action'];
    114125                }
    115126                $x = '';
    116                 $x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action
     127                $x .= "<response action='{$action}_$id'>";
    117128                $x .=   "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>";
    118129                $x .=           $response;
    119                 $x .=           $s;
     130                $x .=           $supplemental;
    120131                $x .=   "</$what>";
    121132                $x .= "</response>";
    122133