WordPress REST API call generates nonce twice on every call
WordPress REST API call generates nonce twice on every call
WordPress REST API call generates nonce twice on every call
When working with the API recently I found if the authentication header with the consumer key as the username and the consumer secret as the password is present and valid this sets the current user global as the matched user. I found the core executes the REST route until current_user_can is called, at which point … Read more
I managed to solve this and access the JSON data using a foreach loop: $json = lusso_posts(); #var_dump( $json ); #die(); foreach( $json as $post ) { $titles = $post->title; $images = $post->featured_image->guid; ?> <div class=”lusso-posts”> <div class=”image-container”><img src=”https://wordpress.stackexchange.com/questions/210472/<?php echo $images; ?>” /> </div> <h4><?php echo $titles; ?></h4> </div> <?php }
I would suggest to not use WP REST API for this purpose, since it’s being used on homepage and not any remote app/service. The REST API is supposed to grant access to any already publicly available data to a remote developer. Since you’re not providing any public data but registering users from homepage, Ajax might … Read more
I’m not familiar with Gutenberg, but as you mentioned it as an example, I assume you didn’t mean “only” Gutenberg. The wp_enqeue_script() or wp_enqueue_style() functions do not accept arguments regarding posts or pages. The script are registered and rendered globally. If a script is output on certain posts only, then it has to be a … Read more
var parentId = 96; // the post id var metaData = new wp.api.collections.PostMeta(”, {parent: parentId}); metaData.fetch() .done(function(data) { var someKey = data.findWhere({key: ‘someKey’}); someKey.set(‘value’, ‘newValue’); someKey.save({parent: parentId}); });
The REST API has no parameters, options to solve this – in my opinion. But you should register only if the users have the capability in his role, like the follow example. add_action( ‘rest_api_init’, function() { // Exit, if the logged in user have not enough rights. if ( ! current_user_can( ‘edit_posts’ ) ) { … Read more
Two things to look at: 1) register_meta() 2) custom-fields support on post type. 1) register_meta You can register your custom post meta with show_in_rest => true to make it accessible via the api. Bottom of this page: Modifying Responses, provides the following example: <?php // The object type. For custom post types, this is ‘post’; … Read more
It should be enough to add the content disposition field. But specifically it’s Content-Disposition not Content-disposition I would also add some validation to your filename parameter thats being passed to file_get_contents to ensure it exists and it’s valid. Else you might be vulnerable to directory traversal attacks or remote URL requests
I have the same problem, i search on google finally with the help of the above answer i found out the solution. this may help others. $this->base = home register_rest_route( $namespace, “https://wordpress.stackexchange.com/” . $this->base . “https://wordpress.stackexchange.com/” . ‘products’ . “https://wordpress.stackexchange.com/”, array( array( ‘methods’ => WP_REST_Server::READABLE, ‘callback’ => array( $this, ‘rest_api_popular_products’), ), ) ); register_rest_route( $namespace, … Read more