designbymerovingi

Show myCRED Balance in Navigation

Jan 12th, 2015
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. /**
  2.  * Insert myCRED Balance in Navigation
  3.  * Injects extra menu items in the main menu showing the logged
  4.  * in users balance.
  5.  * @version 1.0
  6.  */
  7. add_filter( 'wp_nav_menu_items', 'mycred_pro_add_balance_in_nav', 90, 2 );
  8. function mycred_pro_add_balance_in_nav( $items, $args ) {
  9.  
  10.     if ( $args->theme_location != 'main-menu' || ! function_exists( 'mycred' ) || ! is_user_logged_in() )
  11.         return $items;
  12.  
  13.     $user_id = get_current_user_id();
  14.     $mycred_types = mycred_get_types();
  15.  
  16.     foreach ( $mycred_types as $type_id => $label ) {
  17.  
  18.         $mycred = mycred( $type_id );
  19.  
  20.         if ( $mycred->exclude_user( $user_id ) ) continue;
  21.  
  22.         $balance = $mycred->get_users_balance( $user_id, $type_id );
  23.        
  24.         $items[] = '<li class="menu-item menu-item-type-post_type menu-item-balance">' . $mycred->format_creds( $balance ) . '</li>';
  25.  
  26.     }
  27.  
  28.     return $items;
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment