xmlrpc.php 3.06 KB
Newer Older
godog's avatar
godog committed
1 2 3 4 5 6 7 8
<?php
/**
 * XML-RPC protocol support for WordPress
 *
 * @package WordPress
 */

/**
lechuck's avatar
lechuck committed
9
 * Whether this is an XML-RPC Request
godog's avatar
godog committed
10 11 12
 *
 * @var bool
 */
samba's avatar
samba committed
13
define( 'XMLRPC_REQUEST', true );
godog's avatar
godog committed
14 15 16 17 18 19

// Some browser-embedded clients send cookies. We don't want them.
$_COOKIE = array();

// A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default,
// but we can do it ourself.
samba's avatar
samba committed
20
if ( ! isset( $HTTP_RAW_POST_DATA ) ) {
godog's avatar
godog committed
21 22 23
	$HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
}

agata's avatar
agata committed
24
// Fix for mozBlog and other cases where '<?xml' isn't on the very first line.
samba's avatar
samba committed
25 26 27
if ( isset( $HTTP_RAW_POST_DATA ) ) {
	$HTTP_RAW_POST_DATA = trim( $HTTP_RAW_POST_DATA );
}
godog's avatar
godog committed
28 29

/** Include the bootstrap for setting up WordPress environment */
agata's avatar
agata committed
30
require_once __DIR__ . '/wp-load.php';
godog's avatar
godog committed
31

lucha's avatar
lucha committed
32
if ( isset( $_GET['rsd'] ) ) { // http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html
samba's avatar
samba committed
33 34 35
	header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
	echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>';
	?>
godog's avatar
godog committed
36
<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">
samba's avatar
samba committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
	<service>
		<engineName>WordPress</engineName>
		<engineLink>https://wordpress.org/</engineLink>
		<homePageLink><?php bloginfo_rss( 'url' ); ?></homePageLink>
		<apis>
			<api name="WordPress" blogID="1" preferred="true" apiLink="<?php echo site_url( 'xmlrpc.php', 'rpc' ); ?>" />
			<api name="Movable Type" blogID="1" preferred="false" apiLink="<?php echo site_url( 'xmlrpc.php', 'rpc' ); ?>" />
			<api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url( 'xmlrpc.php', 'rpc' ); ?>" />
			<api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url( 'xmlrpc.php', 'rpc' ); ?>" />
			<?php
			/**
			 * Add additional APIs to the Really Simple Discovery (RSD) endpoint.
			 *
			 * @link http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html
			 *
			 * @since 3.5.0
			 */
			do_action( 'xmlrpc_rsd_apis' );
			?>
		</apis>
	</service>
godog's avatar
godog committed
58
</rsd>
samba's avatar
samba committed
59 60
	<?php
	exit;
godog's avatar
godog committed
61 62
}

agata's avatar
agata committed
63 64 65
require_once ABSPATH . 'wp-admin/includes/admin.php';
require_once ABSPATH . WPINC . '/class-IXR.php';
require_once ABSPATH . WPINC . '/class-wp-xmlrpc-server.php';
godog's avatar
godog committed
66 67

/**
lechuck's avatar
lechuck committed
68
 * Posts submitted via the XML-RPC interface get that title
samba's avatar
samba committed
69
 *
godog's avatar
godog committed
70 71 72
 * @name post_default_title
 * @var string
 */
samba's avatar
samba committed
73
$post_default_title = '';
godog's avatar
godog committed
74

lucha's avatar
lucha committed
75
/**
lucha's avatar
lucha committed
76
 * Filters the class used for handling XML-RPC requests.
lucha's avatar
lucha committed
77 78
 *
 * @since 3.1.0
lechuck's avatar
lechuck committed
79 80
 *
 * @param string $class The name of the XML-RPC server class.
lucha's avatar
lucha committed
81 82
 */
$wp_xmlrpc_server_class = apply_filters( 'wp_xmlrpc_server_class', 'wp_xmlrpc_server' );
samba's avatar
samba committed
83
$wp_xmlrpc_server       = new $wp_xmlrpc_server_class;
lechuck's avatar
lechuck committed
84

agata's avatar
agata committed
85
// Fire off the request.
lechuck's avatar
lechuck committed
86 87 88
$wp_xmlrpc_server->serve_request();

exit;
godog's avatar
godog committed
89 90 91 92

/**
 * logIO() - Writes logging info to a file.
 *
lechuck's avatar
lechuck committed
93 94
 * @deprecated 3.4.0 Use error_log()
 * @see error_log()
godog's avatar
godog committed
95 96 97 98
 *
 * @param string $io Whether input or output
 * @param string $msg Information describing logging reason.
 */
agata's avatar
agata committed
99
function logIO( $io, $msg ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
lucha's avatar
lucha committed
100
	_deprecated_function( __FUNCTION__, '3.4.0', 'error_log()' );
samba's avatar
samba committed
101
	if ( ! empty( $GLOBALS['xmlrpc_logging'] ) ) {
lechuck's avatar
lechuck committed
102
		error_log( $io . ' - ' . $msg );
samba's avatar
samba committed
103 104
	}
}