WP REST – video and audio players

Ran into this same issue and I found the answer after many hours and almost giving up. It’s in a bit of code that written to make the Customizer work with playlists. Checkout this comment from /wp-includes/widgets/class-wp-widget-text.php: /** * Enqueue preview scripts. * * These scripts normally are enqueued just-in-time when a playlist shortcode is … 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

WP REST API: Order posts by meta value (acf)?

I’m guessing you haven’t exposed meta_key and meta_value to the REST API with the rest_query_vars filter, so this should do it: function my_add_meta_vars ($current_vars) { $current_vars = array_merge ($current_vars, array (‘meta_key’, ‘meta_value’)); return $current_vars; } add_filter (‘rest_query_vars’, ‘my_add_meta_vars’); Then you can refer to meta_key and meta_value in your query. Be aware that this obviously exposes … Read more

Hiding API routes list

You can use the filter hook ‘rest_index’ : add_filter(‘rest_index’, function ($response) { $data = $response->get_data(); $data[‘namespaces’] = []; $data[‘routes’] = []; return $data; }, 9999, 1); It is possible to remove your route from $data[‘namespaces’] and $data[‘routes’]

How to build a plugin that supports authenticated POST requests to the REST API from external servers?

Answering my own question. For plugin developers, the directive is to use current_user_can() in your code as usual in the REST endpoints, as Core does. WordPress 5.4 does not support authenticated requests originated from outside WordPress to the REST API yet. But your clients can use plugins such as Basic Auth, OAuth2 or JWT to … Read more

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