Make WordPress Core

Changeset 61460


Ignore:
Timestamp:
01/09/2026 08:30:52 PM (6 months ago)
Author:
westonruter
Message:

XML-RPC: Update addTwoNumbers demo method to check args prior to adding.

Invalid args now cause an IXR_Error to be returned.

Comprehensive unit tests are also added for the method.

Developed in https://github.com/WordPress/wordpress-develop/pull/10690

Follow-up to [1348].

Props josephscott, westonruter.
Fixes #64479.

Location:
trunk
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r61454 r61460  
    263263         * @since 1.5.0
    264264         *
    265          * @param array $args {
     265         * @param int[] $args {
    266266         *     Method arguments. Note: arguments must be ordered as documented.
    267267         *
     
    269269         *     @type int $1 A second number to add.
    270270         * }
    271          * @return int Sum of the two given numbers.
     271         * @return int|IXR_Error Sum of the two given numbers.
    272272         */
    273273        public function addTwoNumbers( $args ) {
     274                if ( ! is_array( $args ) || count( $args ) !== 2 || ! is_int( $args[0] ) || ! is_int( $args[1] ) ) {
     275                        $this->error = new IXR_Error( 400, __( 'Invalid arguments passed to this XML-RPC method. Requires two integers.' ) );
     276                        return $this->error;
     277                }
     278
    274279                $number1 = $args[0];
    275280                $number2 = $args[1];
Note: See TracChangeset for help on using the changeset viewer.