xmlrpc.php 3.16 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

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

agata's avatar
agata committed
18 19
// $HTTP_RAW_POST_DATA was deprecated in PHP 5.6 and removed in PHP 7.0.
// phpcs:disable PHPCompatibility.Variables.RemovedPredefinedGlobalVariables.http_raw_post_dataDeprecatedRemoved
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 );
}
agata's avatar
agata committed
28
// phpcs:enable
godog's avatar
godog committed
29 30

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

lucha's avatar
lucha committed
33
if ( isset( $_GET['rsd'] ) ) { // http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html
samba's avatar
samba committed
34 35 36
	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
37
<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">
samba's avatar
samba committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
	<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
59
</rsd>
samba's avatar
samba committed
60 61
	<?php
	exit;
godog's avatar
godog committed
62 63
}

agata's avatar
agata committed
64 65 66
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
67 68

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

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

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

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

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