Extending Endpoint to Return User Role
-
Greetings,
I have used your code example at: https://wp-oauth.com/docs/how-to/extending-endpoints/
I have unset all the unwanted output and extra sensitive/unwanted output that generates.
By adding
array_walk($me_data[$wpdb->prefix.'capabilities'], function (&$value, $key) { $value="role"; });
AFTER
foreach ($infometa as $metarow) { $key = $metarow->meta_key; if( is_serialized( $metarow->meta_value ) ){ $me_data[$key] = unserialize( $metarow->meta_value ); }else{ $me_data[$key] = $metarow->meta_value; } }
I was able to get the output of focus to look like this
"wpos_capabilities":{"administrator":"role","bbp_keymaster":"role"}
The trick is, I am now trying to flip the key and value. I.E.
"wpos_capabilities":{"role":"administrator","role":"bbp_keymaster"}
I have tried
array_walk($me_data[$wpdb->prefix.'capabilities'], function(&$key) { $key = array_flip($key); });
However, that sets this output
"wpos_capabilities":{"administrator":"null","bbp_keymaster":"null"}
Any ideas of what I may be doing wrong here?
I am going to keep working on this and see if I can come up with a solution, but I would really appreciate some suggestions, and hopefully this can help others looking to do this.
Thanks!
- The topic ‘Extending Endpoint to Return User Role’ is closed to new replies.