• Resolved Jose Llanos

    (@latinunit)


    In the database I have the following user meta;

    View post on imgur.com

    I use the following function to delete the user meta

    delete_user_meta( $user_id, 'dismissed_wp_pointers', 'lu_ban_settings_pointer' );

    Where lu_ban_settings_pointer is the meta value I want to match, the problem here is that the data contains comma separated values, so a full string match will fail

    wp330_toolbar,wp330_saving_widgets,wp340_choose_image_from_library,wp340_customize_current_theme_link,wp350_media,wp360_revisions,wp360_locks,lu_ban_settings_pointer

    The problem is that the function only deletes the meta value as long as the full string matches, meaning that I have to go through the array and match the substring.

    What would be the best way to achieve this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Jose Llanos

    (@latinunit)

    Update

    A friend achieved to perform this operation by doing the following;

    $remove_value = 'lu_ban_settings_pointer';
        $meta_data = get_user_meta( $user_id->ID, 'dismissed_wp_pointers' );
        if (isset($meta_data['0'])) {
            //                           //at end (or mid)  //at beg (or mid)  //failsafe
            $new_val = str_replace(array(','.$remove_value, $remove_value.',', $remove_value), '', $meta_data['0'])
            update_user_meta( $user_id->ID, 'dismissed_wp_pointers', $new_val);
        }//end isset meta_data 0

    However, I think that there should be an easier way of achieving this, why would WordPress make it so difficult to delete a comma separated value in a user’s meta data.?

    Thread Starter Jose Llanos

    (@latinunit)

    Can anyone help please, it is rather urgent

    Thread Starter Jose Llanos

    (@latinunit)

    I’ve solved it. thanks

    Yeah this is pretty difficult. Ugh.

    This is how I’m deleting the dismissed_wp_pointers from the array:

    //Display
    		$dismissed_pointers = explode( ',', get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
    
    		// Check if our pointer is among dismissed ones and delete that mofo
    		if ( in_array( 'gmb_welcome_pointer', $dismissed_pointers ) ) {
    			$key = array_search( 'gmb_welcome_pointer', $dismissed_pointers );
    			delete_user_meta( $user_id, 'dismissed_wp_pointers', $key['gmb_welcome_pointer'] );
    		}
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘delete_user_meta problem matching substring’ is closed to new replies.