-
Notifications
You must be signed in to change notification settings - Fork 50
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 admin ajax endpoints to WP-API endpoints #42
Conversation
Refs #40: Convert admin AJAX endpoints and zone feed to WP-API endpoints Also created Zoninator_Rest_Api_Controller and refactored zoninator into separate classes. Added unit tests for Zoninator_Rest_Api_Controller.
You might want to take a look at the pattern we've established for core endpoints. If you follow it, you'll be able to benefit from the abstractions we're creating. |
Thanks @danielbachhuber will refactor the Controller class to follow the established pattern. It is sensible to use it's abstractions, especially for ( |
…nd constantize `zoninator`
endpoint section.
Instead, deactivate and gracefully inform the users to either * upgrade their WordPress * downgrade Zoninator to v0.6
break; | ||
} | ||
|
||
if( ! call_user_func( array( $this, $verify_function ), $zone_id ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just call the method directly within the switch
rather than using call_user_func
? Feels like that would make it easier to read/follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see it's just a copy-paste of the original function. I think this gives us an an opportunity to improve the code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
call _permissions->check directly And remove unneeded method `verify_access`
* Use deactivate_plugins * bail_on_activation does not need the $deactivate param
data = {}; | ||
} | ||
|
||
zoninator.$zonePostSearch.trigger( 'zoninator.ajax', [ endpoint, method, data ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a back-compat issue as well as the original trigger allowed sites to customize the params sent via the AJAX endpoint (e.g. custom search params). Any thoughts on how we could handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done ad768c7
…js autocomplete search
And thus remove duplicate (PHP and JS) view template for admin zone post.
Refs #40: Convert admin AJAX endpoints and zone feed to WP-API endpoints
Created
Zoninator_Rest_Api_Controller
class to represent the new rest API. Amended js code to use the new endpoints.Endpoints
The following endpoints where created
POST /zoninator/v1/zones/:zone_id/posts
(add post to zone)GET /zoninator/v1/zones/:zone_id/posts
(get zone feed)GET /zoninator/v1/posts/search?term=:term
(search term)DELETE /zoninator/v1/zones/:zone_id/posts/:post_id
(remove post from zone)PUT /zoninator/v1/zones/:zone_id/posts/order
(reorder posts)PUT /zoninator/v1/zones/:zone_id/lock
(lock zone)GET /zoninator/v1/zones/:zone_id/posts/recent
(recent posts for select box)NOTE: Supplemented the zone feed endpoint with a RESTful endpoint. Did keep the
old zone feed rewrite rule though, as it might be used by third parties.
Other
Refactored
Zoninator
class in the following waysZoninator_Rest_Api_Controller
andZoninator
into separate classZoninator_Rest_Api_Controller