Last active
November 13, 2018 08:14
-
-
Save jkhaui/6fcd4bf3c26cb640830440bd6e73075c to your computer and use it in GitHub Desktop.
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_action( 'graphql_init', function() { | |
add_filter( 'graphql_user_fields', function( $fields ) { | |
$fields['userBadges'] = [ | |
'type' => \WPGraphQL\Types::String(), | |
'description' => __( 'The badges of the user', 'gqlbadges' ), | |
'resolve' => function( \WP_User $user ) { | |
// $user = new WP_User($user->ID); | |
// Or... | |
$userproMeta = get_user_meta( $current_user->ID ); | |
$badgeURL = $userproMeta['_userpro_badges'][0]; | |
return ! empty( $userproMeta ) ? $userproMeta : null; | |
}, | |
]; | |
// UPDATE BELOW | |
$fields['userBadges'] = [ | |
'type' => \WPGraphQL\Types::String(), | |
'description' => __( 'The badges of the user', 'gqlbadges' ), | |
'resolve' => function( \WP_User $user ) { | |
// $user = new WP_User($user->ID); | |
// Or... | |
$userproMeta = get_user_meta( $current_user->ID, '_userpro_badges', false ); | |
$badgeURL = $userproMeta['badge_url'][0]; | |
return ! empty( $badgeURL ) ? $badgeURL : null; | |
}, | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment