acf-to-rest-api
acf-to-rest-api copied to clipboard
ACF fields for user on registration + updating user details
ACF to Rest v3.0.1-beta WP OAuth Server - Pro v3.3.8 WP v4.7.5 AngularJS v1
I have managed to authorise creating of the user and also for POST/PUT to the users ACF field but it isn't actually saving anything. I am using a taxonomy field that saves the Term ID. I POST a term ID to the /wp-json/acf/v3/users/{id} endpoint with data: { "fields": { "field": termID}}. It returns a success but either doesn't create the data for the registering user OR update data for an exisiting user when they edit their profile.
Please advise! Thanks you.
Hey Matt,
I found the solution creating first the user them in the callback of it updating the ACF fields. The point is: It's not possible do the two actions at the same time.
Did you solve this by another way?
To fix this with ACF5 i changed the code as follow:
In https://github.com/airesvsg/acf-to-rest-api/blob/99c7731e3cc1443a9dd7af98370db0ec228d7b28/v3/lib/class-acf-to-rest-api-acf-api.php#L64 add:
if(is_string($this->id)){
$this->id = preg_replace("/[^0-9,.]/", "", $this->id );
}
And replace https://github.com/airesvsg/acf-to-rest-api/blob/99c7731e3cc1443a9dd7af98370db0ec228d7b28/v3/lib/class-acf-to-rest-api-acf-api.php#L133 with:
if ( strpos( $id, 'user_' ) !== false ) {
$filter = array('user_id' => str_replace( 'user_', '', $id ) );
$user = get_userdata( $filter["user_id"] );
if( ! $user || ! $user->exists() || empty($user->roles) || !user_can($user->ID, $user->roles[0])){
$filter["user_id"] = "new";
}
} else {
$filter = array( 'post_id' => $id );
}
$field_groups = acf_get_field_groups( $filter );
@ghost You absolutely saved my ass on this one! Fantastic! This was able to work for me for the node-wpapi configuration!
apiPromise.then((site) => {
site.users().me().update({
fields:{
stocks: newMeta
}
}).then(function( response ) {
console.log( response );
}).catch((err) => {
console.log( err );
});
});
To fix this with ACF5 i changed the code as follow:
In
https://github.com/airesvsg/acf-to-rest-api/blob/99c7731e3cc1443a9dd7af98370db0ec228d7b28/v3/lib/class-acf-to-rest-api-acf-api.php#L64
add:
if(is_string($this->id)){ $this->id = preg_replace("/[^0-9,.]/", "", $this->id ); }
And replace
https://github.com/airesvsg/acf-to-rest-api/blob/99c7731e3cc1443a9dd7af98370db0ec228d7b28/v3/lib/class-acf-to-rest-api-acf-api.php#L133
with:
if ( strpos( $id, 'user_' ) !== false ) { $filter = array('user_id' => str_replace( 'user_', '', $id ) ); $user = get_userdata( $filter["user_id"] ); if( ! $user || ! $user->exists() || empty($user->roles) || !user_can($user->ID, $user->roles[0])){ $filter["user_id"] = "new"; } } else { $filter = array( 'post_id' => $id ); } $field_groups = acf_get_field_groups( $filter );
THANKS!
To fix this with ACF5 i changed the code as follow:
In
https://github.com/airesvsg/acf-to-rest-api/blob/99c7731e3cc1443a9dd7af98370db0ec228d7b28/v3/lib/class-acf-to-rest-api-acf-api.php#L64
add:
if(is_string($this->id)){ $this->id = preg_replace("/[^0-9,.]/", "", $this->id ); }
And replace
https://github.com/airesvsg/acf-to-rest-api/blob/99c7731e3cc1443a9dd7af98370db0ec228d7b28/v3/lib/class-acf-to-rest-api-acf-api.php#L133
with:
if ( strpos( $id, 'user_' ) !== false ) { $filter = array('user_id' => str_replace( 'user_', '', $id ) ); $user = get_userdata( $filter["user_id"] ); if( ! $user || ! $user->exists() || empty($user->roles) || !user_can($user->ID, $user->roles[0])){ $filter["user_id"] = "new"; } } else { $filter = array( 'post_id' => $id ); } $field_groups = acf_get_field_groups( $filter );
Bang after searching google for 3 hours
still doesn't work for me adding this changes
still doesn't work for me adding this changes
in class-acf-to-rest-api-controller.php
change: $this->acf->get_field_objects( $id );
to: get_field_objects( $id );
this resolve my problem
Thanks, everyone. I had to implement both acionegatilho and shwetdalal changes to get this to fire. :)