Obtain full v2 REST url?

You could add the path argument to the get_rest_url() function as per the WordPress Developer docs – https://developer.wordpress.org/reference/functions/get_rest_url/ – in order to get the path you need: get_rest_url( null, ‘wp/v2/’ ); This would produce: http://mywebsite.com/wp-json/wp/v2/

Check Password Strength using WordPress API

WordPress uses the zxcvbn javascript library by Dropbox, to estimate the password strength. We can see the implementation in: /wp-admin/js/password-strength-meter.js /wp-admin/js/user-profile.js with: strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 ); As far as I know there’s no explicit PHP WordPress API for estimating the password strength, but zxcvbn has been ported to a PHP library here, … Read more

How to search by metadata using REST API

How can I search it by metadata? As far as I know, there’s no standard/built-in way of doing that (for the time being). But with custom coding, you can make it possible: You can append a city to the query string: /wp-json/wp/v2/horario_busao?city=London And then use the rest_{$this->post_type}_query filter to set the meta key/value pair which … Read more

Gutenberg Custom Block Getting All Posts

In addition to loading the wp-api script as mentioned here: wp_enqueue_script( ‘wp-api’ ); // or use below when enqueueing as dependency //wp_enqueue_script( ‘my_script’, ‘path/to/my/script’, array( ‘wp-api’ ) ); You should also know that each collection is a function (equivalent to a class in PHP), so you need to use the new keyword to instantiate a … Read more

How to retrieve custom meta term of category taxonomy from WP Rest API?

First you need to tell WordPress to show this custom field in the API response: register_term_meta(‘category’, ‘_category_color’, [‘show_in_rest’ => true]); Then you can filter the category term API endpoint like so: add_filter( ‘rest_prepare_category’,function($response, $item, $request){ $color = get_term_meta( $item->term_id, ‘_category_color’, true ); $response->data[‘color’] = $color ?: ”; return $response; }, 10, 3);

Application Password is not enable by default?

If you want to add that single filter, you can do it in your theme’s functions.php file. If you’d prefer to keep it out of the theme, you can make it a simple Must Use Plugin. Make a file like wp-content/mu-plugins/enable-application-passwords.php with this file content: <?php /** * Plugin Name: Enable Application Passwords * Description: … Read more

WordPress Rest API response

You might be able to output your headers with the response. Then just kill the request with exit();. The default is usually to return a value and let the process encode and output for you. Based on http://v2.wp-api.org/extending/adding/ function my_awesome_func( $data ) { header(“Content-Type: text/plain”); print_r( array(‘foo’=>’bar’)); exit(); } add_action( ‘rest_api_init’, function () { register_rest_route( … Read more

How add meta fields to a user with the wp-api?

I have managed to do this with hooking into rest_insert_user. I send an array like this: var data = { first_name: user.first_name, last_name: user.last_name, name: user.display_name, email: user.email, description: user.description, meta: { ‘wpcf-phone’: user.phone, ‘wpcf-institution’: user.institution, ‘wpcf-birthday’: Math.round(new Date(user.birthday).getTime()/1000) } }; And treat only the meta data through the hook as this: function aa_user_update($user, $request, … Read more

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