| 1 |
<?php |
| 2 |
/** |
| 3 |
* GamiPress Points BuddyPress Component |
| 4 |
* |
| 5 |
* @package GamiPress\BuddyPress\GamiPress_Points_BP_Component |
| 6 |
* @since 1.0.8 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
if( ! class_exists( 'GamiPress_Points_BP_Component' ) ) { |
| 13 |
|
| 14 |
/** |
| 15 |
* Class GamiPress_Points_BP_Component |
| 16 |
* |
| 17 |
* @since 1.0.8 |
| 18 |
*/ |
| 19 |
class GamiPress_Points_BP_Component extends BP_Component { |
| 20 |
|
| 21 |
function __construct() { |
| 22 |
parent::start( |
| 23 |
'gamipress-points', |
| 24 |
__( 'GamiPress Points', 'gamipress' ), |
| 25 |
BP_PLUGIN_DIR |
| 26 |
); |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
// Globals |
| 31 |
public function setup_globals( $args = '' ) { |
| 32 |
$points_tab_title = gamipress_bp_get_option( 'points_tab_title', __( 'Points', 'gamipress' ) ); |
| 33 |
$points_tab_slug = gamipress_bp_get_option( 'points_tab_slug', '' ); |
| 34 |
|
| 35 |
// If empty slug generate it from the title |
| 36 |
if( empty( $points_tab_slug ) ) { |
| 37 |
$points_tab_slug = sanitize_title( $points_tab_title ); |
| 38 |
} |
| 39 |
|
| 40 |
parent::setup_globals( array( |
| 41 |
'has_directory' => true, |
| 42 |
'root_slug' => $points_tab_slug, |
| 43 |
'slug' => $points_tab_slug, |
| 44 |
) ); |
| 45 |
} |
| 46 |
|
| 47 |
// BuddyPress actions |
| 48 |
public function setup_actions() { |
| 49 |
parent::setup_actions(); |
| 50 |
} |
| 51 |
|
| 52 |
// Member Profile Menu |
| 53 |
public function setup_nav( $main_nav = '', $sub_nav = '' ) { |
| 54 |
|
| 55 |
if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) |
| 56 |
return; |
| 57 |
|
| 58 |
if( ! (bool) gamipress_bp_get_option( 'points_tab', false ) ) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
$points_types_to_show = gamipress_bp_tab_get_points_types(); |
| 63 |
|
| 64 |
if( empty( $points_types_to_show ) ) { |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Filter to programmatically decide if tab should be displayed |
| 70 |
* |
| 71 |
* @param bool $show |
| 72 |
* @param int $displayed_user_id |
| 73 |
* |
| 74 |
* @return bool |
| 75 |
*/ |
| 76 |
if( ! (bool) apply_filters( 'gamipress_bp_member_points_tab', true, bp_displayed_user_id() ) ) { |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
$tab_title = gamipress_bp_get_option( 'points_tab_title', __( 'Points', 'gamipress' ) ); |
| 81 |
|
| 82 |
$sub_nav = ''; |
| 83 |
|
| 84 |
// Add to the main navigation |
| 85 |
$main_nav = array( |
| 86 |
'name' => $tab_title, |
| 87 |
'slug' => $this->slug, |
| 88 |
'position' => 100, |
| 89 |
'screen_function' => 'gamipress_bp_points_tab', |
| 90 |
'default_subnav_slug' => $this->slug |
| 91 |
); |
| 92 |
|
| 93 |
parent::setup_nav( $main_nav, $sub_nav ); |
| 94 |
} |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
} |