hook();
}
/**
* Setup hooks for classes.
*/
private function hook() {
add_action( 'template_redirect', tribe_callback( 'promoter.view', 'display_auth_check_view' ), 10, 0 );
add_action( 'init', tribe_callback( 'promoter.view', 'add_rewrites' ) );
/** @var Tribe__Promoter__PUE $pue */
$pue = tribe( 'promoter.pue' );
// Only add the setting if a promoter key is present.
if ( $pue->has_license_key() ) {
add_action(
'init',
tribe_callback( 'promoter.auth', 'register_setting' )
);
}
// The usage of a high priority so we can push the icon to the end
add_action( 'admin_bar_menu', [ $this, 'add_promoter_logo_on_admin_bar' ], 1000 );
add_action( 'tribe_common_loaded', [ $this, 'add_promoter_assets' ] );
}
/**
* Add Admin Bar link to the promoter website
*
* @since 4.9.2
* @param $wp_admin_bar
*/
public function add_promoter_logo_on_admin_bar( $wp_admin_bar ) {
/** @var Tribe__Promoter__PUE $pue */
$pue = tribe( 'promoter.pue' );
if ( ! $pue->has_license_key() ) {
return;
}
/**
* It uses and inline SVG as will provider more flexibility for styling so we can change
* the fill of the path property of the SVG so we can match the WP installations.
*/
$args = [
'id' => 'promoter-admin-bar',
'title' => sprintf(
"%s%s",
'',
'Promoter'
),
'href' => 'https://promoter.theeventscalendar.com/',
'meta' => [
'target' => '_blank',
'class' => 'promoter-admin-bar-link',
],
];
$wp_admin_bar->add_node( $args );
}
/**
* Register assets associated with promoter
*
* @since 4.9.2
*/
public function add_promoter_assets() {
tribe_asset(
Tribe__Main::instance(),
'promoter',
'promoter.css',
[],
[ 'wp_enqueue_scripts', 'admin_enqueue_scripts' ],
[
'conditionals' => [ $this, 'should_load_promoter_styles' ],
]
);
}
/**
* Only load the styles related to promoter if user is logged in and there's a valid license
* for promoter
*
* @since 4.9.2
*
* @return bool
*/
public function should_load_promoter_styles() {
return is_user_logged_in() && tribe( 'promoter.pue' )->has_license_key();
}
}