Skip to content

Commit

Permalink
Fix backcompat handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0ttkclark committed Aug 28, 2024
1 parent 9f71c66 commit 55fa1a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
28 changes: 14 additions & 14 deletions classes/PodsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4375,37 +4375,37 @@ public function add_rest_settings_tab_fields( $options, $pod ) {
}

$options['rest-api'] = [
'rest_enable' => [
'rest_enable' => [
'label' => __( 'Enable', 'pods' ),
'help' => __( 'Add REST API support for this Pod.', 'pods' ),
'type' => 'boolean',
'default' => '',
'dependency' => true,
],
'rest_base' => [
'rest_base' => [
'label' => __( 'REST Base (if any)', 'pods' ),
'help' => __( 'This will form the url for the route. Default / empty value here will use the pod name.', 'pods' ),
'type' => 'text',
'default' => '',
'depends-on' => [ 'rest_enable' => true ],
],
'rest_namespace' => [
'rest_namespace' => [
'label' => __( 'REST API namespace', 'pods' ),
'help' => __( 'This will change the namespace URL of the REST API route to a different one from the default one that all normal route endpoints use.', 'pods' ),
'type' => 'text',
'default' => '',
'placeholder' => 'wp/v2',
'depends-on' => [ 'rest_enable' => true ],
],
'read_all' => [
'read_all' => [
'label' => __( 'Show All Fields (read-only)', 'pods' ),
'help' => __( 'Show all fields in REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
'type' => 'boolean',
'default' => '',
'depends-on' => [ 'rest_enable' => true ],
'dependency' => true,
],
'read_all_access' => [
'read_all_access' => [
'label' => __( 'Read All Access', 'pods' ),
'help' => __( 'By default the REST API will allow the fields to be returned for everyone who has access to that endpoint/object. You can also restrict the access of your field based on whether the person is logged in.', 'pods' ),
'type' => 'boolean',
Expand All @@ -4414,7 +4414,7 @@ public function add_rest_settings_tab_fields( $options, $pod ) {
'read_all' => true,
],
],
'write_all' => [
'write_all' => [
'label' => __( 'Allow All Fields To Be Updated', 'pods' ),
'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',
Expand All @@ -4430,20 +4430,20 @@ public function add_rest_settings_tab_fields( $options, $pod ) {
'write_all' => true,
],
],*/
'rest_api_field_mode' => [
'label' => __( 'Field Mode', 'pods' ),
'help' => __( 'Specify how you would like your values returned in the REST API responses. If you choose to show Both raw and rendered values then an object will be returned for each field that contains the value and rendered properties.', 'pods' ),
'type' => 'pick',
'rest_api_field_mode' => [
'label' => __( 'Field Mode', 'pods' ),
'help' => __( 'Specify how you would like your values returned in the REST API responses. If you choose to show Both raw and rendered values then an object will be returned for each field that contains the value and rendered properties.', 'pods' ),
'type' => 'pick',
'pick_format_single' => 'radio',
'default' => 'value',
'depends-on' => [ 'rest_enable' => true ],
'data' => [
'default' => 'value',
'depends-on' => [ 'rest_enable' => true ],
'data' => [
'value' => __( 'Raw values', 'pods' ),
'render' => __( 'Rendered values', 'pods' ),
'value_and_render' => __( 'Both raw and rendered values {value: raw_value, rendered: rendered_value}', 'pods' ),
],
],
'rest_api_field_location' => [
'rest_api_field_location' => [
'label' => __( 'Field Location', 'pods' ),
'help' => __( 'Specify where you would like your values returned in the REST API responses. To show in the "meta" object of the response, you must have Custom Fields enabled in the Post Type Supports features.', 'pods' ),
'type' => 'pick',
Expand Down
9 changes: 8 additions & 1 deletion classes/PodsRESTFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,14 @@ public static function field_allowed_to_extend( $field, $pod, $mode ) {

$pod_mode_arg = $mode . '_all';

$all_fields_can_use_mode = filter_var( $pod->get_arg( $pod_mode_arg, false ), FILTER_VALIDATE_BOOLEAN );
$pod_mode = $pod->get_arg( $pod_mode_arg, false );

// Backcompat for a previous bug in Pods < 3.2.7 where the default value was the pod name instead of '0'.
if ( $pod_mode === $pod->get_name() ) {
$pod_mode = 0;
}

$all_fields_can_use_mode = filter_var( $pod_mode, FILTER_VALIDATE_BOOLEAN );
$all_fields_access = 'read' === $mode && filter_var( $pod->get_arg( 'read_all_access', false ), FILTER_VALIDATE_BOOLEAN );

// Check if user must be logged in to access all fields and override whether they can use it.
Expand Down

0 comments on commit 55fa1a1

Please sign in to comment.