benecaster_sponsor_manager_after_save_campaign
Fires once a sponsor campaign has been created or changed on the Sponsors screen, or through POST /benecaster-sponsor-manager/v1/shows/{show_id}/campaigns or PUT, PATCH /benecaster-sponsor-manager/v1/shows/{show_id}/campaigns/{id}. It fires only when the write succeeded.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$campaign_id |
int |
— | The campaign saved |
$show_id |
int |
— | The campaign's show |
$fields |
array |
— | What was written: `name`, `start_date`, `end_date` (`YYYY-MM-DD` or `''`), `currency` (upper case), and, on every create and whenever a rate key was sent, `rate_type` (`flat` or `per_episode`), `rate_by_position` (bool), `rate_minor` (int or null) and `position_rates` (`[ 'pre_roll' => ?int, 'mid_roll' => ?int, 'post_roll' => ?int ]`). Amounts are in the currency's smallest unit |
$created |
bool |
— | `true` for a new campaign, `false` for a change |
Example
// Copy each new campaign into a CRM the podcaster uses, with its show.
add_action( 'benecaster_sponsor_manager_after_save_campaign', function ( int $campaign_id, int $show_id, array $fields, bool $created ): void {
if ( $created ) {
my_crm_add_deal( $campaign_id, $show_id, $fields['name'], $fields['start_date'], $fields['end_date'] );
}
}, 10, 4 );
Notes
$fields holds the rate: never pass it to anything public. Walkthrough: Read, create, change, archive or restore the site's sponsors and a show's sponsor campaigns from code, as the Sponsors screen does.
Affects
- Benecaster → Sponsors
- POST benecaster-sponsor-manager/v1/shows/{show_id}/campaigns
- PUT, PATCH benecaster-sponsor-manager/v1/shows/{show_id}/campaigns/{id}
Need this built rather than just documented? See our services →