description-property.php
1 year ago
display-name-property.php
1 year ago
first-name-property.php
1 year ago
last-name-property.php
1 year ago
nick-name-property.php
1 year ago
update-action.php
1 year ago
user-compare-password-property.php
1 year ago
user-confirm-password-property.php
1 year ago
user-email-property.php
1 year ago
user-id-property.php
1 year ago
user-meta-property.php
1 year ago
user-modifier.php
1 year ago
user-nicename-property.php
1 year ago
user-password-property.php
1 year ago
user-role-property.php
1 year ago
user-url-property.php
1 year ago
user-email-property.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Actions_V2\Update_User\Properties; |
| 5 | |
| 6 | use Jet_Form_Builder\Actions\Methods\Abstract_Modifier; |
| 7 | use Jet_Form_Builder\Actions\Methods\Base_Object_Property; |
| 8 | use Jet_Form_Builder\Exceptions\Action_Exception; |
| 9 | use Jet_Form_Builder\Exceptions\Handler_Exception; |
| 10 | use Jet_Form_Builder\Exceptions\Silence_Exception; |
| 11 | |
| 12 | // If this file is called directly, abort. |
| 13 | if ( ! defined( 'WPINC' ) ) { |
| 14 | die; |
| 15 | } |
| 16 | |
| 17 | class User_Email_Property extends Base_Object_Property { |
| 18 | |
| 19 | public function get_id(): string { |
| 20 | return 'email'; |
| 21 | } |
| 22 | |
| 23 | public function get_attach_id(): string { |
| 24 | return 'user_email'; |
| 25 | } |
| 26 | |
| 27 | public function get_label(): string { |
| 28 | return __( 'Email', 'jet-form-builder' ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @throws Action_Exception |
| 33 | */ |
| 34 | public function do_before( string $key, $value, Abstract_Modifier $modifier ) { |
| 35 | if ( empty( $value ) ) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | $email = sanitize_email( $value ); |
| 40 | |
| 41 | if ( $email !== $value ) { |
| 42 | throw new Action_Exception( 'empty_email' ); |
| 43 | } |
| 44 | |
| 45 | $email_exists = email_exists( $email ); |
| 46 | $id = $modifier->get( 'ID' ); |
| 47 | |
| 48 | if ( $email_exists && $id->value !== $email_exists ) { |
| 49 | throw new Action_Exception( 'email_exists' ); |
| 50 | } |
| 51 | |
| 52 | parent::do_before( $key, $value, $modifier ); |
| 53 | } |
| 54 | |
| 55 | public function get_related(): array { |
| 56 | return array( 'ID' ); |
| 57 | } |
| 58 | |
| 59 | } |
| 60 |