Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_is_user_profile is not working in a functions.php file

  • Avatar of m1000
    m1000
    Participant

    @m1000

    Hi,

    I would like to use 1 function when an user is on its profile page only, so I used bp_is_user_profile in the functions.php but it’s not working. bp_is_user_profile is working on the sidebar.php but I would like to use it in the functions.php file.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of shanebpdev
    shanebp
    Participant

    @shanebp

    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

    Avatar of m1000
    m1000
    Participant

    @m1000

    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

    Avatar of m1000
    m1000
    Participant

    @m1000

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

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    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.

    Avatar of m1000
    m1000
    Participant

    @m1000

    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

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    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)

You must be logged in to reply to this topic.