assets
1 year ago
properties
1 year ago
update-user-action.php
1 year ago
update-user.php
1 year ago
update-user-action.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JFB_Modules\Actions_V2\Update_User; |
| 4 | |
| 5 | use Jet_Form_Builder\Actions\Action_Handler; |
| 6 | use JFB_Modules\Actions_V2\Update_User\Properties\User_Modifier; |
| 7 | use Jet_Form_Builder\Actions\Types\Base; |
| 8 | use Jet_Form_Builder\Classes\Arrayable\Array_Tools; |
| 9 | use Jet_Form_Builder\Classes\Tools; |
| 10 | use Jet_Form_Builder\Exceptions\Action_Exception; |
| 11 | |
| 12 | // If this file is called directly, abort. |
| 13 | if ( ! defined( 'WPINC' ) ) { |
| 14 | die; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Define Base_Type class |
| 19 | */ |
| 20 | class Update_User_Action extends Base { |
| 21 | |
| 22 | public function get_name() { |
| 23 | return __( 'Update User', 'jet-form-builder' ); |
| 24 | } |
| 25 | |
| 26 | public function get_id() { |
| 27 | return 'update_user'; |
| 28 | } |
| 29 | |
| 30 | public function action_attributes() { |
| 31 | return array( |
| 32 | 'fields_map' => array( |
| 33 | 'default' => array(), |
| 34 | ), |
| 35 | 'user_role' => array( |
| 36 | 'default' => '', |
| 37 | ), |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @param array $request |
| 43 | * @param Action_Handler $handler |
| 44 | * |
| 45 | * @return void |
| 46 | * @throws Action_Exception |
| 47 | */ |
| 48 | public function do_action( array $request, Action_Handler $handler ) { |
| 49 | ( new User_Modifier() ) |
| 50 | ->set_request( $request ) |
| 51 | ->set_fields_map( $this->settings['fields_map'] ?? array() ) |
| 52 | ->set( 'role', $this->settings['user_role'] ?? false ) |
| 53 | ->run(); |
| 54 | } |
| 55 | |
| 56 | public function self_script_name() { |
| 57 | return 'jetFormUpdateUserData'; |
| 58 | } |
| 59 | |
| 60 | public function editor_labels() { |
| 61 | return array( |
| 62 | 'fields_map' => __( 'Fields Map:', 'jet-form-builder' ), |
| 63 | 'user_role' => __( 'User Role:', 'jet-form-builder' ), |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Regsiter custom action data for the editor |
| 69 | * |
| 70 | * @return [type] [description] |
| 71 | */ |
| 72 | public function action_data() { |
| 73 | return array( |
| 74 | 'userRoles' => Tools::get_user_roles_for_js(), |
| 75 | 'properties' => Tools::with_placeholder( |
| 76 | Array_Tools::to_array( ( new User_Modifier() )->properties->all() ) |
| 77 | ), |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | } |
| 82 |