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

REST API Write access - Fix invalid default value #7339

Merged
merged 3 commits into from
Aug 28, 2024

Conversation

JoryHogeveen
Copy link
Member

Description

De default value for the write_all option of a Pod was set to the Pod name. This results in incorrect parsing of a boolean in PodsRESTFields::field_allowed_to_extend() in write mode.

@sc0ttkclark See testing instructions. I'm not sure how you would like to implement something that will repair old Pods. You could check for ! empty() instead of using filter_var() but that might not be desirable.

Related GitHub issue(s)

Fixes #7327

Testing instructions

  1. Create a Pod without this patch and enable write mode.
  2. Go to PodsRESTFields::field_allowed_to_extend() and dump $all_fields_can_use_mode. It will return false, allways.
  3. Verify with $pod->get_arg( $pod_mode_arg, 'value_not_set' ) and see it returns the Pod name instead of a 1 or 0.
  4. Apply this patch
  5. Disable REST write access and save Pod (important, otherwise it won't reset the value)
  6. Re-enable REST Write access and save Pod.
  7. Redo 1, 2 and 3 and you'll see it returns the correct values now.

PR checklist

@JoryHogeveen JoryHogeveen added the Component: REST API Issues related to the Pods REST API endpoints or integration with existing WP REST API endpoints label Aug 22, 2024
@JoryHogeveen JoryHogeveen added this to the Next Release milestone Aug 22, 2024
@JoryHogeveen JoryHogeveen self-assigned this Aug 22, 2024
Copy link

what-the-diff bot commented Aug 22, 2024

PR Summary

  • Enhancements in REST API Options
    Several modifications took place in the set of options available for interacting with the REST API. This consists of alterations to the rest_base that allows customized endpoints, rest_namespace for custom namespace definitions, read_all and read_all_access for advanced viewing capabilities, write_all to allow updates over all fields, and rest_api_field_mode & rest_api_field_location for advanced field handling. The changes enhance the flexibility and control of API calls made to the service.

  • Bug Fix in PodsRESTFields.php
    The PR also includes a crucial bug fix for versions of Pods before 3.2.7. Previously, the default value for 'pod_mode' was incorrectly assigned to the pod name. This issue is now rectified with the update. This bug fix will improve reliability and prevent misbehavior in the application's function.

'help' => __( 'Allow all fields to be updated via the REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
'type' => 'boolean',
'default' => '',
'depends-on' => [ 'rest_enable' => true, 'read_all' => true ],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sc0ttkclark This is throughout the whole array, want me to fix or leave as is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The phpcs stuff is just optional to fix. Autoformat can help but it's file by file as we're able to.

@JoryHogeveen JoryHogeveen modified the milestones: Next Release, Pods 3.2.7 Aug 23, 2024
sc0ttkclark
sc0ttkclark previously approved these changes Aug 28, 2024
@sc0ttkclark sc0ttkclark changed the base branch from main to release/3.2.7 August 28, 2024 19:29
@sc0ttkclark sc0ttkclark dismissed their stale review August 28, 2024 19:29

The base branch was changed.

sc0ttkclark
sc0ttkclark previously approved these changes Aug 28, 2024
@sc0ttkclark
Copy link
Member

Added backcompat handling but did not include a DB migration.

@sc0ttkclark sc0ttkclark force-pushed the hotfix/7327-invalid-default-write-value branch from 3293a10 to 55fa1a1 Compare August 28, 2024 19:35
@sc0ttkclark sc0ttkclark merged commit 9a16ab9 into release/3.2.7 Aug 28, 2024
11 of 12 checks passed
@sc0ttkclark sc0ttkclark deleted the hotfix/7327-invalid-default-write-value branch August 28, 2024 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: REST API Issues related to the Pods REST API endpoints or integration with existing WP REST API endpoints Status: PR > Pending Code Review PR is pending code review by core developers Status: PR > QA pass QA passed Type: Bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Custom fields not updating via REST API
3 participants