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

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

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

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

How to hook into “register_rest_field” to modify the behavior of a custom field?

I think the most simple solution would be to use a custom filter for this. It could look something like: $schema = apply_filters(‘pluginA/register/country’, [ “type” => “string”, “description” => “The user’s country”, “arg_options” => [ “sanitize_callback” => function( $value ) { return sanitize_text_field( $value ); }, “validate_callback” => function( $value ) { return is_string( $value … Read more

How send get request to external api with username and password

Watch your keys: $headers = array( // ‘headers’ => array( // this is duplicated ‘Authorization’ => ‘Basic ‘ . base64_encode( ‘username:password’ ), ‘Accept’ => ‘application/xml’ // ) ); $res = wp_remote_request( $url, array( ‘method’ => ‘GET’, ‘headers’ => $headers ) ); Don’t send headers inside headers. Using a variable name different from args can help … 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

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