Working through the steps to set up this plugin.
When I try to upload the JSON file, I get a message, “No file choosen.” and nothing else happens.
Any suggestions for what could be causing this problem? The JSON file I’m trying to upload appears to be complete and valid.
Thanks in advance.
]]>reading the documentation I believe that there is a “nonce” authentication involved.
I don’t know I to do the nonce verification using the getJSON() jQuery function.
Here below is the code I wrote so far:
as fist I pass the nonce to JavaScript using:
wp_localize_script( 'rm_search_js', 'live_reserch', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'root_url' => get_site_url(),
'nonce' => wp_create_nonce( 'wp_rest' )
) );
then I set the nonce inside the jquery function,
jQuery.getJSON( live_reserch.root_url + '/wp-json/rm/research/v1/search?' + "/* rmSearchParameters */" + '&_wpnonce=' + live_reserch.nonce, data => {
// do something with the data
}
on the php side I register a new root
function rm_custom_rest_research(){
register_rest_route( 'rm/research/v1', 'search', array(
'methods' => WP_REST_SERVER::READABLE,
'callback' => 'rm_search_results'
) );
}
add_action( 'rest_api_init', 'rm_custom_rest_research' );
and finally I set the function managing the new rest API root
function rm_search_results( $data ) {
$nonce = $data['_wpnonce'];
//verify the nonce and get the current user id.
$user_id = get_current_user_id();
// do something with the $user_id
}
Does anyone knows how can I do the verification and get the current user id?
Thanks in advance.
]]>jQuery(document).ready(function(){
jQuery.getJSON('questions.json', function(json) {
s.setup(json);
});
});
I am working with child theme. These files (json and js) now are in the sub-folder of the child theme.
Where should I locate json and/or javascript files json file could be found?
Thank you
Vilnia
https://www.url.com/api/get_category_posts/?slug=slug&count=10
But using the same link with getJSON, 5 results are returned no matter what the value of “count” is:
jQuery.getJSON("https://www.vespino.nl/api/get_category_posts/?slug=onze-maud&count=10&callback=?", function(data) {
alert(JSON.stringify(data, null, ' '));
});
Strangely this last thing is only when used on mobile browsers like iPhone of on an Android device.
Can this be overruled or am I doing something wrong or is this a jQuery bug?
Newer or older versions of jQuery all seem to have this problem.
https://www.ads-software.com/plugins/json-api/
]]>