Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verygoodplugins/25d6100358b4eb79d02fb3bbebd21b9f to your computer and use it in GitHub Desktop.
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
<?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