Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: a84f5c96a3
Fetching contributors…

Cannot retrieve contributors at this time

50 lines (42 sloc) 1.222 kB
<?php
class WP_Lite_Autosuggest_Server extends WP_JSON_RPC_Server
{
public function __construct()
{
$this->methods['wpLiteAutosuggest.submitQuery'] = 'this:submitQuery';
}
public function submitQuery( $args = null )
{
global $wp_lite_autosuggest;
if ( empty( $args->{'query'} ) ) {
$response = new WP_Error(
-32602,
__('Invalid method parameters: wpLiteAutosuggest.submitQuery requires that a query text be specified.', 'wp-lite-autosuggest')
);
} else {
$results = $wp_lite_autosuggest->get_results_from_query( $args->{'query'}, get_object_vars( $args ) );
$json_response_wrap = array();
foreach( $results as $link ) {
$json_response_wrap[] = $link;
}
if ( is_wp_error( $results ) ) {
return $results;
} else {
return array(
'results' => $json_response_wrap,
);
}
}
return $response;
}
}
function wp_lite_autosuggest_filter_json_server_classname( $server_class = '', $method = '' )
{
switch( $method ) :
case 'wpLiteAutosuggest.submitQuery' :
$server_class = 'WP_Lite_Autosuggest_Server';
break;
endswitch;
return $server_class;
}
add_filter('json_server_classname', 'wp_lite_autosuggest_filter_json_server_classname', 10, 2);
Jump to Line
Something went wrong with that request. Please try again.