WP-API user email change confirmation

wp-api didn’t has any route for new user registration as the route /users requires authentication for create operation As far as I know, using proper authentication (I’m using JWT), rest API does let you create new users. The problem is that if you go that way, you have to implement your own mail-verifcation system, since … Read more

backbone fetch() not working

fetch returns a promise, so you want to wait until the promise is resolved. For example: new wp.api.models.Post( { id: 1 } ).fetch().then( console.log ); or doing something with the data: new wp.api.models.Post( { id: 1 } ).fetch().then( post => { console.log( post ); } ); To address your comment, Promises are async – so … Read more

I am getting error message on accessing menu-endpoint

You didn’t change your prefix for that plugin’s API. Instead of /MC-ACF/wp-json/wp/v2/menus try /MC-ACF/wp-json/wp-api-menus/v2/menus That plugin developer states it right on the page you referenced in your question. If you’re wondering how I solved this. I’m not sure what your use case is, but there are newer versions of similar plugins as well. That one … Read more

Cache WP remote_get HTTP Response using Transients

function display_api_response() { $body = get_transient( ‘my_remote_response_value’ ); if ( false === $body ) { $api_url = “https://randletter2020.herokuapp.com”; $response = wp_remote_get($api_url); if (200 !== wp_remote_retrieve_response_code($response)) { return; } $body = wp_remote_retrieve_body($response); set_transient( ‘my_remote_response_value’, $body, 5*MINUTE_IN_SECONDS ); } if (‘a’ === $body) { echo ‘A wins’; } else { // Do something else. } } add_action(‘init’, … Read more

WP_REMOTE_POST Requests are being blocked by API provider [closed]

If the API is expecting a JSON object you should change your args to: $args = array ( ‘sslverify’ => false, ‘data_format’ => ‘body’, ‘headers’ => [ ‘Authorization: Bearer {API_KEY}’, ‘Content-Type: application/json’ ], ‘body’ => json_encode([ ‘region’ => ‘USA’, ‘plan’ => 1, ‘label’ => ‘API Test’, ‘app_id’ => 2 ]), ); Encode your data into … Read more

Display post title from WordPress excluding a string via API

If you’re pulling REST API data from a WordPress site (“server”) to a non-WordPress site (“client”), your client site won’t have access to WordPress functions like get_the_title(), etc. What you will receive from the server is a JSON string that will look something like this: // eg. from example.com/wp-json/wp/v2/posts [ { “id”:10887, “date”:”2022-05-04T11:25:43″, “date_gmt”:”2022-05-04T16:25:43″, “guid”: … Read more

How to quickly reorder posts in the admin panel that will persist for the wp-api

Let’s assume it stores the custom order into the menu_order column in the wp_posts table. If you mean the hierarchical page post type (supports page-attributes) then one can order with the query variables: /wp-json/wp/v2/pages/?orderby=menu_order&order=asc If you mean the post post type with: /wp-json/wp/v2/posts/ there’s a way using the rest_{post_type}_query filter: /** * Set orderby to … Read more

WP REST API V2 – Add user data to response

Solution A – Prepare User Response You can filter the response for a user to include any property you want with rest_prepare_user. add_filter( ‘rest_prepare_user’, function( $response, $user, $request ) { $response->data[ ‘first_name’ ] = get_user_meta( $user->ID, ‘first_name’, true ); $response->data[ ‘last_name’ ] = get_user_meta( $user->ID, ‘last_name’, true ); return $response; }, 10, 3 ); Solution … Read more

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