7
7
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-media-library/
8
8
* Description: Set the user profile image using image uploaded via Gravity Forms.
9
9
* Author: Gravity Wiz
10
- * Version: 1.2
10
+ * Version: 1.3
11
11
* Author URI: https://gravitywiz.com/
12
12
*/
13
13
class GPML_ACF_User_Image_Field {
14
14
15
+ protected $ _args ;
16
+
15
17
public function __construct ( $ args ) {
16
18
17
19
$ this ->_args = wp_parse_args (
@@ -28,6 +30,7 @@ public function __construct( $args ) {
28
30
29
31
add_action ( 'gform_user_registered ' , array ( $ this , 'update_user_image_field ' ), 10 , 3 );
30
32
add_action ( 'gform_user_updated ' , array ( $ this , 'update_user_image_field ' ), 10 , 3 );
33
+ add_filter ( "gform_gravityformsuserregistration_pre_process_feeds_ " . $ this ->_args ['form_id ' ], array ( $ this , 'disable_gfur_for_metakey ' ), 10 , 3 );
31
34
32
35
}
33
36
@@ -51,6 +54,36 @@ function update_user_image_field( $user_id, $feed, $entry ) {
51
54
}
52
55
}
53
56
57
+ /**
58
+ * If using this snippet with GF User Registration, we need to remove the mapping for the metakey to prevent GFUR
59
+ * from clearing out the value if an existing file is already set.
60
+ */
61
+ function disable_gfur_for_metakey ( $ feeds , $ entry , $ form ) {
62
+ foreach ( $ feeds as &$ feed ) {
63
+ // If the feed is not set to update, skip it.
64
+ if ( rgars ( $ feed , 'meta/feedType ' ) !== 'update ' ) {
65
+ continue ;
66
+ }
67
+
68
+ $ dynamic_field_map_fields = rgars ( $ feed , 'meta/userMeta ' );
69
+
70
+ if ( empty ( $ dynamic_field_map_fields ) || ! is_array ( $ dynamic_field_map_fields ) ) {
71
+ continue ;
72
+ }
73
+
74
+ // Remove the metakey mapping.
75
+ foreach ( $ dynamic_field_map_fields as $ difm_index => $ dynamic_field_map_field ) {
76
+ if ( $ dynamic_field_map_field ['key ' ] === $ this ->_args ['meta_key ' ] ) {
77
+ unset( $ dynamic_field_map_fields [$ difm_index ] );
78
+ }
79
+ }
80
+
81
+ $ feed ['meta ' ]['userMeta ' ] = $ dynamic_field_map_fields ;
82
+ }
83
+
84
+ return $ feeds ;
85
+ }
86
+
54
87
}
55
88
56
89
# Configuration
0 commit comments