Skip to:
Content

BuddyPress.org

Changeset 1681 for trunk/bp-xprofile.php


Ignore:
Timestamp:
08/22/2009 07:21:36 PM (17 years ago)
Author:
apeatling
Message:

Re-added stripslashes filter to xprofile edit values and moved syncing function from filters file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile.php

    r1672 r1681  
    979979}
    980980
     981/**
     982 * xprofile_avatar_upload_dir()
     983 *
     984 * Setup the avatar upload directory for a user.
     985 *
     986 * @package BuddyPress Core
     987 * @param $directory The root directory name
     988 * @param $user_id The user ID.
     989 * @return array() containing the path and URL plus some other settings.
     990 */
    981991function xprofile_avatar_upload_dir( $directory = false, $user_id = false ) {
    982992        global $bp;
    … …  
    984994        if ( !$user_id )
    985995                $user_id = $bp->displayed_user->id;
     996       
     997        if ( !$directory )
     998                $directory = 'avatars';
    986999
    9871000        $path  = get_blog_option( BP_ROOT_BLOG, 'upload_path' );
    … …  
    9941007                @wp_mkdir_p( $newdir );
    9951008
    996         $newurl = WP_CONTENT_URL . '/blogs.dir/' . BP_ROOT_BLOG . '/files/avatars/' . $user_id;
     1009        $newurl = WP_CONTENT_URL . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $directory . '/' . $user_id;
    9971010        $newburl = $newurl;
    9981011        $newsubdir = '/avatars/' . $user_id;
    … …  
    10001013        return apply_filters( 'xprofile_avatar_upload_dir', array( 'path' => $newdir, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
    10011014}
     1015
     1016/**
     1017 * xprofile_sync_wp_profile()
     1018 *
     1019 * Syncs Xprofile data to the standard built in WordPress profile data.
     1020 *
     1021 * @package BuddyPress Core
     1022 */
     1023function xprofile_sync_wp_profile() {
     1024        global $bp, $wpdb;
     1025       
     1026        if ( (int)get_site_option( 'bp-disable-profile-sync' ) )
     1027                return true;
     1028       
     1029        $fullname = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $bp->loggedin_user->id );
     1030        $space = strpos( $fullname, ' ' );
     1031       
     1032        if ( false === $space ) {
     1033                $firstname = $fullname;
     1034                $lastname = '';
     1035        } else {
     1036                $firstname = substr( $fullname, 0, $space );
     1037                $lastname = trim( substr( $fullname, $space, strlen($fullname) ) );             
     1038        }
     1039       
     1040        update_usermeta( $bp->loggedin_user->id, 'nickname', $fullname );
     1041        update_usermeta( $bp->loggedin_user->id, 'first_name', $firstname );
     1042        update_usermeta( $bp->loggedin_user->id, 'last_name', $lastname );
     1043
     1044        $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $fullname, $bp->loggedin_user->id ) );
     1045        $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_url = %s WHERE ID = %d", bp_core_get_user_domain( $bp->loggedin_user->id ), $bp->loggedin_user->id ) );
     1046}
     1047add_action( 'xprofile_updated_profile', 'xprofile_sync_wp_profile' );
    10021048
    10031049
Note: See TracChangeset for help on using the changeset viewer.