Created
January 20, 2015 02:22
-
-
Save justingreerbbi/8b0342b677c48dc5109d to your computer and use it in GitHub Desktop.
Replaces the default /oauth/me method for WordPress OAuth Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('wo_endpoints','wo_extend_resource_api', 2); | |
function wo_extend_resource_api ($methods) | |
{ | |
$methods['me'] = array('func'=>'_wo_me'); | |
return $methods; | |
} | |
/** | |
* Replaces the default me enpoint | |
* @param [type] $token [description] | |
* @return [type] [description] | |
*/ | |
function _wo_me ( $token=null ) | |
{ | |
$user_id = &$token['user_id']; | |
global $wpdb; | |
$me_data = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}users WHERE ID=$user_id", ARRAY_A); | |
/** prevent sensative data - makes me happy ;) */ | |
unset($me_data['user_pass']); | |
unset($me_data['user_activation_key']); | |
unset($me_data['user_url']); | |
// add user metadata | |
$infometa = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->prefix}usermeta WHERE user_id = ".$user_id.""); | |
foreach ($infometa as $metarow) { | |
// exclude sensitive data | |
if (1 === preg_match( "/pmpro_|token|wp_|theme_my_login_security|credit|card|password/i", + $metarow->meta_key)) { | |
continue; | |
} | |
$key = $metarow->meta_key; | |
$me_data[$key] = unserialize($metarow->meta_value); | |
} | |
$response = new OAuth2\Response($me_data); | |
$response->send(); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment