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
Add REST API endpoint to read/update general settings #2695
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Shelob9 I didn't find PHP unit tests for the new routes so I started testing manually.
|
This test throws an error right now, the permissions_callback parameter seems to create this issue. I had started to write a whole class tha set up a mocked $wp_rest_server when I realized we had it already created at tests/includes/cf-rest-test-case.php and could extend CF_Rest_Test_Case
…aldera_Forms::get_manage_cap() capability - I first tried to use Caldera_Forms_API_CRUD::get_items_permissions_check but it uses the _doing_it_wrong() function and I'm not sure it's what we want here - the permissions_check function check if the user is set. If not, we look for the user using the determine_current_user filter hook to go forward when user is set and find the user ID ( if logged in ) and the set the user again. - we might want to move the permissions_check function to classes/api/crud.php in the case @Shelob9 agrees with it
This test the responses of api requests @Shelob9 I couldn't test post requests using args, right now that broke the tests
Fixed testing with postman, @Shelob9 for context : I'll go back to render/index.js refactor before I look for a solution to test POST requests with args
Use get_items_permissions_check and create_item_permissions_check with custom create or view filters for settings
Shelob9
commented
Dec 13, 2018
classes/api/settings.php
Outdated
public function get_items_permissions_check( WP_REST_Request $request ){ | ||
|
||
//Check if a user is already set | ||
if( wp_get_current_user()->ID === 0 ) { |
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.
@New0 Please remove this, like we discussed.
Shelob9
commented
Dec 13, 2018
classes/api/settings.php
Outdated
* | ||
* @return bool | ||
*/ | ||
public function permissions_check(){ | ||
public function create_item_permissions_check( WP_REST_Request $request ){ | ||
|
||
//Check if a user is already set | ||
if( wp_get_current_user()->ID === 0 ) { |
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.
New0
approved these changes
Dec 17, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#2694
Endpoints added via this PR:
POST /wp-json/cf-api/v2/settings
- Update general settings.GET /wp-json/cf-api/v2/settings
- Read general settings.