Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert AJAX endpoints to REST API routes #36

Closed
MichelleBlanchette opened this issue Aug 22, 2020 · 2 comments · Fixed by #199
Closed

Convert AJAX endpoints to REST API routes #36

MichelleBlanchette opened this issue Aug 22, 2020 · 2 comments · Fixed by #199
Assignees
Labels
cleanup Improves code organization and usability enhancement Existing feature enhancements performance Changes related to performance optimization security Security vulnerability or tightening

Comments

@MichelleBlanchette
Copy link
Collaborator

There seems to be no way to retrieve an object's title by just having the ID, like you can in PHP with the generic get_post( $id ) call. With the REST API v2, you must already know the post_type of the object, which is obviously no good when you only have the object ID. So we gotta make our own endpoint!

And since I want to convert all AJAX endpoints to REST routes, anyways, you might as well go ahead and make our Rest_Routes class so we can easily migrate everything in a future release. 🚀 Be sure to segment Asana routes from generic, WordPress routes such as this.

I discovered this bug by saving a Page object ID to the automations Pin Post field which uses the /wp/v2/posts/{id} endpoint to load the title label for the initial value. Turns out this endpoint is for literally posts... And with custom post types, this just becomes a disaster—especially because custom post types do not automatically have routes set because some are private (only used internally/programmatically), so keep this in mind when displaying search results!!! It can easily get super messy! And then just add a filter if people want to allow private/hidden post types in search results. 👍

Screen Shot 2020-08-21 at 10 52 43 PM

@MichelleBlanchette MichelleBlanchette added the bug Something isn't working label Aug 22, 2020
@MichelleBlanchette MichelleBlanchette changed the title Need AJAX endpoint to give object title by ID Need REST endpoint to give object title by ID Aug 22, 2020
@MichelleBlanchette
Copy link
Collaborator Author

Just went with an AJAX endpoint for now to get release out faster in commit 0fe5c60

@MichelleBlanchette MichelleBlanchette added enhancement Existing feature enhancements and removed bug Something isn't working labels Nov 1, 2020
@MichelleBlanchette MichelleBlanchette changed the title Need REST endpoint to give object title by ID Convert AJAX calls to Rest_Routes Nov 1, 2020
@MichelleBlanchette
Copy link
Collaborator Author

The AJAX endpoint works great, so there's no need to change it. Let's definitely get all AJAX usage switched over to REST API endpoints, though. They are more efficient and accessible. 👍

@MichelleBlanchette MichelleBlanchette changed the title Convert AJAX calls to Rest_Routes Convert AJAX endpoints to REST API routes Nov 1, 2020
@MichelleBlanchette MichelleBlanchette self-assigned this Jan 18, 2021
@MichelleBlanchette MichelleBlanchette removed their assignment Jul 21, 2021
@MichelleBlanchette MichelleBlanchette self-assigned this Dec 26, 2021
@MichelleBlanchette MichelleBlanchette removed their assignment May 18, 2022
@MichelleBlanchette MichelleBlanchette self-assigned this Sep 27, 2023
@MichelleBlanchette MichelleBlanchette linked a pull request Oct 1, 2023 that will close this issue
@MichelleBlanchette MichelleBlanchette added cleanup Improves code organization and usability performance Changes related to performance optimization security Security vulnerability or tightening labels Oct 13, 2023
MichelleBlanchette added a commit that referenced this issue Nov 8, 2023
Issues/36 – Convert WP Admin AJAX actions to REST API endpoints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Improves code organization and usability enhancement Existing feature enhancements performance Changes related to performance optimization security Security vulnerability or tightening
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant