Created
May 15, 2018 12:26
-
-
Save verygoodplugins/25d6100358b4eb79d02fb3bbebd21b9f to your computer and use it in GitHub Desktop.
Deletes user meta fields if the data loaded from the CRM is missing or empty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Deletes user meta fields if the data loaded from the CRM is missing or empty | |
function wpf_remove_empty_meta_fields( $user_id, $user_meta ) { | |
$contact_fields = wp_fusion()->settings->get( 'contact_fields' ); | |
foreach ( $contact_fields as $field_id => $field_data ) { | |
if ( $field_data['active'] == true && empty( $user_meta[ $field_id ] ) ) { | |
delete_user_meta( $user_id, $field_id ); | |
} | |
} | |
add_action( 'wpf_user_updated', 'wpf_remove_empty_meta_fields', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment