benecaster_sponsor_manager_before_save_campaign
Fires before a sponsor campaign is 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}, once the request has validated. A campaign belongs to one show.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$campaign_id |
int |
— | The campaign being changed, or `0` before a create |
$show_id |
int |
— | The campaign's show |
$fields |
array |
— | What will be 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 |
Example
add_action( 'benecaster_sponsor_manager_before_save_campaign', function ( int $campaign_id, int $show_id, array $fields ): void {
my_audit_log( 'campaign-saving', $campaign_id, $show_id, $fields['name'] );
}, 10, 3 );
Notes
A refused request fires nothing; a write that then fails fires this hook alone. $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 →