Export all post from database to JSON only when the database gets updated

it’s file_put_contents which saves the data then it have to be in the hook and not in the body of the plugin : function export_posts_in_json () { $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ); $query = new WP_Query( $args ); … $data = json_encode($posts); $folder=”wp-content/themes/bootstrap/library/”; $file_name = date(‘Y-m-d’) . … Read more

WordPress wp-json API – Custom Post Type returns 403

In version 1.1 of the JSON REST API custom post type endpoints have to be registered manually. See: http://wp-api.org/guides/extending.html#registering-your-endpoints In version 2.0 we register endpoints for any custom post types registered with the show_in_rest property set to true. Documentation on how to do this: http://v2.wp-api.org/extending/custom-content-types/#registering-a-custom-post-type-with-rest-api-support

JSON not valid after json_encode posts

Newlines are not valid inside json strings. However you are outputting this code or otherwise checking it for sanity is somehow adding newlines into your long strings here. Check that your strings really are all one line and not broken up into multiple lines.

AJAX returns response 0

Your action hook should be add_action( ‘wp_ajax_cc_author_change_postauthor’, ‘cc_author_change_postauthor_callback’ ); I think because of your wrong hook, your callback function is never called. You might have got this wrong aswell. In your JS code please change your action from cc-author-change-postauthor to cc_author_change_postauthor

Importing JSON feed should the content be sanitized?

There are two aspects here obviously all input should be sanitized JSON is just a wrapper no different then any other type of container which is used to aggregate data for transmission. You almost never sanitize the container as usually in case of an error you will just not be able to extract the data … Read more

WordPress Customizer Typography: How to load just the unique Google Fonts?

This question is way too broad for a complete answer in a Q&A format, but here is roughly what I would do: Collect all system fonts in an array $sys_fonts Collect all Google fonts in an array $ggl_fonts Collect the complete info about Google fonts in a multidimensional array $ggl_fontinfo Merge $sys_fonts and $ggl_fonts in … Read more

get WP-API by page id

If you want to use v2 of the API (which is the current one you should be using), the endpoint is mysite.me/wp-json/wp/v2/pages/1234 where 1234 is the page ID. https://developer.wordpress.org/rest-api/reference/pages/#retrieve-a-page