• Resolved nicmare

    (@nicmare)


    i have to export user data a lot but i am to lazy to select the meta keys. therefore i came up with this solution:
    find that line of code:
    echo "<option value='".esc_attr( $key )."' title='".esc_attr( $key )."' class='".$usermeta_class."'>$display_key</option>";

    and replace it:

    $checkarray = array(
    	"Blog", // your custom meta key
    	"Ausbildung" // another custom meta key
    );
    
    if(in_array( $key,$checkarray)){
    	$selectedoption = 'selected="selected"';
    }else{
    	$selectedoption = '';
    }
    echo "<option ".$selectedoption." value='".esc_attr( $key )."' title='".esc_attr( $key )."' class='".$usermeta_class."'>$display_key</option>";

    now the meta keys “Blog” and “Ausbildung” are selected by default

    https://www.ads-software.com/plugins/export-user-data/

Viewing 11 replies - 16 through 26 (of 26 total)
  • Thanks Q,

    I’ve tried it out and that seems to work okay for me.

    I believe that sanitize code you were asking about should changed to be:

    // update_option sanitizes the option name but not the option value ##
                    foreach ( $options as $field_name => $field_value ) {
    
                        // so do that here. ##
                        if ( is_array( $field_value ) ) {
    
                            foreach ( $field_value as $field_array_key => $field_array_value ) {
    
                                $options[$field_name][$field_array_key] = sanitize_text_field( $field_array_value );
    
                            }
    
                        } else {
    
                            $options[$field_name] = sanitize_text_field( $field_value );
    
                        }
    
                    }

    Oh, and as an experiment I tried pulling the version of BP_XProfile_ProfileData::get_all_for_user from Buddypress 1.9.2 and putting it in as a function in your code, and calling that instead of the Buddypress 2.0.1 version. Result was I saw a speed improvement on a database of 13302 users on my slow and ancient development server from about 23 minutes to about 3 minutes. So I was right, it did get much slower when Buddypress 2 came out. Pity.

    Plugin Author qstudio

    (@qlstudio)

    Thanks @cwjordan – I’ll try your sanitizing code shortly, did you base this on the code in the github version – this is a bit different from the code your first provided?

    As for the BP function issue, sounds like something that should be taken up with the BP development team, if the old function provides the same results, but quicker – they’re introduced problems which need addressing.

    Fancy opening a bug report on the BP trac?

    Q

    Yes, I based it on what was in the github version.

    Not sure I want to take it up with BP or not. I feel like they’ll just tell me no. I’ll think about it.

    Plugin Author qstudio

    (@qlstudio)

    Yeh, I know what you mean.. so, how about we just use the old function – is it pluggable, or is that a bad idea – it’s a bit late here?!

    Q

    get_all_for_user doesn’t look pluggable to me – it would have to have if ( ! function_exists( in it right? However it is also nice and simple. All I did to test was just copy the old version of the function onto the end of export-user-data.php like below and then called it instead of the buddypress one $bp_data = $this->get_all_for_user( $user->ID );:

    /**
             * BP_XProfile_ProfileData::get_all_for_user()
             *
             * Get all of the profile information for a specific user.
             */
            private static function get_all_for_user( $user_id ) {
                    global $wpdb, $bp;
    
                    $results      = $wpdb->get_results( $wpdb->prepare( "SELECT g.id as field_group_id, g.name as field_group_name, f.id as field_id, f.name as field_name, f.type as field_type, d.value as field_data, u.user_login, u.user_nicename, u.user_email FROM {$bp->profile->table_name_groups} g LEFT JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id INNER JOIN {$bp->profile->table_name_data} d ON f.id = d.field_id LEFT JOIN {$wpdb->users} u ON d.user_id = u.ID WHERE d.user_id = %d AND d.value != ''", $user_id ) );
                    $profile_data = array();
    
                    if ( !empty( $results ) ) {
                            $profile_data['user_login']    = $results[0]->user_login;
                            $profile_data['user_nicename'] = $results[0]->user_nicename;
                            $profile_data['user_email']    = $results[0]->user_email;
    
                            foreach( (array) $results as $field ) {
                                    $profile_data[$field->field_name] = array(
                                            'field_group_id'   => $field->field_group_id,
                                            'field_group_name' => $field->field_group_name,
                                            'field_id'         => $field->field_id,
                                            'field_type'       => $field->field_type,
                                            'field_data'       => $field->field_data
                                    );
                            }
                    }
    
                    return $profile_data;
            }
    Plugin Author qstudio

    (@qlstudio)

    @cwjordan – I’ll have a bit of time tomorrow and I’ll compare this method to the version in the latest BP.. and see what else we might lose by going backwards.. if nothing special, I think we’re fine to go ahead and do this – if the performance changes show it’s worthwhile.

    Cheers

    Q

    Thanks. I did also mention this on the buddypress “requests & feedback” forum. We’ll see if anything comes of that: https://buddypress.org/support/topic/request-for-way-to-disable-caching-of-xprofile-data-for-get_all_for_user/

    Plugin Author qstudio

    (@qlstudio)

    @cwjordan – this is looking good in my initial testing.

    I’ve added the new sanitizing loop and pulled in the get_all_for_user method from BP and call this statically.

    I’ve pushed all the changes to github again – I think with a bit more testing on a large database of users, we might be ready for the next release.

    Q

    Q, Works fine when I try it, nice work!

    Plugin Author qstudio

    (@qlstudio)

    Good news, this was released last week and seems to be working well for users – as there are no new forum topics requesting help.

    Thanks for your help ??

    Q

    Plugin Author qstudio

    (@qlstudio)

    @cwjordan – I’ve got a question, how could I contact you?

    See here for reference: https://wordpress.stackexchange.com/questions/167111/wp-user-query-and-non-unique-usermeta-data

    Cheers

    Q

Viewing 11 replies - 16 through 26 (of 26 total)
  • The topic ‘HowTo: preselected meta keys for export’ is closed to new replies.