Dashboard Widget: Pending Referrals (AffiliateWP)
Adds a dashboard widget for administrators with the number and value of referrals waiting for review, plus pending affiliate applications, linking to each AffiliateWP screen.
Opens WPIDE on
Code
add_action( 'wp_dashboard_setup', function () {
if ( ! function_exists( 'affiliate_wp' ) || ! current_user_can( 'manage_referrals' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_affwp_pending', __( 'Affiliate program' ), function () {
$data = get_transient( 'wpide_affwp_pending' );
if ( false === $data ) {
$data = array(
'referrals' => (int) affiliate_wp()->referrals->count( array( 'status' => 'pending' ) ),
'affiliates' => (int) affiliate_wp()->affiliates->count( array( 'status' => 'pending' ) ),
);
set_transient( 'wpide_affwp_pending', $data, 10 * MINUTE_IN_SECONDS );
}
printf(
'<p><a href="%1$s"><strong>%2$s</strong> %3$s</a></p><p><a href="%4$s"><strong>%5$s</strong> %6$s</a></p>',
esc_url( admin_url( 'admin.php?page=affiliate-wp-referrals&status=pending' ) ),
esc_html( number_format_i18n( $data['referrals'] ) ),
esc_html__( 'referrals pending review' ),
esc_url( admin_url( 'admin.php?page=affiliate-wp-affiliates&status=pending' ) ),
esc_html( number_format_i18n( $data['affiliates'] ) ),
esc_html__( 'affiliate applications waiting' )
);
} );
} );
Notes
Counts are cached for ten minutes.
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.