Skip to:

[Resolved] php conditionals based on group visibility/type?

  • dannyjimmy



    I’m an UBER NOOB to php, and am trying to do something like this:

    `<?php if (bp_this_group_is_public_true_or_false() ) {
    some facebook sharing buttons
    } ?>`

    The goal is to put FB share buttons into the replies within PUBLIC groups’ topics, but not private.

    I’ve looked into
    and others, but none seem to be able to be used in a conditional. They tend to just print the status out onto the page even when I’ve got them nested in the conditional’s ( )’s.

    Literally my first PHP project, working hard to understand. Thanks for patience.

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

  • dannyjimmy


    Also I’ve tried
    `status == “public”) {
    some facebook sharing buttons
    } ?>`
    and that doesn’t work either.

    With that, I just keep getting nothing outputted.

    Roger Coathup


    Logically bp_get_group_is_public() is the function you want to use —

    That said, I can’t find anywhere in the core code where is_public is getting set, or getting used in the default theme. @djpaul – is this a set of functions that should be stripped out – they appear unused and not working.

    Instead, the default template makes use of bp_get_group_type(), which in turn uses the $group->status attribute (as you’ve tried). In your case, are you sure you’ve setup your $group variable correctly?



    they appear unused and not working.

    right. One way they’re not working is that they don’t even report the right info. I don’t recall which it was, but I ran one of those functions, and it was printing Private in a public group.

    I’m not sure what you mean “are you sure you’ve setup your $group variable correctly?”. In my thinking, BuddyPress sets it up, not me; I’m just trying to reference it. I copied that $group->status setup out of the definition for bp_get_group_type() in bp-groups-template.php.

    I’ll give a whirl to the `bp_get_group_type()`, since that demonstrably at least produces the correct group visibility level; my trick will be to use its output in a conditional.

    Ok, so `bp_group_type` is what prints text to the page, `bp_get_group_type` seems to summon the text as a returned value (which bp_group_type() uses for its printing)


    `<?php if (bp_get_group_type()== "Public Group")
    print “foo”
    <?php if (bp_get_group_type()== "Private Group")
    print “bar”

    On a private group, I saw foo outputted and no bar. So it works.

    It feels less than elegant. It would be more elegant to just use the variables that bp_get_group_type() calls. But for now, it works.

    Thanks, @RogerCoathup, for the guidance :-)



    My final code, usable for any who desire:


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] php conditionals based on group visibility/type?’ is closed to new replies.
Skip to toolbar