Skip to content

Instantly share code, notes, and snippets.

@jkhaui
Last active November 13, 2018 08:14
Show Gist options
  • Save jkhaui/6fcd4bf3c26cb640830440bd6e73075c to your computer and use it in GitHub Desktop.
Save jkhaui/6fcd4bf3c26cb640830440bd6e73075c to your computer and use it in GitHub Desktop.
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