How to avoid loading wp-load.php from external php scripts?

Pretty much wp-load.php is the only way to go. I don’t think there is really another way to load the WordPress functions safely… You can account for path variations by recursively including it from any file where you need it though… eg. function file_find_require($file,$folder=null) { if ($folder === null) {$folder = dirname(__FILE__);} $path = $folder.DIRECTORY_SEPARATOR.$file; … Read more

Adding rest api endpoints to an old theme

WordPress REST API has nothing directly to do with the theme, REST API is in the WordPress core, and any plugin and theme can be made to support it. Normal WordPress themes don’t use REST API: it is relatively new part of the WordPress, and so far, very few themes are made to use REST … Read more

How can I cache WordPress Rest API Response

You should create a new instance from WP_REST_Response to set the Cache-Control value. <?php register_rest_route(‘wp/v2’, ‘/your_endpoint’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘function_callback’, )); function function_callback($data) { $response = array( 1,2,3,4,5,6,7,8 ); $result = new WP_REST_Response($response, 200); // Set headers. $result->set_headers(array(‘Cache-Control’ => ‘max-age=3600’)); return $result; } Click here to get more info about directives.

Post body not working with wp_remote_post()

You’re setting the Content-Type header to application/json and wp_remote_post() doesn’t intelligently JSON-encode the request data (the body array), so you should manually do it. So for example: ‘body’ => json_encode( array( ‘Username’ => ‘myusername’, ‘Password’ => ‘mypassword’ ) )

node-wpapi: how to handle authentication?

I’m the author of the node-wpapi library, thanks for checking it out. Unfortunately we do not currently support any external authentication scheme out of the box, because WordPress itself does not ship with any authentication scheme other than the cookie/nonce option (which doesn’t work with external apps, as you describe). There are plugins for authenticating … Read more

Headless WordPress – Issue with plugin path

I understand the question and answer are from more than a year ago, but I just wanted to add some additional information in hopes it might be useful for future visitors of this Question. Recently, while setting up a Headless WordPress CMS with Roots Bedrock, I came across the same issue and solved it with … Read more

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