Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_is_user_profile is not working in a functions.php file

Viewing 6 replies - 1 through 6 (of 6 total)
  • @shanebp

    Moderator

    bp_is_user_profile
    returns true / false as to whether the current component is ‘profile’

    bp_is_user()
    returns true / false as to whether you are on a profile page

    bp_is_my_profile()
    returns true / false as to whether the logged in user is looking at their own profile page

    @m1000

    Participant

    That’s right, it’s not working when used in the functions.php

    `if ( bp_is_my_profile() == 1 )
    {

    EXECUTE CODE

    } else {

    DO NOT EXECUTE CODE

    }`

    It always EXECUTE CODE, please check full code – http://pastebin.com/Ku2LgwTz

    @m1000

    Participant

    Weird, I posted yesterday but forum says this topic is 4 days old.

    @hnla

    Participant

    Functions.php will load and run before bp has a chance to esatblish what page is being shown those conditional functions ought to always return ‘false’ from that point, you can try hooking into an earlier point perhaps or if you are writing a function to be called on a page ensure your checks are carried out in the function not outside it.

    As always asking a tech question demonstrate the code you are working with and what you need to achieve then someone can suggest the best approach.

    @m1000

    Participant

    you can try hooking into an earlier point

    Unfortunately it doesn’t work.

    if you are writing a function to be called on a page ensure your checks are carried out in the function not outside it.

    I want to remove bp_core_set_avatar_constants action and use my own but following code doesn’t work outside the functions.php of theme:

    remove_action( ‘bp_init’, ‘bp_core_set_avatar_constants’, 3 );

    I think it’s a big limitation of BP if I can’t use conditional tags in the functions.php

    @hnla

    Participant

    this may be utterly unhelpful but can you not set or define the constants rather than remove all those avatar constants?

    e.g as long as you run a earlier priority you can define the constants before BP sets them and checking if a constant is defined but running late enough in functions.php that bp_is_my_profile() is set.

    
    function user_profile(){
      if( bp_is_user_profile() ) {
       define( BP_AVATAR_THUMB_WIDTH, '130');
      }
    }
    add_action('bp_init', 'user_profile', 2);
    

    But I might be barking mad!?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘bp_is_user_profile is not working in a functions.php file’ is closed to new replies.
Skip to toolbar