| 1 |
<?php |
| 2 |
/** |
| 3 |
* Form Submitted Event |
| 4 |
* |
| 5 |
* @package Forge12\DoubleOptIn\Events\Form |
| 6 |
* @since 4.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Forge12\DoubleOptIn\Events\Form; |
| 10 |
|
| 11 |
use Forge12\DoubleOptIn\EventSystem\Event; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Class FormSubmittedEvent |
| 19 |
* |
| 20 |
* @api |
| 21 |
* |
| 22 |
* Dispatched when a form is submitted before opt-in creation. |
| 23 |
* Listeners can modify this event to skip opt-in creation. |
| 24 |
* Covered by the Addon API semver policy as of Core API 4.3.0. |
| 25 |
*/ |
| 26 |
class FormSubmittedEvent extends Event { |
| 27 |
|
| 28 |
private int $formId; |
| 29 |
private string $formType; |
| 30 |
private array $postedData; |
| 31 |
private array $uploadedFiles; |
| 32 |
private string $formUrl; |
| 33 |
private bool $shouldCreateOptIn = true; |
| 34 |
private ?string $skipReason = null; |
| 35 |
|
| 36 |
/** |
| 37 |
* Constructor. |
| 38 |
* |
| 39 |
* @param int $formId The form ID. |
| 40 |
* @param string $formType The form type (cf7, avada, etc.). |
| 41 |
* @param array $postedData The submitted form data. |
| 42 |
* @param array $uploadedFiles The uploaded files. |
| 43 |
* @param string $formUrl The URL where the form was submitted. |
| 44 |
*/ |
| 45 |
public function __construct( |
| 46 |
int $formId, |
| 47 |
string $formType, |
| 48 |
array $postedData, |
| 49 |
array $uploadedFiles, |
| 50 |
string $formUrl |
| 51 |
) { |
| 52 |
parent::__construct(); |
| 53 |
$this->formId = $formId; |
| 54 |
$this->formType = $formType; |
| 55 |
$this->postedData = $postedData; |
| 56 |
$this->uploadedFiles = $uploadedFiles; |
| 57 |
$this->formUrl = $formUrl; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* {@inheritdoc} |
| 62 |
*/ |
| 63 |
public static function getWordPressHookName(): string { |
| 64 |
return 'f12_cf7_doubleoptin_form_submitted'; |
| 65 |
} |
| 66 |
|
| 67 |
public function getFormId(): int { |
| 68 |
return $this->formId; |
| 69 |
} |
| 70 |
|
| 71 |
public function getFormType(): string { |
| 72 |
return $this->formType; |
| 73 |
} |
| 74 |
|
| 75 |
public function getPostedData(): array { |
| 76 |
return $this->postedData; |
| 77 |
} |
| 78 |
|
| 79 |
public function getUploadedFiles(): array { |
| 80 |
return $this->uploadedFiles; |
| 81 |
} |
| 82 |
|
| 83 |
public function getFormUrl(): string { |
| 84 |
return $this->formUrl; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Check if opt-in should be created. |
| 89 |
* |
| 90 |
* @return bool |
| 91 |
*/ |
| 92 |
public function shouldCreateOptIn(): bool { |
| 93 |
return $this->shouldCreateOptIn; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Skip opt-in creation for this submission. |
| 98 |
* |
| 99 |
* @param string $reason The reason for skipping. |
| 100 |
* |
| 101 |
* @return void |
| 102 |
*/ |
| 103 |
public function skipOptInCreation( string $reason = '' ): void { |
| 104 |
$this->shouldCreateOptIn = false; |
| 105 |
$this->skipReason = $reason; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Get the reason for skipping. |
| 110 |
* |
| 111 |
* @return string|null |
| 112 |
*/ |
| 113 |
public function getSkipReason(): ?string { |
| 114 |
return $this->skipReason; |
| 115 |
} |
| 116 |
} |
| 117 |
|