BuddyDev

Search

[Resolved] X-Profile Fields in BuddyPress Multi Network

  • Participant
    Level: Initiated
    Posts: 6
    Jason on #9563

    Hi,

    I am developing a site around the BuddyPress Multi Network plugin and I would like the x-profile fields to be shared by all networks. The activity, groups, messages and other features are great to be segmented, but I would like for the x-profile fields to be universal so my users don’t have to re-enter them for each different site.

  • Keymaster
    (BuddyDev Team)
    Posts: 22211
    Brajesh Singh on #9565

    Hi Jason,
    Welcome to BuddyDev.

    Please put this code in your bp-custom.php

    
    
    /**
     * Filter profile tables to use main site's tables.
     * 
     * @param $tables
     *
     * @return array
     */
    function buddydev_global_profile_tables( $tables ) {
    	global $wpdb;
    
    	$prefix = $wpdb->base_prefix;
    
    	// overwrite names
    	$tables = array(
    		'table_name_data'   => $prefix . 'bp_xprofile_data',
    		'table_name_groups' => $prefix . 'bp_xprofile_groups',
    		'table_name_fields' => $prefix . 'bp_xprofile_fields',
    		'table_name_meta'   => $prefix . 'bp_xprofile_meta',
    	);
    
    	return $tables;
    }
    add_filter( 'bp_xprofile_global_tables', 'buddydev_global_profile_tables');
    
    /**
     * Filter meta table to use the main site's tables
     *
     * @param array $tables
     *
     * @return array
     */
    function buddydev_gloabl_profile_meta_tables( $tables ) {
    	global $wpdb;
    
    	$prefix = $wpdb->base_prefix;
    
    	$tables = array(
    		'xprofile_group' => $prefix . 'bp_xprofile_meta',
    		'xprofile_field' => $prefix . 'bp_xprofile_meta',
    		'xprofile_data'  => $prefix . 'bp_xprofile_meta',
    	);
    
    	return $tables;
    }
    add_filter( 'bp_xprofile_meta_tables', 'buddydev_gloabl_profile_meta_tables' );
    
    

    We are overriding the table names to use it from the main sites.

    Hope that helps.

    • This reply was modified 5 years, 5 months ago by Brajesh Singh. Reason: fixing the name used in filter
  • Keymaster
    (BuddyDev Team)
    Posts: 22211
    Brajesh Singh on #9713

    Hi Jason,
    Can you please confirm if it worked for you or not?

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 6
    Jason on #9714

    Hi Brajesh,

    I missed the response. I’ll test it today and get back with you. Thanks for the info!

    ~jason

  • Participant
    Level: Initiated
    Posts: 6
    Jason on #9718

    Hi Brajesh,

    It works well. There was a small typo:

    add_filter( ‘bp_xprofile_global_tables’, ‘buddydev_filter_profile_tables’);

    Should be: add_filter( ‘bp_xprofile_global_tables’, ‘buddydev_global_profile_tables’);

    What about avatar images and cover images. They currently write to the uploads folder of each site independently. Is there any way to write them to the main site only so that they can be used on any site?

    Thanks!
    ~jason

  • Keymaster
    (BuddyDev Team)
    Posts: 22211
    Brajesh Singh on #9735

    Hi Jason,
    Thank you.
    I have updated the code with the correct function name. I am sorry about that goof up. I should have tested the code before posting.

    For avatars etc, Please open a new topic, I guess, we will need to tell BuddyPress to treat them as the main sites.

  • Participant
    Level: Initiated
    Posts: 6
    Jason on #9737

    Will do.

    Thank you!

The topic ‘ [Resolved] X-Profile Fields in BuddyPress Multi Network’ is closed to new replies.

This topic is: resolved