Skip to main content

benecaster_get_marketing_consent()

Membership Free
benecaster_get_marketing_consent( int $user_id, int $show_id ): ?array

Reads a person’s marketing-consent answer for one show. Benecaster asks for consent on its own forms only when an add-on asks it to, with benecaster_marketing_consent_label, and stores one current answer per person per show; a later answer replaces it.

null is not “no”. It means Benecaster never showed this person the box on that show — they joined through a membership plugin, before your add-on asked, or were added by an admin. Apply your own default for that show, and never treat null as a refusal or as consent.

granted alone is not enough. An unverified yes may have been ticked by someone typing a stranger’s address. It becomes verified when the owner answers while logged in or clicks any Benecaster signed link for the show. A cautious add-on emails only when granted && verified.

Parameters

Name Type Default Required Description
user_id int — Yes WordPress user ID.
show_id int — Yes The show the answer is for.

Return Value

Type: array|null

array{granted: bool, verified: bool, source: string, consent_text: string, recorded_at: string} — the person's current answer for that show — or null when they were never asked there. granted is whether they ticked the box; verified whether the address was proven to be theirs; source is subscribe, follower_signup or donation; consent_text is the exact label they were shown; recorded_at is when they answered, UTC Y-m-d H:i:s.

Example

function my_addon_may_email( int $user_id, int $show_id ): bool {
    $consent = benecaster_get_marketing_consent( $user_id, $show_id );
    if ( null === $consent ) {
        return 'opt_out' === get_option( "my_addon_opt_in_mode_{$show_id}" ); // your default
    }
    return $consent['granted'] && $consent['verified'];
}

Notes

Erasing a person's data — either WordPress personal-data erasure or Delete subscriber data — removes their answers. The nightly inactivity sweep keeps them: a quiet listener has not withdrawn consent, and the record is the proof it was given. Export Personal Data lists them under Benecaster Marketing Consent. To hear an answer change, use benecaster_marketing_consent_changed. Worked example: the recipe Ask for marketing consent on Benecaster's own forms.

Need this built rather than just documented? See our services →