weixin_39799565
weixin_39799565
2020-11-22 13:19

Incorrect post id to pass into Filter pods_pods_field in REST API

Describe the bug When using the filter 'pods_pods_field' on normal pages, the four parameter $instance (object|Pods) (referred to here: http://hookr.io/filters/pods_pods_field/) will pass in the correct id, but with REST API, it seems to pass in the last available id only.

To Reproduce Steps to reproduce the behavior: 1. Install the pods with the package code below. 2. Add the following code to functions.php. This function will return the ids from the second and the fourth parameters instead of the value so we can see the error add_filter( 'pods_pods_field', 'pods_field_fn', 10, 4 );
function pods_field_fn( $value_ukn, $row_arr, $params_arr, $pods_obj ){ //print_r($params_arr->name); if( $params_arr->name == 'post_id' ){ return $pods_obj->id; } if( $params_arr->name == 'row_id' ){ return $row_arr['ID']; }

return $value_ukn;

} 3. Add at least two radmon Sections. 4. Add wp-json/wp/v2/section/ to the url after the domain name 5. post_id should be the same as the id, but it is not.

Expected behavior In REST API, pods_pods_field should receive the correct current Pods object.

Screenshots http://www.codingpanda.co.uk/pprf/wp-json/wp/v2/section/ codingpanda co uk pprf wp json wp v2 section (3)

Pods Version

Please provide the version of Pods you are running: 2.7.12

WordPress Environment

WordPress Version: 5.2.1 PHP Version: 7.0.33 MySQL Version: 5.5.5 Server Software: Apache/2.4.39 (Unix) Your User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0 Session Save Path: /home/sites/codingpanda.co.uk/tmp/ Session Save Path Exists: Yes Session Save Path Writeable: Yes Session Max Lifetime: 1440 Opcode Cache: Apc: No Memcached: No OPcache: Yes Redis: No Object Cache: APC: No APCu: No Memcache: No Memcached: No Redis: No WPDB Prefix: ppde_ WP Multisite Mode: No WP Memory Limit: 40M Current Memory Usage: 34.826M Current Memory Usage (real): 38.000M Pods Network-Wide Activated: No Pods Install Location: /home/sites/codingpanda.co.uk/public_html/pprf/wp-content/plugins/pods/ Pods Tableless Mode Activated: No Pods Light Mode Activated: No Currently Active Theme: Twenty Seventeen Currently Active Plugins: Panda Pods Repeater Field: 1.4.1 Pods - Custom Content Types and Fields: 2.7.12

Pods Package Export (helpful!)

{"meta":{"version":"2.7.12","build":1558724616},"pods":{"120":{"id":120,"name":"section","label":"Sections","description":"","type":"post_type","storage":"table","object":"","alias":"","fields":{"post_id":{"id":132,"name":"post_id","label":"Post ID","description":"","help":"","class":"","type":"number","weight":0,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","number_format_type":"number","number_format":"i18n","number_decimals":"0","number_format_soft":"0","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","oembed_enabled_providers_funnyordiecom":"0","oembed_enabled_providers_photobucketcom":"0","oembed_enabled_providers_polldaddycom":"0","pick_post_status":["publish"],"pandarepeaterfield_table":"member","pandarepeaterfield_field_width":"100","pandarepeaterfield_entry_limit":"0","pandarepeaterfield_enable_load_more":"0","pandarepeaterfield_initial_amount":"10","pandarepeaterfield_enable_trash":"0","pandarepeaterfield_order_by":"pandarf_order","pandarepeaterfield_order":"ASC","pandarepeaterfield_display_order_info":"0","pandarepeaterfield_apply_admin_columns":"0","pandarepeaterfield_allow_reassign":"0","pandarepeaterfield_public_access":"0","subscriber":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"1","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","number_repeatable":"0","number_placeholder":""},"row_id":{"id":133,"name":"row_id","label":"Row ID","description":"","help":"","class":"","type":"number","weight":1,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","number_format_type":"number","number_format":"i18n","number_decimals":"0","number_format_soft":"0","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","oembed_enabled_providers_funnyordiecom":"0","oembed_enabled_providers_photobucketcom":"0","oembed_enabled_providers_polldaddycom":"0","pick_post_status":["publish"],"pandarepeaterfield_table":"member","pandarepeaterfield_field_width":"100","pandarepeaterfield_entry_limit":"0","pandarepeaterfield_enable_load_more":"0","pandarepeaterfield_initial_amount":"10","pandarepeaterfield_enable_trash":"0","pandarepeaterfield_order_by":"pandarf_order","pandarepeaterfield_order":"ASC","pandarepeaterfield_display_order_info":"0","pandarepeaterfield_apply_admin_columns":"0","pandarepeaterfield_allow_reassign":"0","pandarepeaterfield_public_access":"0","subscriber":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"1","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","number_repeatable":"0","number_placeholder":""},"sectionid":{"id":121,"name":"sectionid","label":"SectionID","description":"","help":"","class":"","type":"text","weight":2,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","oembed_enabled_providers_funnyordiecom":"0","oembed_enabled_providers_photobucketcom":"0","oembed_enabled_providers_polldaddycom":"0","pick_post_status":["publish"],"pandarepeaterfield_table":"member","pandarepeaterfield_field_width":"100","pandarepeaterfield_entry_limit":"0","pandarepeaterfield_enable_load_more":"0","pandarepeaterfield_initial_amount":"10","pandarepeaterfield_enable_trash":"0","pandarepeaterfield_order_by":"pandarf_order","pandarepeaterfield_order":"ASC","pandarepeaterfield_display_order_info":"0","pandarepeaterfield_apply_admin_columns":"0","pandarepeaterfield_allow_reassign":"0","pandarepeaterfield_public_access":"0","subscriber":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","text_repeatable":"0","text_placeholder":""},"description":{"id":122,"name":"description","label":"description","description":"","help":"","class":"","type":"text","weight":3,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","oembed_enabled_providers_funnyordiecom":"0","oembed_enabled_providers_photobucketcom":"0","oembed_enabled_providers_polldaddycom":"0","pick_post_status":["publish"],"pandarepeaterfield_table":"member","pandarepeaterfield_field_width":"100","pandarepeaterfield_entry_limit":"0","pandarepeaterfield_enable_load_more":"0","pandarepeaterfield_initial_amount":"10","pandarepeaterfield_enable_trash":"0","pandarepeaterfield_order_by":"pandarf_order","pandarepeaterfield_order":"ASC","pandarepeaterfield_display_order_info":"0","pandarepeaterfield_apply_admin_columns":"0","pandarepeaterfield_allow_reassign":"0","pandarepeaterfield_public_access":"0","subscriber":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","text_repeatable":"0","text_placeholder":""}},"show_in_menu":"1","label_singular":"Section","public":"1","show_ui":"1","supports_title":"1","supports_editor":"1","publicly_queryable":"1","exclude_from_search":"0","capability_type":"post","capability_type_custom":"section","capability_type_extra":"1","has_archive":"0","hierarchical":"0","rewrite":"1","rewrite_with_front":"1","rewrite_feeds":"0","rewrite_pages":"1","query_var":"1","can_export":"1","default_status":"draft","supports_author":"0","supports_thumbnail":"0","supports_excerpt":"0","supports_trackbacks":"0","supports_custom_fields":"0","supports_comments":"0","supports_revisions":"0","supports_page_attributes":"0","supports_post_formats":"0","built_in_taxonomies_category":"0","built_in_taxonomies_link_category":"0","built_in_taxonomies_post_tag":"0","show_in_nav_menus":"1","show_in_admin_bar":"1","pfat_enable":"0","pfat_run_outside_loop":"0","pfat_append_single":"append","pfat_filter_single":"the_content","pfat_append_archive":"append","pfat_filter_archive":"the_content","rest_enable":"1","rest_base":"section","read_all":"0","write_all":"0"}}}

Additional context Add any other context about the problem here.

Possible Workaround If you have discovered a workaround, please include it below.

该提问来源于开源项目:pods-framework/pods

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • weixin_39655160 weixin_39655160 5月前

    Issue-Label Bot is automatically applying the label Type: Bug to this issue, with a confidence of 0.99. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

    Links: app homepage, dashboard and code for this bot.

    点赞 评论 复制链接分享
  • weixin_39928099 weixin_39928099 5月前

    -panda Using the method id() instead of the parameter fixes your issue.

    However , it looks like the fetch(), reset() methods etc. don't set the $id parameter in the Pods object at all. Might be a good idea to add the following to these methods before returning a value:

    $this->id = $this->id()

    Let me know and I'll create a PR.

    点赞 评论 复制链接分享
  • weixin_39537298 weixin_39537298 5月前

    $this->id only gets set when pods() is intentionally called from a singular context via pods( 'pod_name', $id_or_slug ) or when calling $pod->fetch( $id_or_slug ). It does not store the current ID when in a fetch() loop etc. No PR necessary here, but in the future we may expand the Pods object to support context in a separate class property instead of relying solely on $this->id internally to track singular versus list.

    点赞 评论 复制链接分享
  • weixin_39928099 weixin_39928099 5月前

    $this->id only gets set when pods() is intentionally called from a singular context via pods( 'pod_name', $id_or_slug ) or when calling $pod->fetch( $id_or_slug )

    Not entirely correct. $pod->fetch( $id ) does not set the id parameter. The REST handler uses fetch().

    点赞 评论 复制链接分享
  • weixin_39537298 weixin_39537298 5月前

    Yeah sorry, I should have left the fetch() part out there, it gets setup by PodsData::__construct() which is only setup when you do the initial pods( 'pod_name', $id_or_slug ).

    点赞 评论 复制链接分享
  • weixin_39928099 weixin_39928099 5月前

    Okidoki, closing this issue then!

    点赞 评论 复制链接分享

相关推荐