BuddyDev

Search

Profile Visibility for existing users

  • Participant
    Kathy Goss on #3703

    Hi, I just purchased your Profile Visibility plugin.
    I am launching a site and have uploaded 200 users from another site that have been invited to beta test so they should not be visible until they accept. Unfortunately, I uploaded them as users prior to finding your plugin. I set the default to be not visible in member directory but because they are existing users they are not impacted by your plugin. Is there any way that I can efficiently change them all to not visible?

  • Keymaster
    (BuddyDev Team)
    Posts: 22218
    Brajesh Singh on #3704

    Hi Kathy,
    Welcome to BuddyDev. Thank you for purchasing the plugin.

    1. Please update the settings that you want to applied to all users in the Admin settings page

    2. Please put the following code in your bp-custom.php

    
    
    function bppv_custom_bulk_update() {
    
    	if ( get_site_option( 'bppv_custom_bulk_updated') || ! function_exists( 'bp_profile_visibility_get_default_settings' ) ) {
    		return ;//do not update again
    	}
    	//only admins with capability to manage users can do it
    	if ( !  current_user_can( 'delete_users' ) ) {
    		return ;
    	}
    
    	//apologies for the implicit dependency
    	$settings = bp_profile_visibility_get_default_settings();
    	if ( empty( $settings ) ) {
    		return ;
    	}
    
    	$keys = array_keys( $settings );
    
    	if ( empty( $keys ) ) {
    		return ;
    	}
    
    	$meta_keys = array_map( 'esc_sql', $keys );
    
    	$list = '\'' . join( '\', \'', $meta_keys ) . '\'';
    
    	$meta_list = '(' . $list .')';
    
    	//delete current preference
    
    	global $wpdb;
    
    	//Drop it for all existing Users
    	$delete_sql = "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN {$meta_list}";
    
    	$wpdb->query( $delete_sql );
    
    	//now update for each key
    	foreach ( $settings  as $key => $val ) {
    
    		if ( $key =='admin_only' ) {
    			continue;//
    		}
    		$update_settings_query = "INSERT INTO {$wpdb->usermeta} (user_id, meta_key, meta_value)
                    SELECT  ID, %s as meta_key, %s as meta_value   FROM {$wpdb->users} where ID !=0";
    
    		$prepared_query = $wpdb->prepare( $update_settings_query, $key, $val );
    
    		$wpdb->query( $prepared_query );
    		update_site_option( 'bppv_custom_bulk_updated', 1 );
    	}
    
    }
    //Run it only once
    add_action( 'init', 'bppv_custom_bulk_update' );//
    

    It needs to be run only once and It will overwrite the settings of ALL USERS(even for users with existing preference).

    After one run, you can remove the code if you want.

    Hope that helps.

  • Participant
    Level: Initiated
    Posts: 4
    SM on #5649
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 22218
    Brajesh Singh on #5681

    Hi Sm,
    I am sorry I though I replied earlier.

    Do you want everyone to be hidden on members directory all the time?

  • Participant
    Level: Initiated
    Posts: 4
    SM on #5690
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 22218
    Brajesh Singh on #5696

    Hi S,
    The plugin does not allow to set the directory visibility option for existing users. That change needs bulk update in database and most of the site due to lack of resources had issues.

    If you are able to use PHP My admin, Please post me the table prefix(it should be something like wp_ or similar) and the exact configuration you want for the users. I will post the bulk update sql queries instead.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 2
    Matthew Bourne on #6212

    Hi Im a bit unclear. I have the same issue of needing to default an initial batch of users to private. Does the code above work or not?

  • Keymaster
    (BuddyDev Team)
    Posts: 22218
    Brajesh Singh on #6215

    Hi Matthew,
    Thank you for posting. The above code works. Also, we will be adding the option to reset privacy settings for all members this weekend.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 2
    Matthew Bourne on #6217

    Great will wait till Monday then.

  • Keymaster
    (BuddyDev Team)
    Posts: 22218
    Brajesh Singh on #6219

    Thank you. I will post back here.

You must be logged in to reply to this topic.

This topic is: not resolved