Can you Use the Rest API to query a custom database table

WordPress has no system of assigning privileges or access to control to code that runs in functions.php or in an enabled plugin. Therefore if you can get code to run into functions.php or a plugin in your WordPress environment, you can do anything that you can do in PHP in your web hosting environment, and … Read more

Identical wp_rest nonce returned from rest_api

Despite you already figured it out or found a solution, since this is a follow-up to the other question, I thought it’d be benefecial to post this answer, so hopefully it helps you. =) WordPress uses the native setcookie() function in PHP for setting the authentication cookies, and $_COOKIE for reading the cookies values. But … Read more

permission_callback has no effect

Are you sure that a _doing_it_wrong notice isn’t being issued? You won’t see the notice visibly output on the page because that would break the JSON response. But if you look in the headers of the response you should see a X-WP-DoingItWrong header. It should also appear if you use a plugin like this to … Read more

What is the proper way to validate and sanitize JSON response from REST API?

Thanks to @GTsvetanov from Stackoverflow.com. Missing part of my code is $request->get_json_params(); for getting json request then compare it with schema using rest_validate_value_from_schema() then using rest_sanitize_value_from_schema() for saving proper data to database. $schema = $this->user_playtime_meta_schema(); $val = $request->get_json_params();//<– my mistake $result = rest_validate_value_from_schema( $values, $schema ); if ( ! is_wp_error( rest_validate_value_from_schema( $val, $schema ) ) … Read more

how to send Ajax request in wordpress backend

When you enqueue or localize a script you’re doing it specifically for the front end or the admin. If you want to enqueue or localize a script in both, you have to specifically do it for both. This is used to enqueue/localize for the front end add_action( ‘wp_enqueue_scripts’, ‘your_function_front’ ); your_function_front() { wp_localize_script(‘scripts’, ‘myAjax’, array( … Read more

wp_get_object_terms() returns invalid taxonomy inside rest_api_init hook

I tried to reproduce the issue with the following post type and taxonomy registration code (which I put in the functions.php file of a child theme): add_action( ‘init’, function () { register_post_type( ‘venue’, [ ‘public’ => true, ‘label’ => ‘Venues’, ‘show_in_rest’ => true, ] ); register_taxonomy( ‘country’, ‘venue’, [ ‘public’ => true, ‘label’ => ‘Countries’, … Read more

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