IXR_Error example


function _xmlrpc_wp_die_handler( $message$title = '', $args = array() ) {
    global $wp_xmlrpc_server;

    list( $message$title$parsed_args ) = _wp_die_process_input( $message$title$args );

    if ( ! headers_sent() ) {
        nocache_headers();
    }

    if ( $wp_xmlrpc_server ) {
        $error = new IXR_Error( $parsed_args['response']$message );
        $wp_xmlrpc_server->output( $error->getXml() );
    }
    if ( $parsed_args['exit'] ) {
        die();
    }
}

/** * Kills WordPress execution and displays XML response with an error message. * * This is the handler for wp_die() when processing XML requests. * * @since 5.2.0 * @access private * * @param string $message Error message. * @param string $title Optional. Error title. Default empty string. * @param string|array $args Optional. Arguments to control behavior. Default empty array. */
// Now send the request.         if ( $this->debug ) {
            echo '<pre class="ixr_request">' . htmlspecialchars( $xml ) . "\n</pre>\n\n";
        }

        $response = wp_remote_post( $url$args );

        if ( is_wp_error( $response ) ) {
            $errno       = $response->get_error_code();
            $errorstr    = $response->get_error_message();
            $this->error = new IXR_Error( -32300, "transport error: $errno $errorstr);
            return false;
        }

        if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
            $this->error = new IXR_Error( -32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')' );
            return false;
        }

        if ( $this->debug ) {
            echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n";
        }

        
// Now send the request         if ($this->debug) {
            echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n";
        }

        if ($this->timeout) {
            $fp = @fsockopen($this->server, $this->port, $errno$errstr$this->timeout);
        } else {
            $fp = @fsockopen($this->server, $this->port, $errno$errstr);
        }
        if (!$fp) {
            $this->error = new IXR_Error(-32300, 'transport error - could not open socket');
            return false;
        }
        fputs($fp$request);
        $contents = '';
        $debugContents = '';
        $gotFirstLine = false;
        $gettingHeaders = true;
        while (!feof($fp)) {
            $line = fgets($fp, 4096);
            if (!$gotFirstLine) {
                // Check line for '200'

function xmlrpc_pingback_error( $ixr_error ) {
    if ( 48 === $ixr_error->code ) {
        return $ixr_error;
    }
    return new IXR_Error( 0, '' );
}

// // Cache. //
/** * Removes a comment from the object cache. * * @since 2.3.0 * * @param int|array $ids Comment ID or an array of comment IDs to remove from cache. */
EOD;
      // Send it       $this->output($xml);
    }

    function call($methodname$args)
    {
        if (!$this->hasMethod($methodname)) {
            return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
        }
        $method = $this->callbacks[$methodname];

        // Perform the callback and send the response         if (count($args) == 1) {
            // If only one parameter just send that instead of the whole array             $args = $args[0];
        }

        // Are we dealing with a function or a method?         if (is_string($method) && substr($method, 0, 5) == 'this:') {
            


    function call($methodname$args)
    {
        // Make sure it's in an array         if ($args && !is_array($args)) {
            $args = array($args);
        }

        // Over-rides default call method, adds signature check         if (!$this->hasMethod($methodname)) {
            return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
        }
        $method = $this->callbacks[$methodname];
        $signature = $this->signatures[$methodname];
        $returnType = array_shift($signature);

        // Check the number of arguments         if (count($args) != count($signature)) {
            return new IXR_Error(-32602, 'server error. wrong number of method parameters');
        }

        // Check the argument types
'akismet_pre_check' => '1',
                'comment_pingback_target' => $pingback_args[1],
                'pingbacks_closed' => $pingbacks_closed ? '1' : '0',
                'is_multicall' => $is_multicall,
                'multicall_count' => $multicall_count,
            );

            $comment = self::auto_check_comment( $comment, 'xml-rpc' );

            if ( isset( $comment['akismet_result'] ) && 'true' == $comment['akismet_result'] ) {
                // Sad: tightly coupled with the IXR classes. Unfortunately the action provides no context and no way to return anything.                 $wp_xmlrpc_server->error( new IXR_Error( 0, 'Invalid discovery target' ) );

                // Also note that if this was part of a multicall, a spam result will prevent the subsequent calls from being executed.                 // This is probably fine, but it raises the bar for what should be acceptable as a false positive.             }
        }
    }

    /** * Ensure that we are loading expected scalar values from akismet_as_submitted commentmeta. * * @param mixed $meta_value * @return mixed */
/** * Logs user in. * * @since 2.8.0 * * @param string $username User's username. * @param string $password User's password. * @return WP_User|false WP_User object if authentication passed, false otherwise. */
    public function login( $username$password ) {
        if ( ! $this->is_enabled ) {
            $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) );
            return false;
        }

        if ( $this->auth_failed ) {
            $user = new WP_Error( 'login_prevented' );
        } else {
            $user = wp_authenticate( $username$password );
        }

        if ( is_wp_error( $user ) ) {
            $this->error = new IXR_Error( 403, __( 'Incorrect username or password.' ) );

            
Home | Imprint | This part of the site doesn't use cookies.