I think you should stop using rewrite endpoints to handle JSON responses. Instead you can and you should use the REST API.
So, instead of this:
function makeplugins_add_json_endpoint() {
add_rewrite_endpoint( 'json', EP_PERMALINK | EP_PAGES );
}
add_action( 'init', 'makeplugins_add_json_endpoint' );
And then handle the JSON response at your own, you can and you should do something like this:
add_action( 'rest_api_init', 'cyb_register_api_endpoints' );
function cyb_register_api_endpoints() {
$namespace="myplugin/v1";
register_rest_route( $namespace, '/myendpoint/', array(
'methods' => 'GET',
'callback' => 'cyb_myendpoint_callback',
) );
}
function cyb_myendpoint_callback() {
//$response can be a Object, JSON, array
$response = [];
return new WP_REST_Response( $response );
}
In conclusion: a JSON endpoint should be handle now through REST API.
Related Posts:
- WordPress Rest API custom endpoint optional param
- Using the Rewrite API to Construct a RESTful URL
- How to stop WP API endpoint from caching?
- Custom Endpoint Gives 404 Header
- Sync posts from one WordPress site to another
- “rest_no_route” – Debug error
- Associate the “add_rewrite_endpoint” and “$_GET”
- Add Rewrite Endpoint to CPT Archive
- 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
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- WordPress – replicate same globals, query vars and query for an alternate endpoint
- How to use endpoint, but remove/rewrite endpoint base?
- REST API Plugin Update call back not updating the plugin
- How do you create a “virtual” page in WordPress
- When should add_rewrite_tag() be used?
- Query WP REST API v2 by multiple meta keys
- Why does everybody hook add_rewrite_rule on init
- Custom Taxonomy Endpoint Pagination using paginate_links()
- Dynamic Endpoints
- How do I cache (core) API requests?
- WP REST API only returning partial list of users
- Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API
- WP REST API no longer supports filter param, so how do I get posts in a custom taxonomy?
- Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
- add_rewrite_rule() vs $wp_rewrite->rules vs ‘rewrite_rules_array’?
- Slow REST API calls on self-hosted WordPress [closed]
- Why is my custom API endpoint not working?
- Is it safe to fix Access-Control-Allow-Origin (CORS origin) errors with a php header directive?
- How to check if a rewrite rule exists
- WooCommerce: Can’t use wc_get_products for custom REST API endpoints
- Retrieving pages with multiple tags using REST API
- Querystring parameter getting lost in rewrite rule
- REST API endpoint for elasticpress autosuggest
- How can I get users email (and additional data) from the rest API?
- how to authenticate for the REST API from a plugin and from command line
- Make Two Views of Post Type Archive At Two URLs
- Custom post types and custom variables — add_rewrite_tag() question
- Why is per_page not working with categories in WP API?
- How to Rewrite WordPress URL for a Plugin
- add_rewrite_rule not producing anything in $_GET
- WordPress API – Get Drafts
- REST API: How can I restrict a custom post type to only be accessible by authenticated users?
- Flush_rewrite_rules not working when settings updated
- How do I use the WP REST API plugin and the OAuth Server plugin to allow for registration and login?
- WordPress Custom URL Rewrites
- Creating a post with the REST API, curl and oauth returning 401 error
- Case-insensitive add_rewrite_rules in WordPress functions
- WordPress 4.7 REST API endpoints
- Add rewrite endpoint to author page + pagination
- Does the REST API (official) support custom post types?
- How to: Rest endpoint returning empty object
- How to get the attached gallery in the rest API?
- WP API : date_query parameter
- Rewrite /?rest_route=/ link to /wp-json/ without changing default permalink structure in apache
- Does add_rewrite_rule(..) only accept “index.php” as redirect target?
- Cyrillic characters in rewrite rules cause 404 Not Found errors
- Clean URLs for custom $_GET variables
- register_rest_field for custom taxonomy fields that are assosiated with custom post type
- Custom route for WP-API gives “rest_no_route” value
- How to force Authentication on REST API for Password protected page using custom table and fetch() without Plugin
- Prettified page URL w/ query var redirects to prettified page URL w/o query var
- AJAX request from Chrome Extension to WordPress Website
- Custom endpoint that returns an xml
- Get post from custom REST endpoint in Gutenberg
- Headless WordPress: How to authenticate front end requests?
- Dynamic URL, not a physical page within the database
- Get more than 10 posts in a specific category with the wordpress api
- Making extra parameters optional
- flush_rewrite_rules() cancels the effect of add_rewrite_rule()
- Developing Themes with React/Angular
- why is are these rewrite_tags and rules not working?
- Multisite functions to communicate with individual site functions
- Separate posts by chapter per rewrite
- How to send multipart form data to WordPress endpoint
- curl POST work with user meta but not the custom user meta
- Redirect taxonomy to custom template to list terms in taxonomy
- How to change the matches in add_rewrite_rule
- Using add_rewrite_rule() to redirect to Front Page
- Cannot edit post meta fields with rest API
- resolve /author/ to a page or archive (of all authors) template
- WordPress Rest API – Get all posts based on post_meta on custom endpoint
- Multiple values in a rewrite rule, is it possible?
- Implementing the wp json-rest api
- How make a multi language routes, with rewrite rules or rewrite endpoints?
- What add_rewrite_tag()’s RegEx matches against?
- get_userdata by username
- Add rewrite rule for rewrite endpoint
- add_rewrite_rule() not working
- add_feed and flush_rewrite_rules
- How to have multiple rewrite endpoints in the same URL?
- REST-API: extend media-endpoint
- Rewrite rules and query for virtual page
- Can I define multiple callback methods depending on the call method?
- Create post with REST API in php with file_get_contents
- add_rewrite_rule parameter is not received by the page
- How get Themes list via REST api?
- add_rewrite_rules prefix everything
- Request object for validate_callback
- x-wp-nonce is not allowed by Access-Control-Allow-Headers in preflight response
- WordPress REST API “rest_authentication_errors” doesn’t work external queries?