You can create a plugin to contain your code. The admin_post_
action can be used to trigger a request handler. WordPress core will be loaded, and the API will work.
<?php
/*
Plugin Name: Ben's GF Plugin
*/
// for logged-in users
add_action( 'admin_post_ben_gf', 'ben_gf_handle_request' );
// for non logged-in users
add_action( 'admin_post_nopriv_ben_gf', 'ben_gf_handle_request' );
function ben_gf_handle_request() {
// Your processing code.
// WordPress functions will work here.
echo 'Your home url: ' . home_url();
// die() at the end to terminate execution
die();
}
This will map your request handler to the URL:
http://www.example.com/wp-admin/admin-post.php?action=ben_gf
Use caution if you are allowing non-logged in users to access this URL, you don’t want to publicly expose sensitive data.
Related Posts:
- What is an Endpoint?
- Yahoo! Finance CSV file will not return Dow Jones (^DJI)
- Is there a developers api for craigslist.org
- How do you get the API key for Locu?
- Access WordPress API Outside of WordPress (command-line PHP)
- WP REST API only returning partial list of users
- What is the best way to get directory path for wp-config.php?
- 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?
- WordPress.org Support Forum API
- Authentication/API Questions
- Custom route for WP-API gives “rest_no_route” value
- Connect external web app to wordpress
- How to get all posts (in chunks) via XML-RPC?
- How to add a custom parameter to a WP API default route?
- Get more than 10 posts in a specific category with the wordpress api
- “rest_no_route” – Debug error
- utf8 encoding in json rest api
- Authentication for a mobile app connected via wp-rest api?
- curl POST work with user meta but not the custom user meta
- Implementing the wp json-rest api
- How to Securely and remotely Create new user in wordpress using Rest API
- how to get nonce using json api
- What is the official way to consume the WordPress API? (api.wordpress.org)
- How to get title tag of an external page with http api?
- How to Hit External REST POST API in WordPress? [closed]
- API getting null values with wp_remote_post
- WordPress JSON API Extend to Create Users [closed]
- External API to WP
- Headless WordPress – Issue with plugin path
- Can’t get POST data in API endpoint callback
- node-wpapi: how to handle authentication?
- Post body not working with wp_remote_post()
- Possible to use wordpress as publishing platform but programmatically inject content?
- Adding rest api endpoints to an old theme
- How to avoid loading wp-load.php from external php scripts?
- Develop REST API using WordPress for Android app [closed]
- are there any initiatives to work wordpress as microservices?
- Sanitize Disqus API results?
- I want to retrieve all posts of a blog without username & password
- 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?
- WordPress Google Calendar Oath 404
- WordPress as GraphQL client
- Get non-rendered content from WP-API
- How to save post with different languages and linked them with WPML?
- Calling an API to do authentication / user login
- Add basic authentication of WordPress on any external PHP file?
- Store regex expression in WordPress DB using Options API
- cURL to install theme
- Enabling CORS with WordPress
- 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
- WP List Table in custom post type
- How to send messages when a customer is registered
- Save external API calls in WordPress
- How to add an endpoint for my custom post type? /wp-json/wp/v2/posts is working but it didn’t in the custom post
- 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?
- Use WordPress user database in external php application
- Implement External API into WordPress [closed]
- Integrate WooCommerce to PromoSoftware Rest API
- Theme Customization API Changes not Saving
- term_exists returns NULL
- Consuming an external API to publish/post to wordpress
- Set up WP Authentication from External API
- WordPress API Create post content
- Solution for processing lots of data with CRON/API, dealing with memory/timeout issues
- WordPress API causing fatal error
- woocommerce api echo out response
- Limit the number of external API calls per second
- WordPress Theme/Plugin Information API Response to Text and Button
- WordPress API – Getting just post content
- 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?
- How to use following API with WordPress?
- rest_cannot_create_user
- Implementing URL JSON API Data into Website
- How to use filters/params in wordpress as headless cms api
- How do I filter Child Posts by Parent Post ID for Custom Post types in WordPress REST API response?
- Rest WP_Error always return null
- Daily automatic update of stock quotes via REST API and Cronjob. Or is there a more sophisticated way?
- Using the JSON API via HTTPS and HTTP
- Posting data from Ionic app to WordPress
- WordPress REST API Endpoint (Authors and Categories latest posts)
- Stop Vimeo video with javascript – inside a loop and using a modal window
- Instructure Canvas API with WordPress [closed]
- Why does “if statement” has to “die()”, otherwise wont work?
- REST API And Error Codes – No Message
- Get full page HTML for a non-public WordPress page
- WordPress SMS API integration without plugin
- Send Order Confirmation automatically to customer’s mobile number
- XMLRPC: How to retrieve possible custom fields for a new post?
- Using WordPress API to mass update posts freezes the server