Skip to:
Content
Pages
Categories
Search
Top
Bottom

Filter site_url() to always point to main blog/site (Help request)


  • Mike Pratt
    Participant

    @mikepratt

    Use Case: I do not allow blog creation by users on one of my BP sites. I DO, however, make use of several blogs for other purposes on the site. For example, blog ID #2 is an “announcements” blog. Users don’t know or care that they are actually looking at an actually different blog than the main one. It works, for now.

    Problem: site_url (used liberally throughout bp-default) returns mysite.com on the main blog and mysite.com/announcements on blog 2. So profiles now become mysite.com/announcements/members/username. It’s a mess and templates and sidebars are inconsistent.

    I have no need for the mysite.com/announcements url and would prefer all references to site_url() to return the url of the main site/blog #1 (whatever it takes). site_url() has a filter and maybe it’s as simple as intercepting the problem there but I could use some suggestions by those who understand now what I am trying to do. Addressing this will solve a ton of header, url and other problems.

    Many Thanks

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

  • Brajesh Singh
    Participant

    @sbrajesh

    hi Mike
    If I understand your situation correctly, here is a quick and simple fix
    /* site url uses get_option (siteurl), just filter on the option*/
    add_filter(“option_siteurl”,”my_site_url”);
    function my_site_url(){
    return get_blog_option(1,’home’);/* return the url of the main site*/
    }

    btw, profile will only point to yoursite.com/subsite/members/usersname if the BP_ENABLE_MULTIBLOG is defined somewhere, otherwise user profile will alwys point to the main site.
    The trick above, makes the heder urls(like members/groups/sitename) etc to link back to the main site not the sub blog. Hope that helps.


    Mike Pratt
    Participant

    @mikepratt

    beautiful, Brajesh. Now I just need to figure out how to remove all the sub-sites when

    bp_loggedin_user_domain() & bp_displayed_user_domain() are called

    ($bp->loggedin_user->domain is where that $value is set) for example


    Brajesh Singh
    Participant

    @sbrajesh

    hi Mike
    For setting the user domain, bp calls following function
    bp_core_get_user_domain() and It has a filter bp_core_get_user_domain, but I am little hesitant to change something with this, as It may affect the other behaviors. Please check that function and bp_core_setup_globals() for more.

    As far as I think, please check again and make sure you have not enabled the Multiblog mode(sometimes we may do it for testing an forget,specially my own experience), the subdomains in the userdomain is mostly a result of enabling multiblog mode.
    Hope that helps :)


    Mike Pratt
    Participant

    @mikepratt

    Brajesh – I will have no choice but to make adjustments to those functions. I have enabled multi blog mode because I have multiple blogs! I just control them all, that’s all. Thank you for all your help.


    Mike Pratt
    Participant

    @mikepratt

    @sbrajesh the following function suits purpose #2 just fine. I think the var $user_url which seems tied to the main site url is safe enough (untested for sure). fingers crossed.

    function bn_loggedin_user_domain() {
    global $bp;
    return $bp->loggedin_user->userdata->user_url;
    }
    add_filter(‘bp_loggedin_user_domain’,’bn_loggedin_user_domain’);


    Mike Pratt
    Participant

    @mikepratt

    Well. Nowhere near finished. All the author links on the sublobgs have the sub blog in the link eg domain.com/subblog/member/username. The darn things are everywhere!

    What i really need is a way to universally remove sub blog references from all user links.

    I know I view things differently but the way I see it, you are a member of the site, not the blog. Sure you may have a role in that blog eg author, but your member profile should not point to a slew of different urls just because you happen to be viewing a blog that is not the main site. In practice, I see that the data remains the same so, in the end, we’re really talking about messy urls but I figured why confuse users


    Brajesh Singh
    Participant

    @sbrajesh

    hi Mike
    The problem with the author url is, it is generated by wordpress. Let me take a look at it, there must be someway to get over that too.
    The problem with the unified url is a trouble as wordpress uses 3/4 options settings for that (home,wpurl,siteurl,url), an interesting thing will be if we just cap all of them.

    Let me take a look at the author url, will be posting again soon :)


    Brajesh Singh
    Participant

    @sbrajesh

    ooh, As I guessed, author url uses get_option(‘home’)
    So, we will not need any extra code, just adding another filter will do the trick using our very first function.
    `add_filter(“option_home”,”my_site_url”);

    we are using the old function, just adding to work it for the home url too.
    and I hope your filtering user domain is not causing any issue.


    Mike Pratt
    Participant

    @mikepratt

    Actually, the author url is intercepted here -> bp_core_get_userlink( $post->post_author ) in the bp-defualt templates. I am going to try and go high enough in the url creation process to catch everything but only as high as I need to go so as not to create other problems


    stwc
    Participant

    @stwc

    [Sorry no help to offer, but I’m just commenting in this thread so I can find it later a little more easily, since we don’t have forum thread favoriting any more]


    Brajesh Singh
    Participant

    @sbrajesh

    @stwc :)
    @mikepratt
    In that case, you will have to cap on “bp_core_get_root_domain”, as this is what used by the userlink.

    `
    add_filter(“bp_core_get_root_domain”,”my_site_url”);//just removing the effect of BP_ENABLE_MULTIBLOG on the urls
    `
    This will do things like change all the references of sub blog used by buddypress to point to main site not the sub blog. I hope it helps :)


    Mike Pratt
    Participant

    @mikepratt

    Update. After lengthy chats yesterday with @boonegorges and @jeffsayre I will do the following

    Find all of the functions I need to filter in order to force all member related URL creation to the domain of the main blog/site (Suits my use case) We will then see if that can be consolidated with a patch to make the effort easier. Will try @sbrajesh ‘s suggestion today.

    More later.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Filter site_url() to always point to main blog/site (Help request)’ is closed to new replies.
Skip to toolbar