I came up with this solution.
This function checks in each directory level starting from the directory of the current file for the file wp-config.php.
<?php
function find_wp_config_path() {
$dir = dirname(__FILE__);
do {
if( file_exists($dir."/wp-config.php") ) {
return $dir;
}
} while( $dir = realpath("$dir/..") );
return null;
}
?>
To actually include the file you can use this:
if ( ! function_exists('add_action') ) {
include_once( find_wp_config_path() . '/wp-load.php' );
}
This can also be found here:
How to determine wordpress base path when wordpress core is not loaded
Related Posts:
- This page didn’t load Google Maps correctly. See the JavaScript console for technical details
- This page didn’t load Google Maps correctly. See the JavaScript console for technical details
- Constructing requests with URL Query String in Python
- Yahoo! Finance CSV file will not return Dow Jones (^DJI)
- Is there a developers api for craigslist.org
- WordPress Rest API custom endpoint optional param
- Access WordPress API Outside of WordPress (command-line PHP)
- Create API for single sign-on with 3rd party site
- Move WordPress to subdirectory, keep ALL URLs
- How to individually set WP_DEBUG on a sub-directory multisite?
- Retrieving pages with multiple tags using REST API
- How do I use the WP REST API plugin and the OAuth Server plugin to allow for registration and login?
- Should I store external API data in my WP database or keep it as a transient?
- Sending POST Request from server
- List Table API – Safe to use?
- API integration with WordPress
- POST to a REST API from a wordpress form
- get WP-API by page id
- Custom route for WP-API gives “rest_no_route” value
- How to get all posts (in chunks) via XML-RPC?
- Get more than 10 posts in a specific category with the wordpress api
- “rest_no_route” – Debug error
- utf8 encoding in json rest api
- Implementing the wp json-rest api
- How to Securely and remotely Create new user in wordpress using Rest API
- API in numbers?
- What is the official way to consume the WordPress API? (api.wordpress.org)
- Stuck with wp_remote_post sending data to an external api on user registration
- How to get title tag of an external page with http api?
- How to Hit External REST POST API in WordPress? [closed]
- register_theme_directory somehow “fails” when folder is outside of WP-Folder
- How to Increase WordPress JSON API Speed?
- WordPress JSON API Extend to Create Users [closed]
- External API to WP
- Can’t get POST data in API endpoint callback
- node-wpapi: how to handle authentication?
- Post body not working with wp_remote_post()
- Custom theme folder
- Possible to use wordpress as publishing platform but programmatically inject content?
- Where to store OAuth 2.0 client id and secret?
- Adding rest api endpoints to an old theme
- Develop REST API using WordPress for Android app [closed]
- Integrate ZOHO Recruit API?
- WP install in sub-dir white screen
- Allow logged in WordPress user to access 3rd party Laravel API via OAuth
- are there any initiatives to work wordpress as microservices?
- Sanitize Disqus API results?
- Best Practice for re-using API Data in WordPress?
- For using google api is it necessary to install the google client libraries for using Oauth 2 in wordpress installation?
- Get non-rendered content from WP-API
- Calling an API to do authentication / user login
- Add basic authentication of WordPress on any external PHP file?
- Enabling CORS with WordPress
- How do I query my WordPress posts on another HTML page using the WordPress Restful API?
- body_class REST field in WP-API
- Authenticating a user with the WP-API V2 in Postman
- WP OAuth Server “The grant type was not specified in the request”
- Submit comment via JSON from Android device
- How to send messages when a customer is registered
- WordPress keeps autoplaying my Youtube-Links no matter what I write
- Integrating API in to WordPress
- How to convert and use JSON data from a remote WordPress server?
- JSON API and notification about registration
- How to get the post_id after you successfully create new post using xmlrpc api wp newPost?
- Where to put API Code?
- Implement External API into WordPress [closed]
- Integrate WooCommerce to PromoSoftware Rest API
- hybridauth (google OAuth integration) and WP problems
- term_exists returns NULL
- Consuming an external API to publish/post to wordpress
- Set up WP Authentication from External API
- How to queue API requests with PHP in WordPress?
- WordPress API causing fatal error
- WordPress Theme/Plugin Information API Response to Text and Button
- Composer Installed Package with WordPress Rest API Endpoint
- Is there a way to get Google My Business photos on WordPress with the API or other?
- Call external API
- WordPress json rest api displaying 10 categories only
- How do I filter Child Posts by Parent Post ID for Custom Post types in WordPress REST API response?
- Creating posts, containing data from remote API
- Passing data outside of WordPress possible?
- Periodically Query an external API on wordpress site
- Post to WordPress API using cURL and login cookies
- Extending the API I created to return category names
- Rest WP_Error always return null
- Using the JSON API via HTTPS and HTTP
- Posting data from Ionic app to WordPress
- WordPress REST API Endpoint (Authors and Categories latest posts)
- Best way to make a JSON API from WordPress?
- Encrypt API key [duplicate]
- Can I get the post id when trying to make a new post using xmlrpc?
- Using PHP Api wrapper within plugin. Wrapper uses name space
- Querying Posts Using JSON API
- basic wordpress api endpoint to serve a key-value dictionary
- Is it possible to make website content available on another website?
- How to login via wordpress api and get user details?
- Send Order Confirmation automatically to customer’s mobile number
- How many users/load can the rest API handle?
- How get JSON from external API on every page load if not existing in transient?
- Send PUT remote request with BuddyPress checkbox