Skip to main content

BulkEnrollmentProcessor

Benecaster\Subscribers\BulkEnrollmentProcessor

Synchronous core processor for bulk subscriber enrollment. Accepts a list of email addresses and a target tier, iterates each address, and creates subscriber records. Can be called directly without WP-Cron.

Method

public function enroll(
    int    $show_id,
    string $tier_slug,
    array  $emails,
    string $job_id = ''
): array

Parameters

Name Type Description
$show_id int Show post ID
$tier_slug string The membership tier slug to assign
$emails string[] Array of email address strings to process
$job_id string Optional job identifier; passed through to benecaster_bulk_enrollment_complete

Return Value

Associative array with integer keys enrolled, skipped, and errors.

[
    'enrolled' => 47,
    'skipped'  => 3,
    'errors'   => 0,
]

Per-Row Outcomes

For each address in $emails:

Outcome Condition
enrolled Address belongs to an existing WP user who is not already an active subscriber on any tier; subscription created, token generated, welcome email queued
skipped Address is already active on the selected tier; or address belongs to an active subscriber on a different tier; or address does not match any WP user
error Unexpected exception during subscriber record creation

Notes

The processor does not create WordPress user accounts. Only existing WP users can be enrolled. Addresses that match no user are silently skipped, not errored.

The maximum per call is 1,000 addresses. BulkEnrollmentJobRunner enforces this limit when submitting jobs; callers invoking the processor directly are responsible for their own batching.

benecaster_subscription_activated fires for each successful enrollment with $source = 'admin_enrolled'.

Direct Usage

$processor = new \Benecaster\Subscribers\BulkEnrollmentProcessor();
$result = $processor->enroll(
    show_id:   $show_id,
    tier_slug: 'gold',
    emails:    $email_list,
);

Calling the processor directly bypasses the one-active-job-per-show constraint managed by BulkEnrollmentJobRunner. Use it only for non-interactive or test contexts.