Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Introduce a special wp_die handler for XMLRPC requests to ensure we s…

…end an XML response.

Props koke for the original patch. See #16748.

git-svn-id: http://svn.automattic.com/wordpress/trunk@17643 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
commit eed35967cc88e021fda5899679740180740d1bfa 1 parent 9c0a5cd
westi authored
Showing with 39 additions and 0 deletions.
  1. +36 −0 wp-includes/functions.php
  2. +3 −0  xmlrpc.php
View
36 wp-includes/functions.php
@@ -2855,6 +2855,42 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) {
}
/**
+ * Kill WordPress execution and display XML message with error message.
+ *
+ * This is the handler for wp_die when processing XMLRPC requests.
+ *
+ * @since 3.2.0
+ * @access private
+ *
+ * @param string $message Error message.
+ * @param string $title Error title.
+ * @param string|array $args Optional arguements to control behaviour.
+ */
+function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
+ global $wp_xmlrpc_server;
+ $defaults = array( 'response' => 500 );
+
+ $r = wp_parse_args($args, $defaults);
+
+ if ( $wp_xmlrpc_server ) {
+ $error = new IXR_Error( $r['response'] , $message);
+ $wp_xmlrpc_server->output( $error->getXml() );
+ }
+ die();
+}
+
+/**
+ * Filter to enable special wp_die handler for xmlrpc requests.
+ *
+ * @since 3.2.0
+ * @access private
+ */
+function _xmlrpc_wp_die_filter() {
+ return '_xmlrpc_wp_die_handler';
+}
+
+
+/**
* Retrieve the WordPress home page URL.
*
* If the constant named 'WP_HOME' exists, then it willl be used and returned by
View
3  xmlrpc.php
@@ -98,6 +98,9 @@ function logIO($io,$msg) {
if ( isset($HTTP_RAW_POST_DATA) )
logIO("I", $HTTP_RAW_POST_DATA);
+// Make sure wp_die output is XML
+add_filter( 'wp_die_handler', '_xmlrpc_wp_die_filter' );
+
// Allow for a plugin to insert a different class to handle requests.
$wp_xmlrpc_server_class = apply_filters('wp_xmlrpc_server_class', 'wp_xmlrpc_server');
$wp_xmlrpc_server = new $wp_xmlrpc_server_class;
Please sign in to comment.
Something went wrong with that request. Please try again.