Advertiser API

Get Started

The Advertiser API provides programmatic access to create, retrieve, update, and manage advertiser accounts and their associated wallets. Use these methods to integrate advertiser management into your custom workflows or third-party services.

Getting Advertiser Data

All advertiser operations go through the Advertiser_Manager singleton:

use WBAM_Pro\Modules\Advertisers\Advertiser_Manager;

$manager = Advertiser_Manager::get_instance();

// Get by ID
$advertiser = $manager->get( $advertiser_id );

// Get by user ID
$advertiser = $manager->get_by_user( $user_id );

// Get by email
$advertiser = $manager->get_by_email( 'user@example.com' );

// List all advertisers
$advertisers = $manager->get_all( array(
    'status'   => 'active',
    'per_page' => 20,
    'page'     => 1,
    'orderby'  => 'created_at',
    'order'    => 'DESC',
) );

Creating Advertisers

$advertiser_id = $manager->create( array(
    'user_id'        => $user_id,
    'company_name'   => 'Acme Corp',
    'contact_name'   => 'John Doe',
    'email'          => 'john@acme.com',
    'phone'          => '555-1234',
    'website'        => 'https://acme.com',
    'status'         => 'active',
    'wallet_balance' => 0.00,
) );

Wallet Operations

The wallet system uses atomic database operations with row-level locking to ensure balance consistency:

// Credit wallet
$new_balance = $manager->credit_wallet( $advertiser_id, 100.00, 'payment', 'Stripe payment' );

// Debit wallet
$new_balance = $manager->debit_wallet( $advertiser_id, 25.00, 'campaign_spend', 'Campaign #123' );

// Get balance
$balance = $manager->get_wallet_balance( $advertiser_id );

// Get transaction history
$transactions = $manager->get_transactions( $advertiser_id, array(
    'per_page' => 20,
    'page'     => 1,
) );

Portal Integration

The advertiser portal is a frontend interface that lets advertisers manage their ads, campaigns, classifieds, and wallet. You can customize the portal tabs using the wbam_pro_portal_tabs filter:

add_filter( 'wbam_pro_portal_tabs', function( $tabs, $advertiser_id ) {
    $tabs['custom_tab'] = array(
        'label'    => __( 'Custom Tab', 'my-plugin' ),
        'callback' => 'my_custom_tab_callback',
        'priority' => 50,
    );
    return $tabs;
}, 10, 2 );

Code Example: Auto-Approve Trusted Advertisers

add_action( 'wbam_pro_ad_submitted', function( $submission_id, $advertiser_id, $data ) {
    $advertiser = wbam_pro_get_advertiser( $advertiser_id );

    // Auto-approve for trusted advertisers
    if ( 'trusted' === $advertiser['tier'] ) {
        $manager = WBAM_Pro\Modules\Ads\Ad_Submission_Manager::get_instance();
        $manager->approve( $submission_id, 0, 'Auto-approved (trusted advertiser)' );
    }
}, 10, 3 );

Code Example: Custom Analytics Dashboard Widget

add_action( 'wbam_pro_analytics_dashboard_widgets', function() {
    ?>
    <div class="wbam-widget">
        <h3><?php esc_html_e( 'Top Performing Advertisers', 'my-plugin' ); ?></h3>
        <?php
        global $wpdb;
        $top_advertisers = $wpdb->get_results( "
            SELECT a.company_name, SUM(t.amount) as total_spent
            FROM {$wpdb->prefix}wbam_advertisers a
            JOIN {$wpdb->prefix}wbam_transactions t ON a.id = t.advertiser_id
            WHERE t.type = 'debit' AND t.source = 'spend'
            GROUP BY a.id
            ORDER BY total_spent DESC
            LIMIT 10
        " );

        if ( $top_advertisers ) {
            echo '<ol>';
            foreach ( $top_advertisers as $adv ) {
                printf(
                    '<li>%s - $%s</li>',
                    esc_html( $adv->company_name ),
                    number_format( $adv->total_spent, 2 )
                );
            }
            echo '</ol>';
        }
        ?>
    </div>
    <?php
} );
Last updated: March 4, 2026