Skip to content

Instantly share code, notes, and snippets.

@ericmann
Created June 5, 2012 17:26
Show Gist options
  • Save ericmann/2876388 to your computer and use it in GitHub Desktop.
Save ericmann/2876388 to your computer and use it in GitHub Desktop.
"Phone app" template from WordCamp Phoenix presentation
<?php
/*
Template Name: RPC Test
*/
/**
* This template interacts with a new XML-RPC endpoint created specifically to handle `wcphx.change_query`
* Code for the endpoint is available in a ZIP file at: http://eam.me/3-
* Slides from the WordCamp Phoenix presentation are at: http://www.slideshare.net/ericmann/playing-nice-with-others-11758893
* Video from the presentation is at: http://wordpress.tv/2012/06/04/eric-mann-playing-nice-with-others-integrating-wp-with-other-apis/
**/
$message = '';
if ( isset( $_POST[ 'rpc-send' ] ) ) {
include_once(ABSPATH . WPINC . '/class-IXR.php');
include_once(ABSPATH . WPINC . '/class-wp-http-ixr-client.php');
$query = $_POST[ 'query' ];
$client = new WP_HTTP_IXR_Client( "http://wcphx.jumping-duck.com/xmlrpc.php" );
$result = $client->query( 'wcphx.change_query', array(
"demo", // WordPress user name
"demopass", // WordPress password
$query // Query string to set
) );
if ( $result ) {
$message ='<p>Search query changed!</p>';
} else {
$message = '<p>Something went wrong ...</p>';
}
}
?>
<!doctype html>
<html lang="en">
<head>
<title>Proto</title>
<meta charset="utf-8">
<link rel="stylesheet" href="<?php print get_stylesheet_uri(); ?>">
</head>
<body>
<?php echo $message; ?>
<form action="" method="post">
<input type="text" id="query" name="query" />
<input type="submit" value="Update Query" />
<input type="hidden" name="rpc-send" id="rpc-send" value="true" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment