Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Created December 2, 2024 12:44
Show Gist options
  • Select an option

  • Save yuriinalivaiko/2a473b4f09c12e103ca4597c298b1f5d to your computer and use it in GitHub Desktop.

Select an option

Save yuriinalivaiko/2a473b4f09c12e103ca4597c298b1f5d to your computer and use it in GitHub Desktop.
Remove the glitch field from the Ultimate Member form
<?php
// Set a field you want to remove here.
$meta_key = 'um_number_graduation';
function um_delete_field( $meta_key ) {
global $wpdb;
// Remove the field.
UM()->fields()->delete_field_from_db( $meta_key );
// Remove the field manually.
$fields = get_option( 'um_fields', array() );
foreach ( $fields as $key => $field ) {
if ( $key === $meta_key ) {
do_action( 'um_delete_custom_field', $key, $field );
unset( $fields[ $key ] );
}
}
update_option( 'um_fields', $fields );
// Remove the field from forms manually.
$forms = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'um_form'" );
foreach ( $forms as $form_id ) {
$form_fields = get_post_meta( $form_id, '_um_custom_fields', true );
if ( is_array( $form_fields ) ) {
foreach ( $form_fields as $key => $field ) {
if ( $key === $meta_key ) {
do_action( 'um_delete_custom_field', $key, $field );
unset( $form_fields[ $key ] );
}
}
update_post_meta( $form_id, '_um_custom_fields', $form_fields );
}
}
}
um_delete_field( $meta_key );
@yuriinalivaiko
Copy link
Copy Markdown
Author

Sometimes the field is not deleted completely. This is a rare case. It may happen if the Internet connection is interrupted when the field is deleted.


Go to the profile form builder and click the plus (+) icon to open the "Fields Manager". Scroll down to see the "Custom Fields" section. Do you see the glitch field in this section? You can remove the field by clicking the cross (❌) icon, see image.

Image - Standard way to remove a field.
How to remove a field


Try to remove the field using the code snippet from this gist if you don't see the glitch field in the "Custom Fields" section of the "Fields Manager".

You can use the Code Snippets plugin to execute this code, see image below. Change the $meta_key variable to the Meta Key of the field you want to remove and click the "Execute Once" button.

How to find the field Meta Key:

  • go to profile.
  • right click on the glitch field.
  • click the "Inspect" item.
  • look at the "Elements" tab in the browsers development tools.
  • find the data-key attribute of the field. The value inside the data-key attribute is the field Meta Key.

Image - How to find the field Meta Key.
How to find the field Meta Key

Image - How to execute the code.
Remove a glitch field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment