Skip to content

Commit f67f43a

Browse files
committed
gpml-acf-user-image-field.php: Improved compatibility with GF User Registration.
1 parent ffcc2d5 commit f67f43a

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

gp-media-library/gpml-acf-user-image-field.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-media-library/
88
* Description: Set the user profile image using image uploaded via Gravity Forms.
99
* Author: Gravity Wiz
10-
* Version: 1.2
10+
* Version: 1.3
1111
* Author URI: https://gravitywiz.com/
1212
*/
1313
class GPML_ACF_User_Image_Field {
1414

15+
protected $_args;
16+
1517
public function __construct( $args ) {
1618

1719
$this->_args = wp_parse_args(
@@ -28,6 +30,7 @@ public function __construct( $args ) {
2830

2931
add_action( 'gform_user_registered', array( $this, 'update_user_image_field' ), 10, 3 );
3032
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 );
3134

3235
}
3336

@@ -51,6 +54,36 @@ function update_user_image_field( $user_id, $feed, $entry ) {
5154
}
5255
}
5356

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+
5487
}
5588

5689
# Configuration

0 commit comments

Comments
 (0)