How to use wp_send_json_error?

wp_send_json_error( ‘Error: Invalid data!’ ) Will echoes a JSON string: {“success”:false,”data”:”Error: Invalid data!”} The nice thing about wp_send_json_error() is, the parameter could also be a WP_Error object. As opposed to wp_send_json_success( ‘Everything okay.’ ) which echoes this JSON string: {“success”:true,”data”:”Everything okay.”} Both rely internally on wp_send_json() to echo the JSON data properly and die() afterwards. … Read more

fetch_feed: retrieve entries in the appearing order, not chronologically

Ok, found. I spent hours on this but I managed to find the solution. The command I was looking for was $rss->enable_order_by_date(false);. So you should set (for benefit of the community): <?php /* include the required file */ include_once(ABSPATH . WPINC . ‘/feed.php’); /* specify the source feed */ $rss = fetch_feed(‘FEED_URL’); /* disable order … Read more

Display sub-taxonomies based on SELECTED parent-taxonomy

Here’s a fully functional snippet for doing this. I added the correct WordPress table stylings This requires adding my smyles_get_taxonomy_hierarchy to add children of taxonomy to the term object This hides the child dropdown if no children exist This handles everything (and saves) based on TERM ID not the NAME .. you should always use … Read more

Disable REST API for a user ROLE

The plugin has a filter drh_allow_rest_api which determines whether the current user has full access and can skip the whitelist check. By default this is just is_user_logged_in(): /** * Allow carte blanche access for logged-in users (or allow override via filter) * * @return bool */ private function allow_rest_api() { return (bool) apply_filters( ‘dra_allow_rest_api’, is_user_logged_in() … Read more

API JSON Data in WordPress

Here is some quick first draft code for populating a dropdown from the Google Font API, I do not know about the options framework so this will not deal with that. 1. Get an API Access Key from Google Your request will need a valid key, you can follow the instruction here on how to … Read more

How Do I Add User Custom Field to REST API Response?

I got it. Turns out the tutorial I was looking at was old and I was using the wrong WP function. I was using register_api_field but the correct one to use is register_rest_field. It goes like this… function facebook_add_user_data() { register_rest_field( ‘user’, ‘facebook’, array( ‘get_callback’ => ‘rest_get_user_field’, ‘update_callback’ => null, ‘schema’ => null, ) ); … Read more