Affiliate Area Link in the Admin Bar (AffiliateWP)
Adds an "Affiliate Area" link to the toolbar for logged-in affiliates, showing their unpaid earnings, so they can reach their dashboard from anywhere on the site.
Opens WPIDE on
Code
add_action( 'admin_bar_menu', function ( $bar ) {
if ( ! function_exists( 'affwp_get_affiliate_id' ) || ! is_user_logged_in() ) {
return;
}
$affiliate_id = affwp_get_affiliate_id( get_current_user_id() );
$page_id = (int) affiliate_wp()->settings->get( 'affiliates_page' );
if ( ! $affiliate_id || ! $page_id ) {
return;
}
$bar->add_node( array(
'id' => 'wpide-affiliate-area',
'title' => esc_html( sprintf( 'Affiliate Area (%s)', wp_strip_all_tags( affwp_get_affiliate_unpaid_earnings( $affiliate_id, true ) ) ) ),
'href' => get_permalink( $page_id ),
) );
}, 85 );
Notes
Uses the Affiliate Area page set in AffiliateWP > Settings.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.