Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Insert myCRED Balance in Navigation
- * Injects extra menu items in the main menu showing the logged
- * in users balance.
- * @version 1.0
- */
- add_filter( 'wp_nav_menu_items', 'mycred_pro_add_balance_in_nav', 90, 2 );
- function mycred_pro_add_balance_in_nav( $items, $args ) {
- if ( $args->theme_location != 'main-menu' || ! function_exists( 'mycred' ) || ! is_user_logged_in() )
- return $items;
- $user_id = get_current_user_id();
- $mycred_types = mycred_get_types();
- foreach ( $mycred_types as $type_id => $label ) {
- $mycred = mycred( $type_id );
- if ( $mycred->exclude_user( $user_id ) ) continue;
- $balance = $mycred->get_users_balance( $user_id, $type_id );
- $items[] = '<li class="menu-item menu-item-type-post_type menu-item-balance">' . $mycred->format_creds( $balance ) . '</li>';
- }
- return $items;
- }
Advertisement
Add Comment
Please, Sign In to add comment