jetformbuilder
/
modules
/
actions-v2
/
update-user
/
properties
/
user-compare-password-property.php
description-property.php
2 years ago
display-name-property.php
2 years ago
first-name-property.php
2 years ago
last-name-property.php
2 years ago
nick-name-property.php
2 years ago
update-action.php
2 years ago
user-compare-password-property.php
8 months ago
user-confirm-password-property.php
2 years ago
user-email-property.php
2 years ago
user-id-property.php
2 years ago
user-meta-property.php
2 years ago
user-modifier.php
2 months ago
user-nicename-property.php
2 years ago
user-password-property.php
2 years ago
user-role-property.php
2 months ago
user-url-property.php
2 years ago
user-compare-password-property.php
62 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\Actions\Methods\Exceptions\Modifier_Exclude_Property; |
| 9 | use Jet_Form_Builder\Exceptions\Action_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_Compare_Password_Property extends Base_Object_Property { |
| 18 | |
| 19 | public function get_id(): string { |
| 20 | return 'compare_password'; |
| 21 | } |
| 22 | |
| 23 | public function get_label(): string { |
| 24 | return __( 'Compare with Current Password', 'jet-form-builder' ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @param string $key |
| 29 | * @param $value |
| 30 | * @param Abstract_Modifier $modifier |
| 31 | * |
| 32 | * @throws Action_Exception |
| 33 | */ |
| 34 | public function do_before( string $key, $value, Abstract_Modifier $modifier ) { |
| 35 | $id = $modifier->get( 'ID' ); |
| 36 | $user_id = $id->value; |
| 37 | |
| 38 | if ( false === $id && false === $user_id ) { |
| 39 | throw new Action_Exception( 'internal_error' ); |
| 40 | } |
| 41 | |
| 42 | $user = get_user_by( 'ID', $user_id ); |
| 43 | |
| 44 | if ( ! is_a( $user, \WP_User::class ) ) { |
| 45 | // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 46 | throw new Action_Exception( 'internal_error', $user, $value ); |
| 47 | } |
| 48 | |
| 49 | if ( ! wp_check_password( $value, $user->user_pass, $user->ID ) ) { |
| 50 | throw new Action_Exception( 'incorrect_old_password' ); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | public function get_related(): array { |
| 55 | return array( 'ID' ); |
| 56 | } |
| 57 | |
| 58 | public function get_help(): string { |
| 59 | return __( 'Password comparison works correctly with the DEFAULT.PROCESS event.', 'jet-form-builder' ); |
| 60 | } |
| 61 | } |
| 62 |