Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help! Some members can’t upload avatars


  • scorpnetwork
    Participant

    @scorpnetwork

    Hello BP Community,

    for a unknown reason, some of my member profiles cant upload Avatars anymore.
    I tested it with my own (admin) Profile and it works. I switched to a regular subscriber test account and also used another inactive user account that I hijacked for this, but they cant upload avatars – anymore. My test account has an avatar + profile banner, which I set up when I started with BP. but now I cant change them.

    The displayed error message is the default / generic one “there was a problem bla bla, try again”.

    I checked the BP directorys inside wp-content and they all have chmod 755. I also made sure the owner of the directorys are correct. Then I enabled WP_DEBUG and made it write into a logfile while I try to upload a avatar. Sadly, all it writes into the log is this:
    [28-Jul-2017 07:22:26 UTC] PHP Notice: Undefined offset: 1 in /xxx/wp-includes/media.php on line 712

    I also checked if the BP settings are correct and users are (still) allowed to upload images, which is done correctly.

    So I am in need of you BP pros now. Can somebody help me with this problem? I am thankful for any clues on how to solve this problem, since I wanted to make some UX improvements that dont make any sense if users cant upload their own avatars anaymore. 🙁

Viewing 4 replies - 1 through 4 (of 4 total)

  • scorpnetwork
    Participant

    @scorpnetwork

    I now found this thread which seems to be the source of my problem.
    https://buddypress.org/support/topic/only-administrator-can-change-avatar/

    Trying it out now. Sadly its closed and even sadder, there is no “solution”.

    If this thread is correct, then the problem occurs because of a redirect that forbids “regular users” to enter WP Admin.

    Does anybody have a solution for this?


    scorpnetwork
    Participant

    @scorpnetwork

    Ok, solved it on my own.

    Like almost everybody else on this forum and on other blogs I found, most people are using the same function to block specific users to access WP admin and redirect them to the frontpage f.e..

    As stated above, the problem lies within the redirect. As far as I understood its because the admin_init hook is getting fired when admin-ajax.php gets loaded, which of course happens when you try to upload an avatar, which happens via AJAX by default.

    So the solution is pretty simple – just check if the current request is trying to get admin-ajax.php and if not, do your redirect.

    Maybe this post will help somebody with the same problem. If somebody has a smoother approach to this, ill be glad to know. 🙂

    /// Block admin access
    function psinside_no_admin_access(){
        $redirect = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : home_url( '/' );
        global $current_user;
        $user_roles = $current_user->roles;
        $user_role = array_shift($user_roles);
        if(
    		($user_role != 'administrator' && $user_role != 'editor')
    		&&
    		($_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php')
    	){
            exit( wp_redirect( $redirect ) );
        }
    }
    add_action( 'admin_init', 'psinside_no_admin_access', 100 );

    shanebp
    Moderator

    @shanebp

    You could replace this: ($_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php')

    With this: ! wp_doing_ajax()

    wp_doing_ajax()


    scorpnetwork
    Participant

    @scorpnetwork

    Awesome, that makes it even better! Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar