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

Adding user custom fields to the reponse #10

Closed
Pxlat opened this issue Feb 1, 2016 · 7 comments
Closed

Adding user custom fields to the reponse #10

Pxlat opened this issue Feb 1, 2016 · 7 comments

Comments

@Pxlat
Copy link

Pxlat commented Feb 1, 2016

Hi, Thanks for your great code,
#9 Does this solution work also to get fields from /users/ ?

@airesvsg
Copy link
Owner

airesvsg commented Feb 1, 2016

Hi @Pxlat,

Yes, this solution works too.

See below the example:

add_filter( 'acf/rest_api/user/get_fields', function( $data, $request, $response ) {
    if ( $response instanceof WP_REST_Response ) {
        $data = $response->get_data();
    }

    if( isset( $data['acf'] ) ) {
        $data['acf']['my_fields']->acf = get_fields( 1 );    // get fields from post #1     
    }   

    return $data;
}, 10, 3 );

Whats fields do you want to append in your response?

@Pxlat
Copy link
Author

Pxlat commented Feb 1, 2016

I want to append the field "logo" from this endpoint http://s15695.p20.sites.pressdns.com/wp-json/wp/v2/users/ into this endpoint http://s15695.p20.sites.pressdns.com/wp-json/wp/v2/wimo-order/ in "acf.retailer"

@airesvsg
Copy link
Owner

airesvsg commented Feb 1, 2016

Hi @Pxlat,

Please, replace the filter of isseu #9 by bellow code:

add_filter( 'acf/rest_api/wimo-order/get_fields', function( $data, $request, $response ) {
    if ( $response instanceof WP_REST_Response ) {
        $data = $response->get_data();
    }

    if( isset( $data['acf'] ) ) {
        $data['acf']['shipping_address']->acf = get_fields( $data['acf']['shipping_address']->ID );

        // only logo
        // $data['acf']['retailer']->logo    = get_field( 'logo', 'user_' . $data['acf']['retailer']->ID );

        // all acf fields
        $data['acf']['retailer']->acf         = get_fields( $data['acf']['retailer']->ID );
    }   

    return $data;
}, 10, 3 );

@Pxlat
Copy link
Author

Pxlat commented Feb 1, 2016

Didn't work..do you think this has anything to do with Auth? http://s15695.p20.sites.pressdns.com/wp-json/wp/v2/users/5

@airesvsg
Copy link
Owner

airesvsg commented Feb 1, 2016

In the plugin ( wp rest api ) has some conditions for you get data from users.

See: https://github.com/WP-API/WP-API/blob/develop/lib/endpoints/class-wp-rest-users-controller.php#L199

@airesvsg
Copy link
Owner

airesvsg commented Feb 2, 2016

Hi @Pxlat,
I'll close this issue, because the error isn't in the plugin.
If you want some help. Please, write an email for me: airesvsg@gmail.com
Thanks

@airesvsg airesvsg closed this as completed Feb 2, 2016
@airesvsg
Copy link
Owner

Hi @Pxlat,

please, check that the filter below will work:

add_filter( 'acf/rest_api/item_permissions/get', function( $permission, $request, $type ) {
    if ( 'user' == $type && method_exists( $request, 'get_param' ) && get_current_user_id() == $request->get_param( 'id' ) ) {
        return true;
    }
    return $permission;
}, 10, 3 );

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants