Skip to:
Content
Pages
Categories
Search
Top
Bottom

BuddyPress bp_is_my_profile() method not working in custom PHP file


  • ygagnon2016
    Participant

    @ygagnon2016

    I’m working on a custom WordPress site that uses a BuddyBoss child theme that I’ve been heavily modifying over the past few months. Note that I’m using WordPress multisite version 4.1.8, and Buddypress version 2.9.0.

    I’m currently working on a custom PHP template that’s using JQuery’s Colorbox plugin to load a PHP file in modal window via ajax. The popup that contains the PHP file is being displayed without any issues .. and the native WordPress functions within it are working as expected. But the one BuddyPress method that I’m trying to use is not working .. namely “bp_is_my_profile()”.

    Here is my PHP code:

    <?php 
    require("../../../../../../wp-blog-header.php");
    require('../../../../../../wp-load.php'); 
    
    if ( is_user_logged_in() ) { // THIS METHOD IS WORKING
    
      if ( bp_is_my_profile() ) { // THIS METHOD IS NOT WORKING
    
    		echo '<p>This is your Buddypress profile page.</p>';
    
      } else {
    		echo '<p>This is NOT your Buddypress profile page.</p>';
      }  
    
    }  else {  
    		echo '<p>You are not authorized to access this resource.</p>';  
    }
    ?>

    What do I need to add to this PHP file in order for the “bp_is_my_profile()” method to work correctly? I’ve already verified that this method DOES in fact work when I call it within a normal PHP template file that’s part of my child theme. I just can’t seem to get it to work when calling it from any other PHP file .. despite the fact that I’m loading both the “wp-blog-header.php” & “wp-load.php” files.

    Thanks,
    – Yvan

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

  • shanebp
    Moderator

    @shanebp

    Try passing the value of bp_is_my_profile() as a var in your ajax call.


    ygagnon2016
    Participant

    @ygagnon2016

    Although that would definitely work (and I have considered using this approach) … that would definitely be a security breach, as the PHP script could simply be linked to directly by any logged in WordPress user. So that obviously wouldn’t work in my situation.

    Any other suggestions?
    – Yvan


    shanebp
    Moderator

    @shanebp

    Good point.

    Rather than put the conditionals in the php for the modal window, try calling a function from the php for the modal window.


    shanebp
    Moderator

    @shanebp

    If that does not work, try using bp_is_my_profile() in the php for the ajax call.
    And then load the appropriate template in the modal.


    ygagnon2016
    Participant

    @ygagnon2016

    I like your idea about calling a function from the php for the modal window.

    Just FYI .. this is what I have set up for colorbox (which isn’t a real ajax call, you’ll see):

    echo '<a class="ajax cboxElement launch-dashboard" href="' . get_stylesheet_directory_uri() . '/buddypress/members/single/dashboard.php?username=' . $row->username . '" title="Dashboard">Launch Dashboard</a>';

    If you aren’t familiar with how colorbox works … note that the modal window is being enabled by simply adding the “ajax” class to the link … similar to how a lightbox popup works.

    Ideally .. it’d be great if I didn’t have to call these 2 lines in my dashboard.php file either:

    require("../../../../../../wp-blog-header.php");
    require('../../../../../../wp-load.php'); 

    It’s my understanding that this is a terrible approach anyways .. since the WordPress engine is supposed to be already loaded in the background (making it redundant).

    So how would I implement something like what you’ve suggested? Could you show me an example, maybe? I’m assuming that if I don’t load the WordPress engine in my dashboard.php file, that I wouldn’t be able to call a function that’s been added to my functions.php file, right?

    Here’s a dumb question. Should I maybe just place my dashboard.php file in a different location within my child theme directory structure, perhaps? I ask because I’m starting to think that I might need to treat this as a normal WordPress template file .. instead of a standalone PHP script. Any thoughts?


    shanebp
    Moderator

    @shanebp

    I would try the WP template file approach.
    I haven’t used colorbox for modals.
    Why not do your bp_is_my_profile check before your echo and then use a conditional to load the appropriate template? Meaning you have two templates.
    I cannot provide any examples or more info re this issue.

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