Automattic\WooCommerce\Internal\StockNotifications\Emails

EmailActionController::validate_and_maybe_process_requestpublicWC 1.0

Checks request parameters and processes the notification based on the action type.

Method of the class: EmailActionController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$EmailActionController = new EmailActionController();
$EmailActionController->validate_and_maybe_process_request( $notification_id, $email_link_action_key, $action ): void;
$notification_id(int) (required)
The ID of the notification to process.
$email_link_action_key(string) (required)
The action key from the email link.
$action(string)
The action to perform: 'verify' or 'unsubscribe'.
Default: ''

EmailActionController::validate_and_maybe_process_request() code WC 10.9.4

public function validate_and_maybe_process_request( int $notification_id, string $email_link_action_key, string $action = '' ): void {
	if ( empty( $email_link_action_key ) || empty( $notification_id ) ) {
		return;
	}

	// An empty $action means the caller omitted the routing argument — a
	// programming error, not a mis-routed email. Return silently so the
	// debug branch in the switch is reserved for genuinely-unknown
	// tokens arriving in the wild.
	if ( '' === $action ) {
		return;
	}

	$notification = $this->get_notification_to_be_processed( $notification_id );

	if ( ! $notification ) {
		return;
	}

	switch ( $action ) {
		case self::ACTION_VERIFY:
			$this->process_verification_action( $notification, $email_link_action_key );
			break;
		case self::ACTION_UNSUBSCRIBE:
			$this->process_unsubscribe_action( $notification, $email_link_action_key );
			break;
		default:
			// Unknown action — silently drop in production, log in debug so
			// mis-routed email links surface during alpha testing rather
			// than no-op'ing invisibly.
			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
				wc_get_logger()->debug(
					sprintf(
						'Unknown email_link_action "%s" for notification %d',
						$action,
						$notification->get_id()
					),
					array( 'source' => 'stock-notifications' )
				);
			}
			break;
	}//end switch
}