Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpml-acf-user-image-field.php: Improved compatibility with GF User Registration. #754

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion gp-media-library/gpml-acf-user-image-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-media-library/
* Description: Set the user profile image using image uploaded via Gravity Forms.
* Author: Gravity Wiz
* Version: 1.2
* Version: 1.3
* Author URI: https://gravitywiz.com/
*/
class GPML_ACF_User_Image_Field {

protected $_args;

Check failure on line 15 in gp-media-library/gpml-acf-user-image-field.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Tabs must be used to indent lines; spaces are not allowed

public function __construct( $args ) {

$this->_args = wp_parse_args(
Expand All @@ -28,6 +30,7 @@

add_action( 'gform_user_registered', array( $this, 'update_user_image_field' ), 10, 3 );
add_action( 'gform_user_updated', array( $this, 'update_user_image_field' ), 10, 3 );
add_filter( "gform_gravityformsuserregistration_pre_process_feeds_" . $this->_args['form_id'], array( $this, 'disable_gfur_for_metakey' ), 10, 3 );

Check failure on line 33 in gp-media-library/gpml-acf-user-image-field.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 33 in gp-media-library/gpml-acf-user-image-field.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

String "gform_gravityformsuserregistration_pre_process_feeds_" does not require double quotes; use single quotes instead

}

Expand All @@ -51,6 +54,36 @@
}
}

/**

Check failure on line 57 in gp-media-library/gpml-acf-user-image-field.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Tabs must be used to indent lines; spaces are not allowed
* If using this snippet with GF User Registration, we need to remove the mapping for the metakey to prevent GFUR

Check failure on line 58 in gp-media-library/gpml-acf-user-image-field.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Tabs must be used to indent lines; spaces are not allowed
* from clearing out the value if an existing file is already set.
*/
function disable_gfur_for_metakey( $feeds, $entry, $form ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function disable_gfur_for_metakey( $feeds, $entry, $form ) {
function disable_gfur_for_meta_key( $feeds, $entry, $form ) {

foreach ( $feeds as &$feed ) {
// If the feed is not set to update, skip it.
if ( rgars( $feed, 'meta/feedType' ) !== 'update' ) {
continue;
}

$dynamic_field_map_fields = rgars( $feed, 'meta/userMeta' );

if ( empty( $dynamic_field_map_fields ) || ! is_array( $dynamic_field_map_fields ) ) {
continue;
}

// Remove the metakey mapping.
foreach ( $dynamic_field_map_fields as $difm_index => $dynamic_field_map_field ) {
if ( $dynamic_field_map_field['key'] === $this->_args['meta_key'] ) {
unset( $dynamic_field_map_fields[$difm_index] );
}
}

$feed['meta']['userMeta'] = $dynamic_field_map_fields;
}

return $feeds;
}

}

# Configuration
Expand Down
Loading