PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.4.2
JetFormBuilder — Dynamic Blocks Form Builder v3.6.4.2
3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / actions-v2 / update-user / update-user-action.php
jetformbuilder / modules / actions-v2 / update-user Last commit date
assets 2 months ago properties 2 months ago update-user-action.php 2 months ago update-user.php 2 weeks ago
update-user-action.php
112 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\Admin\Tabs_Handlers\Tab_Handler_Manager;
9 use Jet_Form_Builder\Admin\Pages\Pages_Manager;
10 use Jet_Form_Builder\Classes\Arrayable\Array_Tools;
11 use Jet_Form_Builder\Classes\Tools;
12 use Jet_Form_Builder\Exceptions\Action_Exception;
13
14 // If this file is called directly, abort.
15 if ( ! defined( 'WPINC' ) ) {
16 die;
17 }
18
19 /**
20 * Define Base_Type class
21 */
22 class Update_User_Action extends Base {
23
24 public function get_name() {
25 return __( 'Update User', 'jet-form-builder' );
26 }
27
28 public function get_id() {
29 return 'update_user';
30 }
31
32 public function action_attributes() {
33 return array(
34 'fields_map' => array(
35 'default' => array(),
36 ),
37 'user_role' => array(
38 'default' => '',
39 ),
40 );
41 }
42
43 /**
44 * @param array $request
45 * @param Action_Handler $handler
46 *
47 * @return void
48 * @throws Action_Exception
49 */
50 public function do_action( array $request, Action_Handler $handler ) {
51 $modifier = ( new User_Modifier() )
52 ->set_request( $request )
53 ->set_fields_map( $this->settings['fields_map'] ?? array() )
54 ->set_self_promotable_roles( $this->get_self_promotable_roles() );
55
56 $user_roles = isset( $this->settings['user_role'] ) ? Tools::get_array_of_user_roles( $this->settings['user_role'] ) : '';
57
58 if ( ! empty( $user_roles ) ) {
59 $main_role = Tools::get_main_user_role_by_priority( $user_roles );
60
61 if ( ! empty( $main_role ) ) {
62 $additional_roles = array_filter( $user_roles, fn( $r ) => $r !== $main_role );
63
64 $roles = array_merge( array( $main_role ), $additional_roles );
65
66 $modifier->set( 'role', $roles );
67 }
68 }
69
70 $modifier->run();
71 }
72
73 public function self_script_name() {
74 return 'jetFormUpdateUserData';
75 }
76
77 public function editor_labels() {
78 return array(
79 'fields_map' => __( 'Fields Map:', 'jet-form-builder' ),
80 'user_role' => __( 'User Role:', 'jet-form-builder' ),
81 );
82 }
83
84 /**
85 * Regsiter custom action data for the editor
86 *
87 * @return [type] [description]
88 */
89 public function action_data() {
90 return array(
91 'userRoles' => Tools::get_user_roles_for_js(),
92 'globalSelfPromotableRoles' => $this->get_self_promotable_roles(),
93 'globalSettingsUrl' => Pages_Manager::instance()->get_stable_url( 'jfb-settings' ) . '#options-tab',
94 'properties' => Tools::with_placeholder(
95 Array_Tools::to_array( ( new User_Modifier() )->properties->all() )
96 ),
97 );
98 }
99
100 private function get_self_promotable_roles(): array {
101 $options = Tab_Handler_Manager::get_options( 'options-tab' );
102 $roles = Tools::get_array_of_user_roles( $options['self_promotable_roles'] ?? array() );
103
104 return array_values(
105 array_filter(
106 array_map( 'strval', $roles )
107 )
108 );
109 }
110
111 }
112