Can’t send emails through REST API

You didn’t include the code for your send_email() function, but I looked at the original source (revision 1) of your question, and it seems to me that your send_email() function is good, but if this answer doesn’t help solve the issue, then add the function code into your question body. So I don’t know why … Read more

Attach featured image to custom endpoints

To attach anything onto the results, you need to loop through each item and set the property on the object before you return it. You can do a for loop or an array_map() which essentially does a loop and sets the value for each item in the return array to what is returned by the … Read more

Filter post_content before loading in Gutenberg editor

I found that there is no way to change the data which is coming to editor when it is loaded. But it’s possible to replace the data after that. JS: script.js wp.domReady(function () { const newData = window.myNewBlocksData; if (newData) { wp.data.dispatch(‘core/block-editor’).resetBlocks(wp.blocks.parse(newData)); console.log(‘replaced’); } }) PHP: <?php class MyBlocksManipulation { public $prefix = ‘my’; public … Read more

REST API multiple media upload

While not optimal, there is nothing stopping you from sending two requests at the same time and to continue your logic after both responses are received. This is relatively easy with jQuery or JS promises, but most likely possible in all languages which has an API to send HTTP requests asynchronously. Just keep in mind … Read more

Can I authenticate with both WooCommerce consumer key and JWT?

Yes this is possible by structuring your requests appropriately. For system requests use OAuth 1.0 (consumer key as before), but encode it to include the OAuth credentials in the URL not in the headers. Having the OAuth credentials in the Authorisation header triggers the JWT error. GET https://DOMAIN/wp-json/wc/v1/subscriptions * Authorization: `OAuth 1.0` * Consumer key: … Read more

How to use the WP REST API for new user registration (sign up form)?

hopefully you’ve found the answer already. Here’s our solution, for your reference. 😀 The following code should add User Registration via REST API to your WordPress Website. It supports Registration of ‘subscriber’ and ‘customer’. Add it to your function.php add_action(‘rest_api_init’, ‘wp_rest_user_endpoints’); /** * Register a new user * * @param WP_REST_Request $request Full details about … Read more

Match REST API post output from custom endpoint

The prepare_item_for_response method of the WP_REST_Posts_Controller class “Prepares a single post output for response” by translating every property of the post object for output from the REST API. The method doesn’t run statically, so we need to instantiate a controller in our endpoint. Here’s a simple example endpoint: function endpoint( $request ) { $p = … Read more

Is it possible to nest the JSON result of WordPress REST API?

Use below code snippet function video_get_post_meta($object, $field_name, $request) {    return array( ‘video’ => array( ‘length’ => get_post_meta($object[‘id’], ‘length’, true), ‘file_name’ => get_post_meta($object[‘id’], ‘file_name’, true), ‘thumbnail_’ => get_post_meta($object[‘id’], ‘thumbnail_’, true), ‘video_url’ => get_post_meta($object[‘id’], ‘video_url’, true), )); } add_action(‘rest_api_init’, function() {    register_rest_field(‘post’, ‘video’,        array(            ‘get_callback’ => ‘video_get_post_meta’,            ‘update_callback’ => ‘video_update_post_meta’,            ‘schema’ => null        )    ); } Output … Read more

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