Skip to content

Commit 22ec416

Browse files
author
westi
committed
Introduce a special wp_die handler for XMLRPC requests to ensure we send an XML response.
Props koke for the original patch. See #16748. git-svn-id: http://core.svn.wordpress.org/trunk@17643 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 6769bfb commit 22ec416

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

wp-includes/functions.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,42 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) {
28542854
die();
28552855
}
28562856

2857+
/**
2858+
* Kill WordPress execution and display XML message with error message.
2859+
*
2860+
* This is the handler for wp_die when processing XMLRPC requests.
2861+
*
2862+
* @since 3.2.0
2863+
* @access private
2864+
*
2865+
* @param string $message Error message.
2866+
* @param string $title Error title.
2867+
* @param string|array $args Optional arguements to control behaviour.
2868+
*/
2869+
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
2870+
global $wp_xmlrpc_server;
2871+
$defaults = array( 'response' => 500 );
2872+
2873+
$r = wp_parse_args($args, $defaults);
2874+
2875+
if ( $wp_xmlrpc_server ) {
2876+
$error = new IXR_Error( $r['response'] , $message);
2877+
$wp_xmlrpc_server->output( $error->getXml() );
2878+
}
2879+
die();
2880+
}
2881+
2882+
/**
2883+
* Filter to enable special wp_die handler for xmlrpc requests.
2884+
*
2885+
* @since 3.2.0
2886+
* @access private
2887+
*/
2888+
function _xmlrpc_wp_die_filter() {
2889+
return '_xmlrpc_wp_die_handler';
2890+
}
2891+
2892+
28572893
/**
28582894
* Retrieve the WordPress home page URL.
28592895
*

xmlrpc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ function logIO($io,$msg) {
9898
if ( isset($HTTP_RAW_POST_DATA) )
9999
logIO("I", $HTTP_RAW_POST_DATA);
100100

101+
// Make sure wp_die output is XML
102+
add_filter( 'wp_die_handler', '_xmlrpc_wp_die_filter' );
103+
101104
// Allow for a plugin to insert a different class to handle requests.
102105
$wp_xmlrpc_server_class = apply_filters('wp_xmlrpc_server_class', 'wp_xmlrpc_server');
103106
$wp_xmlrpc_server = new $wp_xmlrpc_server_class;

0 commit comments

Comments
 (0)