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

Pod extension of 'media' type returns empty fields in JSON API #4893

Open
2 tasks
demitri opened this issue May 4, 2018 · 3 comments
Open
2 tasks

Pod extension of 'media' type returns empty fields in JSON API #4893

demitri opened this issue May 4, 2018 · 3 comments
Labels
Component: REST API Issues related to the Pods REST API endpoints or integration with existing WP REST API endpoints Status: Need Reproduction Issue must be reproduced before coding can begin Type: Bug

Comments

@demitri
Copy link

demitri commented May 4, 2018

Issue Overview

Created a new Pod that is an extension of the 'media' type. Custom fields are returned in the API, but all values are false.

Expected Behavior

JSON fields populated with values defined in the WordPress interface.

Current Behavior

New fields are being returned in the JSON response, but all values are false.

Possible Solution

I don't know anything about the internals.

Steps to Reproduce (for bugs)

  1. Create a new pod that extends Media.
  2. Add a new custom text field. I was using types "string" and "web address".
  3. Enable the JSON API in the interface.
  4. Make an API request to return the media object.
  5. Fields are present, but empty.

Pods Package Export (helpful!)

{"meta":{"version":"2.7.1","build":1525445607},"pods":{"73":{"id":73,"name":"media","label":"Media","description":"","type":"media","storage":"meta","object":"media","alias":"","fields":{"author_name":{"id":74,"name":"author_name","label":"Author Name","description":"Name of the author","help":"","class":"","type":"text","weight":0,"pick_object":"","pick_val":"","sister_id":"","required":"1","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_post_status":["publish"],"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","unique":"0","text_repeatable":"0","text_placeholder":""},"license_name":{"id":75,"name":"license_name","label":"License Name","description":"Name of the use license","help":"","class":"","type":"text","weight":1,"pick_object":"","pick_val":"","sister_id":"","required":"1","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_post_status":["publish"],"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","unique":"0","text_repeatable":"0","text_placeholder":""},"license_url":{"id":76,"name":"license_url","label":"License URL","description":"URL to the use license","help":"","class":"","type":"website","weight":2,"pick_object":"","pick_val":"","sister_id":"","required":"0","website_format":"normal","website_allow_port":"0","website_clickable":"0","website_new_window":"0","website_max_length":"255","website_html5":"0","pick_post_status":["publish"],"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","unique":"0","website_repeatable":"0","website_placeholder":""},"media_source_url":{"id":77,"name":"media_source_url","label":"Source URL","description":"URL where the image was originally taken from.","help":"","class":"","type":"website","weight":3,"pick_object":"","pick_val":"","sister_id":"","required":"0","website_format":"normal","website_allow_port":"0","website_clickable":"0","website_new_window":"0","website_max_length":"255","website_html5":"0","pick_post_status":["publish"],"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","unique":"0","website_repeatable":"0","website_placeholder":""}},"show_in_menu":1,"rest_enable":"1","read_all":"1","write_all":"0"},"52":{"id":52,"name":"resource-link","label":"Resource Links","description":"","type":"post_type","storage":"meta","object":"","alias":"","fields":{"resource_url":{"id":53,"name":"resource_url","label":"Resource URL","description":"A link to a resource.","help":"","class":"","type":"website","weight":0,"pick_object":"","pick_val":"","sister_id":"","required":"1","website_format":"normal","website_allow_port":"1","website_clickable":"1","website_new_window":"1","website_max_length":"255","website_html5":"0","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"1","rest_write":"1","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","website_repeatable":"0","website_placeholder":""},"resource_blurb":{"id":54,"name":"resource_blurb","label":"Resource Blurb","description":"A short description of the resource.","help":"","class":"","type":"text","weight":1,"pick_object":"","pick_val":"","sister_id":"","required":"1","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"1","rest_write":"1","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","text_repeatable":"0","text_placeholder":""},"resource_name":{"id":55,"name":"resource_name","label":"Resource Name","description":"A title or heading for the resource.","help":"","class":"","type":"text","weight":2,"pick_object":"","pick_val":"","sister_id":"","required":"1","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"1","rest_write":"1","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","text_repeatable":"0","text_placeholder":""},"category":{"id":59,"name":"category","label":"Category","description":"Resource category","help":"","class":"","type":"pick","weight":3,"pick_object":"taxonomy","pick_val":"category","sister_id":"","required":"0","pick_format_type":"multi","pick_format_single":"dropdown","pick_format_multi":"checkbox","pick_allow_add_new":"1","pick_taggable":"0","pick_show_icon":"1","pick_show_edit_link":"1","pick_show_view_link":"1","pick_limit":"0","pick_user_role":[],"pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"1","rest_write":"1","rest_pick_response":"id","rest_pick_depth":"2","unique":"0","pick_select_text":"","pick_table_id":"","pick_table_index":"","pick_display":"","pick_where":"","pick_orderby":"","pick_groupby":""},"resource_author":{"id":60,"name":"resource_author","label":"Resource Author","description":"The resource author.","help":"","class":"","type":"pick","weight":4,"pick_object":"user","pick_val":"","sister_id":"","required":"0","pick_format_type":"single","pick_format_single":"dropdown","pick_format_multi":"checkbox","pick_allow_add_new":"0","pick_taggable":"0","pick_show_icon":"1","pick_show_edit_link":"1","pick_show_view_link":"1","pick_limit":"0","pick_user_role":[],"pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"1","rest_write":"1","rest_pick_response":"id","rest_pick_depth":"2","unique":"0","pick_select_text":"","pick_table_id":"","pick_table_index":"","pick_display":"","pick_where":"","pick_orderby":"","pick_groupby":""},"resource_image":{"id":61,"name":"resource_image","label":"Resource Image","description":"An icon or image for the resource.","help":"","class":"","type":"pick","weight":5,"pick_object":"media","pick_val":"","sister_id":"","required":"0","pick_format_type":"single","pick_format_single":"list","pick_format_multi":"checkbox","pick_allow_add_new":"1","pick_taggable":"0","pick_show_icon":"1","pick_show_edit_link":"1","pick_show_view_link":"1","pick_limit":"0","pick_user_role":[],"pick_post_status":["publish"],"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":"id","rest_pick_depth":"2","unique":"0","pick_select_text":"","pick_table_id":"","pick_table_index":"","pick_display":"","pick_where":"","pick_orderby":"","pick_groupby":""}},"show_in_menu":"1","label_singular":"Resource Link","public":"1","show_ui":"1","supports_title":"1","supports_editor":"1","publicly_queryable":"1","exclude_from_search":"0","capability_type":"post","capability_type_custom":"resource-link","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","read_all":"1","write_all":"1"}}}

Related Issues and/or PRs

Todos

  • Tests
  • Documentation

WordPress Environment

``` WordPress Version: 4.9.5

PHP Version: 7.0.10

MySQL Version: 5.5.56

Server Software: Apache/2.4.27 (Red Hat) PHP/7.0.10

Your User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15

Session Save Path: /var/opt/rh/rh-php70/lib/php/session

Session Save Path Exists: Yes

Session Save Path Writeable: Yes

Session Max Lifetime: 1440

Opcode Cache:

Apc: No
Memcached: No
OPcache: No
Redis: No
Object Cache:

APC: No
APCu: No
Memcache: No
Memcached: No
Redis: No
WPDB Prefix: wp_

WP Multisite Mode: No

WP Memory Limit: 40M

Pods Network-Wide Activated: No

Pods Install Location: /opt/rh/httpd24/root/var/www/html/wordpress/wp-content/plugins/pods/

Pods Tableless Mode Activated: No

Pods Light Mode Activated: No

Currently Active Theme: Twenty Seventeen

Currently Active Plugins:

Akismet Anti-Spam: 4.0.3
FG Drupal to WordPress: 1.58.0
Pods - Custom Content Types and Fields: 2.7.1

</details>
@jimtrue jimtrue added Type: Bug Status: Need Reproduction Issue must be reproduced before coding can begin labels May 4, 2018
@quasel quasel added the Component: REST API Issues related to the Pods REST API endpoints or integration with existing WP REST API endpoints label Aug 31, 2018
@a-nom-ali
Copy link

I'm getting the same issue. Going to try and figure out how to fix it...

@a-nom-ali
Copy link

a-nom-ali commented May 15, 2019

Just in case anyone else hits this issue. I know it's not pretty, but here's how I solved it in my plugin in the meantime:

function get_media_fields($row)
{
    if ($row["type"] == "attachment")
    {
        $pod = pods("media", $row["id"]);
        foreach ($pod->fields() as $field)
        {
            $name = $field['name'];
            $meta = $pod->display($name, true);
            $row[$name] = $meta;
        }

    }
    return $row;

}

function rest_request_after_callbacks( $response, $handler, $request )
{
    if (strpos($request->get_route(), "/wp/v2/media") === FALSE)
        return $response;

    if (array_key_exists("X-WP-Total", $response->headers))
    {
        for ($i=0; $i < count($response->data); $i++)
        {
            $response->data[$i] = self::get_media_fields( $response->data[$i] );
        }
    }
    else
        $response->data = self::get_media_fields( $response->data );
    
    return $response;
}
add_filter( 'rest_request_after_callbacks', 'rest_request_after_callbacks', 20, 3);

@AbbasTallaq
Copy link

Hi,
the issue still on.
I facing this ,
by using @Nielo method, am getting the vaules in api, however like if am posting the images with data, it's not saving ... i have to do in wp otherwise its not displaying.
its been almost one year.

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: Need Reproduction Issue must be reproduced before coding can begin Type: Bug
Projects
None yet
Development

No branches or pull requests

5 participants