Skip to:
Content
Pages
Categories
Search
Top
Bottom

Registration with Profile Photo


  • metalhead
    Participant

    @aaronthomas1979

    Hello Buddypress buds!

    A lot of people have been talking over the past couple of years about “how to require a profile photo upon registration. And I know it’s a risky thing to do, but many of us are willing to take that risk.

    There are a handful of plugins that try to assist with this procedure, but some fail, and some are only partially successful. The best solution that I’ve found is Xprofile Custom Fields. With this plugin, and a lot of help from the author, I’ve managed to get profile photos to be required in the registration process. However, the issue I’m having is that the users are unable to effectively change their profile photo by using the options in the Buddypress “Profile” section/menu. The user can still click “Change Profile Photo,” and it will accept their upload, but the old photo remains in the member directory & in the user’s profile itself.

    I think there must be a miscommunication occurring due to this new way of gathering the user’s original profile photo. It seems like some code, pertaining to the Buddypress “Change Profile Photo” function needs to be tweaked, but I can not pinpoint the function, which would be the first step towards fixing this issue.

    To demonstrate how I’m requiring the profile photo upload in the registration, here is the function I’ve added to my theme’s functions.php file:

    add_filter( 'bp_core_fetch_avatar', 'my_custom_avatar', 10, 2 );
    function my_custom_avatar( $avatar, $params ) {
        if ( 'user' === $params['object'] ) {
            // Get the src of the original avatar.
            $array = array();
            preg_match( '/src="([^\"]*)"/i', $avatar, $array );
            if ( count( $array ) > 1 ) {
                $old_url_avatar = $array[1];
                // Get the new url of image.
                $uploads = wp_upload_dir();
                $img = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( 5218, $params['item_id'] ) );
                if ( ! empty( $img ) ) {
                    $new_url_avatar = $uploads['baseurl'] . $img;
    
                    // Replace the old src with the new url.
                    $avatar = str_replace( $old_url_avatar, $new_url_avatar, $avatar );
                }
            }
        }
    
        // Return the avatar.
        return $avatar;
    }

    I’d like to mention that I have asked the plugin author about this, but my message on that plugin’s support forum has been deleted twice, making me think I should give the man a break.

    Here are some specifications of my site:

    The site can be reached here.

    It’s running on WordPress v4.6.1, Buddypress v2.7.0, & using BuddyPress Xprofile Custom Fields Type v2.6

    “5218” is the field ID for the “Upload Image” field.

    Thanks and sorry if I posted in an inappropriate forum, I think I chose the right one.

  • You must be logged in to reply to this topic.
Skip to toolbar