Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_core_avatar_save action hook missing?

  • @jd55

    Participant

    I see in the codex that there is supposed to be a hook called ‘bp_core_avatar_save’ in bp-core/bp-core-avatars.php. I have looked for this hook and it isn’t there. I need a hook for a project I’m working on that fires when a group avatar is uploaded. There doesn’t appear to be any such hook in BuddyPress 1.6.4. Will this hook be coming back? Why was it removed?

Viewing 7 replies - 1 through 7 (of 7 total)
  • @djpaul

    Keymaster

    Looks like it was removed in BP 1.2, about three years ago. Not sure why.

    @jd55

    Participant

    Hmmm… Well, there is currently no way to hook into a successful group avatar upload. At least none that I can see.

    @shanebp

    Moderator

    Take a look at
    function bp_core_avatar_handle_upload(…)
    in bp-core-avatars.php
    and use the apply_filters hook near the top.

    But that is pre-upload, so may not be useful to you.
    Although you could over-ride the whole function – yikes.

    @jd55

    Participant

    Yes, I thought of that, but there’s no way to know whether the upload was successful, is there?

    @shanebp

    Moderator

    Well, you could over-ride the whole function – yikes.

    @jd55

    Participant

    I thought of that. But I was hoping for a solution that would be more forward-compatible. In my opinion there really should be a hook.

    I was thinking of overriding the function, but calling it within the overriding function. That seems sort of convoluted, though. And I’d have to find a way to keep it from looping. (I was thinking I could set a global and then check its value to see if this is the first or second call…)

    @jd55

    Participant

    For anyone else out there who might be interested, here is how I solved the issue.

    I overrode `bp_core_avatar_handle_upload` with the following function. It calls bp_core_avatar_handle_upload within it, but avoids an infinite loop by setting and checking the value of a global variable.

    `global $my_bp_group_avatar_upload;
    function my_bp_group_avatar_upload( $upload, $file, $upload_dir_filter )
    {
    // Global.
    global $my_bp_group_avatar_upload;

    // Check upload filter.
    if ( $upload_dir_filter != ‘groups_avatar_upload_dir’ )
    return;

    // Check if this is the second call.
    if ( $my_bp_group_avatar_upload !== 2 )
    {
    // We are being called for the first time!

    // We are about to call the second time.
    $my_bp_group_avatar_upload = 2;

    // Call the function.
    // We’re calling ourselves too, but this time the global equals 2, so we are now in the else statement.
    if ( bp_core_avatar_handle_upload( $file, $upload_dir_filter ) ) {
    // Do stuff here, the upload was a success.
    }

    // We’ve executed the function. We can bail out of the original function run.
    return FALSE;
    } else {
    // We have been called a second time, so set this to something other than 2.
    $my_bp_group_avatar_upload = 0;

    // We want to continue with the execution.
    return TRUE;
    }
    }
    add_filter( ‘bp_core_pre_avatar_handle_upload’, ‘my_bp_group_avatar_upload’, 10, 3 );`

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘bp_core_avatar_save action hook missing?’ is closed to new replies.
Skip to toolbar