Engineering-Best-Practices
Engineering-Best-Practices copied to clipboard
Update AJAX Endpoints section to recommend REST API endpoints
Now that core has both the built-in REST API endpoints as well as the ability to create custom endpoints, we should update the best practices to recommend custom endpoints instead of custom rewrite rules and template_redirect
hooks.
https://10up.github.io/Engineering-Best-Practices/php/#ajax-endpoints
Definitely agree. Would love to see a PR.
Propose splitting that section into two parts: Ajax endpoints (containing references to rest API) and scenarios where it's a non ajax endpoint (e.g. something that returns templates / dom partials ) and contains the current recommendations with rewrite_rules + template_redirect.
With the rest_pre_serve_request
filter, it's easy to return non-JSON responses from an endpoint, so I'd still lean towards not using rewrite rules and template redirects and instead still take full advantage of the sanitization, validation, permissions, etc from the REST API.
@petenelson @ivankruchkoff Any updates on this?