esc_attr() corrupts json values

Normally, when one want to put strings to be used in javascript, esc_js is the right function, not esc_attr. The problem is that esc_js, according to docs: Escapes text strings for echoing in JS (bold mine). So, using with esc_js you obtain a string that can be safely echoed in js, not parsed: it’s not … Read more

WP REST API format response

Since you’re filtering with the rest_prepare_{post_type} filter, you could restrict it to the WP_REST_Posts_Controller::get_items() callback, with the rest_{post_type}_query filter: add_filter( ‘rest_post_query’, function( $args ) { add_filter( ‘rest_prepare_post’, ‘api_remove_extra_data’, 12, 3 ); return $args; } ); where the post type is post. Note that in general we always want to return the filter value and I … Read more

Adding JSON Structured Data to WordPress

If you’re creating the theme yourself, you can always use Schema Microata markup directly in the theme itself. As we can see in the below example, adding extra attributes to your HTML can make it Schema compliant. In this instance, we are using itemscope, itemtype and itemprop: Taken from http://schema.org/docs/gs.html#microdata_how <div itemscope itemtype =”http://schema.org/Movie”> <h1 … Read more

Inserting custom post meta value using WP-REST API

Well, there is a way to update post meta. You have to add the update_callback when registering rest field. See the example below: function rest_api_player_meta() { register_rest_field(‘sp_player’, ‘player_meta’, array( ‘get_callback’ => ‘get_player_meta’, ‘update_callback’ => ‘update_player_meta’, ‘schema’ => null, ) ); } function get_player_meta($object) { $postId = $object[‘id’]; return get_post_meta($postId); } function update_player_meta($meta, $post) { $postId … Read more

Have WordPress generate a JSON of the content

After pondering your question some I am guessing you mean to generate actual physical JSON file in filesystem to use as data source? That would certainly be unorthodox in WP development. Typically in WP you try to minimize disk access, since it is more likely to be a bottleneck in general. Doing file writes is … Read more

WordPress JSON API returns normal site page in html. How do I get it to give me JSON?

I’m likely doing it wrong, but when I form my requests for a WordPress installation at http://www.example.com/ like this: http://www.example.com/index.php?rest_route=/my/rest/route/here I end up getting proper responses back. I had a heck of a time figuring this out and ended up grokking a URL formatted like that in the HTML returned to me. I was expecting … Read more

Android authentication

The best way to authenticate an app with the REST API would be to use OAuth. There’s a good section on OAuth Authentication the REST API documentation site. You will need to install the OAuth1 plugin on your site as well. There are some gotchas with implementing the OAuth plugin on WordPress. I found this … Read more

wordpress API for android app

Yes, WP REST API supports user authentication. With this plugin you can use OAuth authentication, application passwords, or basic authentication. Read this. Here you’ll find complete documentation. For JSON API there is a plugin called JSON API Auth. Here you’ll get it. By using it you can implement authentication with JSON API. And yes, as … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)