Make WordPress Core

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

File class-wp-ajax-response.php.patch, 2.9 KB (added by ramiy, 9 years ago)

Docs: Rewrite the $args parameter in WP_Ajax_Response::add()

  • 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. XML response arguments to override defaults.
    4737         *
    48          * @since 2.1.0
    49          *
    50          * @param string|array $args Override defaults.
     38         *     @type string          $what         XMLRPC response type. Default is 'object'.
     39         *     @type bool            $action       Use nonce. Default is false.
     40         *     @type int|WP_Error    $id           The id. Default is '0'.
     41         *     @type int|false       $old_id       The previous ID. Default is false.
     42         *     @type string          $position     bottom = 1 ; top = -1 ; after = html ID ;
     43         *                                         before = -html ID ; Default is 1 (bottom).
     44         *     @type string|WP_Error $data         The content or message. Default is empty.
     45         *     @type array           $supplemental An array of strings that will be children
     46         *                                         of the <supplemental> element.
     47         * }
    5148         * @return string XML response.
    5249         */
    5350        public function add( $args = '' ) {
    5451                $defaults = array(
    55                         'what' => 'object', 'action' => false,
    56                         'id' => '0', 'old_id' => false,
    57                         'position' => 1,
    58                         'data' => '', 'supplemental' => array()
     52                        'what'         => 'object',
     53                        'action'       => false,
     54                        'id'           => '0',
     55                        'old_id'       => false,
     56                        'position'     => 1,
     57                        'data'         => '',
     58                        'supplemental' => array()
    5959                );
    6060
    6161                $r = wp_parse_args( $args, $defaults );
    6262
    6363                $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'];
     64                $id       = $r['id'];
     65                $what     = $r['what'];
     66                $action   = $r['action'];
     67                $old_id   = $r['old_id'];
     68                $data     = $r['data'];
    6969
    7070                if ( is_wp_error( $id ) ) {
    7171                        $data = $id;