Advertisement
designbymerovingi

myCRED Log Menu Items - BuddyPress Addon

Nov 26th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. /**
  2.  * Setup Navigation
  3.  * @since 0.1
  4.  * @version 1.3
  5.  */
  6. public function setup_nav() {
  7.     global $bp;
  8.  
  9.     $user_id = bp_displayed_user_id();
  10.  
  11.     // User is excluded
  12.     if ( $this->core->exclude_user( $user_id ) ) return;
  13.  
  14.     // If visibility is not set for visitors
  15.     if ( ! is_user_logged_in() && ! $this->buddypress['visibility']['history'] ) return;
  16.  
  17.     // Admins always see the token history
  18.     if ( ! $this->core->can_edit_plugin() && $this->buddypress['history_location'] != 'top' ) return;
  19.  
  20.     // Show admins
  21.     if ( $this->core->can_edit_plugin() )
  22.         $show = true;
  23.     else
  24.         $show = $this->buddypress['visibility']['history'];
  25.  
  26.     // Top Level Nav Item
  27.     $top_name = bp_word_or_name(
  28.         $this->buddypress['history_menu_title']['me'],
  29.         $this->buddypress['history_menu_title']['others'], false, false );
  30.  
  31.     bp_core_new_nav_item( array(
  32.         'name'                    => $this->core->template_tags_general( $top_name ),
  33.         'slug'                    => 'mycred-history',
  34.         'parent_url'              => $bp->displayed_user->domain,
  35.         'default_subnav_slug'     => 'mycred-history',
  36.         'screen_function'         => array( $this, 'my_history' ),
  37.         'show_for_displayed_user' => $show,
  38.         'position'                => $this->buddypress['history_menu_pos']
  39.     ) );
  40.  
  41.     // Date Sorting
  42.     $date_sorting = apply_filters( 'mycred_sort_by_time', array(
  43.         ''          => __( 'All', 'mycred' ),
  44.         'today'     => __( 'Today', 'mycred' ),
  45.         'yesterday' => __( 'Yesterday', 'mycred' ),
  46.         'thisweek'  => __( 'This Week', 'mycred' ),
  47.         'thismonth' => __( 'This Month', 'mycred' )
  48.     ) );
  49.  
  50.     // "All" is default
  51.     bp_core_new_subnav_item( array(
  52.         'name'            => __( 'All', 'mycred' ),
  53.         'slug'            => 'mycred-history',
  54.         'parent_url'      => $bp->displayed_user->domain . $this->buddypress['history_url'] . '/',
  55.         'parent_slug'     => 'mycred-history',
  56.         'screen_function' => array( $this, 'my_history' )
  57.     ) );
  58.  
  59.     // Loop though and add each filter option as a sub menu item
  60.     if ( !empty( $date_sorting ) ) {
  61.         foreach ( $date_sorting as $sorting_id => $sorting_name ) {
  62.             if ( empty( $sorting_id ) ) continue;
  63.  
  64.             bp_core_new_subnav_item( array(
  65.                 'name'            => $sorting_name,
  66.                 'slug'            => $sorting_id,
  67.                 'parent_url'      => $bp->displayed_user->domain . $this->buddypress['history_url'] . '/',
  68.                 'parent_slug'     => 'mycred-history',
  69.                 'screen_function' => array( $this, 'my_history' )
  70.             ) );
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement