Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

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

  • Garrett Hyder
    Participant

    @garrett-eclipse

    I assume you’re talking about the group listing when referring to ‘clicking the group’. In that case I believe you’d want to customize the groups/groups-loop.php template by copying it into your own theme and conditionally remove the links if the current user isn’t a member.
    Here’s docs on the template hierarchy in Buddypress – https://codex.buddypress.org/themes/theme-compatibility-1-7/template-hierarchy/

    That should allow you to control that list of groups and suppress links depending on role.
    As to the request access form if for some off chance they make it to that screen, if you want to suppress the form with a blocking message when they’re a member you can use the same template replacement concept to replace groups/single/home.php

    Or potentially this plugin by @imath may be more appropriate as you could just make the groups private/hidden;
    https://github.com/imath/altctrl-public-group


    Garrett Hyder
    Participant

    @garrett-eclipse

    @welshlamb10 I believe that should be possible.

    
    // Remove Join/Leave Button
    function bp_remove_group_join_button( $button, $group ) {
        $current_user = wp_get_current_user();
        if ( in_array( 'member', (array) $current_user->roles ) ) {
            return '';
        }
        return $button;
    }
    add_filter( 'bp_get_group_join_button', 'bp_remove_group_join_button', 10, 2);
    

    The filter gives access to the $button and $group, then you can use the current user to determine if $button should be returned or an empty string.

    The above code will check the current user to see if they have the ‘member’ role. If they do the button is suppressed otherwise the button will be there.

    Hope that helps


    Garrett Hyder
    Participant

    @garrett-eclipse

    Glad it’s still working.

    Looking at the original Trac ticket there is now a bp_core_get_directory_page_id() method for this which takes the $component as a param or defaults to bp_current_component().

    Just wanted to follow-up for others looking to this as a solution… there’s now an official method which is probably more appropriate.

    Cheers


    Garrett Hyder
    Participant

    @garrett-eclipse

    In the end utilizing BP_Media_Extractor with wp_oembed_get and do_shortcode I was able to get this functional;

    
    $group_content = groups_get_groupmeta(bp_get_group_id(), 'bp_group_content_editor');
    
    if(!empty($group_content)) {
    	$bp_extractor = new BP_Media_Extractor;
    	$media = $bp_extractor->extract( $group_content, BP_Media_Extractor::ALL );
    	if ( ! empty( $media['embeds'] ) ) {
    		foreach ( $media['embeds'] as $embed ) {
    			$cachekey = '_oembed_response_' . md5( $embed['url'] );
    			$oembed = groups_get_groupmeta( bp_get_group_id(), $cachekey );
    			if ( '' === $oembed ) {
    				$oembed = wp_oembed_get($embed['url']);
    				groups_update_groupmeta( bp_get_group_id(), $cachekey, $oembed );
    			}
    			if ( $oembed ) {
    				$group_content = str_replace($embed['url'], $oembed, $group_content);
    			}
    		}
    	}
    	if ( ! empty( $media['shortcodes'] ) ) {
    		foreach ( $media['shortcodes'] as $shortcode ) {
    			$cachekey = '_shortcode_response_' . md5( $shortcode['original'] );
    			$shortcode_content = groups_get_groupmeta( bp_get_group_id(), $cachekey );
    			if ( '' === $shortcode_content ) {
    				$shortcode_content = do_shortcode($shortcode['original']);
    				groups_update_groupmeta( bp_get_group_id(), $cachekey, $shortcode_content );
    			}
    			if ( $shortcode_content ) {
    				$group_content = str_replace($shortcode['original'], $shortcode_content, $group_content);
    			}
    		}
    	}
        echo wpautop($group_content);
    }
    

    Garrett Hyder
    Participant

    @garrett-eclipse

    Came across this and tried @danbp’s solution with no avail until i realized bp_is_active should be looking for ‘groups’ as a string and with s. But in any case that check isn’t necessary as the filter will only be executed for groups so that check is redundant and the global group_template isn’t needed either.
    Here’s what I’ve employed with success.

    // Remove Join/Leave Button
    function bp_remove_group_join_button() {
        return '';
    }
    add_filter( 'bp_get_group_join_button', 'bp_remove_group_join_button');

    *I know old topic, but might as well provide the working function for future finders.


    Garrett Hyder
    Participant

    @garrett-eclipse

    Hi @fullmoonfriday,

    At the time I was able to just work around it as described by keeping the forum public but placing it into a Private Group and having the Groups Forum (parent) hidden.

    Anyway I’ve recently updating WP/BP/BBP and attempted to reproduce.
    When the forum is hidden it still doesn’t render anything which may be intended as it’s ‘hidden’.
    When the forum is private I am now getting the shortcode to render properly and in full. So it appears the issue where a private forum is embedded through shortcode and only renders the ‘No Topics’ message has been resolved.

    This is good in my case at least since I can now switch all my forums back to private.
    As to the hidden forum not rendering, I’m unsure if it should be displaying anything or not.

    So at the very least you can avoid hidden and stick to private groups. But if you require hidden as well will either need custom coding. Or you might want to open up a trac ticket to push the issue to bp-dev team.

    Cheers


    Garrett Hyder
    Participant

    @garrett-eclipse

    As I’ve suggested forget about changing functionality of private groups and instead focus on public groups and employing the alternate control public group plugin to lock public groups down to require membership requests so they act similar to Private Groups. And then you won’t need to reinvent the wheel concerning Private Group functionality.
    Basically look at your problem from another angle and focus on modifying Public Group functionality over Private Group functionality as you’ll have a much easier time with that approach.
    Cheers


    Garrett Hyder
    Participant

    @garrett-eclipse

    Hi @sprocketbuddy,

    As @imath notes in his video trying to get private groups to function ‘publicly’ is going to be quite difficult as it’s ingrained in the core.

    You’ll want to start with his plugin (https://github.com/imath/altctrl-public-group) and customize to your needs. As Public Groups by default have Group content and activity visible to any user by employing his plugin you’ll achieve the options you desire with introducing membership requests to the public group but still display it’s members, content, activity.

    Hope that helps get you started in the right direction. Try it out and let me know what roadblocks you hit and we can probably assist.

    Cheers


    Garrett Hyder
    Participant

    @garrett-eclipse

    Hi @sprocketbuddy,

    Take a look at this plugin by @imath;
    https://github.com/imath/altctrl-public-group

    I believe it goes along with your needs. He found rather than hacking/rewritting permission things for private groups that it was easier to utilize a public group and just lock it down with more controls.

    There’s a demo here;

    Cheers


    Garrett Hyder
    Participant

    @garrett-eclipse

    Hi @noobiestrikesagain,

    You’ll want to use the bp_is_my_profile check. As follows;
    if ( is_user_logged_in() && ! bp_is_my_profile() ) {

    Hope that helps,
    Cheers


    Garrett Hyder
    Participant

    @garrett-eclipse

    Posted Enhancement Request – https://buddypress.trac.wordpress.org/ticket/6575#ticket
    If you have any suggestions or changes @shanebp your input is appreciated.
    Thanks


    Garrett Hyder
    Participant

    @garrett-eclipse

    Thanks @shanebp,

    Sadly neither of these filters will allow me to modify the ‘(required)’ text itself which is what I’m looking for, I guess I’m a little off in my request encompassing the entire label text as you pointed out the field name is filterable it’s the required portion that is outside of it as you can see in the code snippet;

    <label for="<?php bp_the_profile_field_input_name(); ?>">
    	<?php bp_the_profile_field_name(); ?>
    	<?php if ( bp_get_the_profile_field_is_required() ) : ?>
    		<?php esc_html_e( '(required)', 'buddypress' ); ?>
    	<?php endif; ?>
    </label>

    And yes I realize I can replace it through the text-domain and a .po file, but I’d like to keep the (required) in the Buddypress Xprofile and target the inclusion of these fields specifically on the Woocommerce Checkout page where they’re included through the Buddypress for Woocommerce integration.

    I’ll open an enhancement request, thanks for pointing that out, and specify the targetting of the (required) portion of the label specifically.

    Appreciated,
    Cheers


    Garrett Hyder
    Participant

    @garrett-eclipse

    Answered my own question using the instanceof comparator and the class name of the field type object;
    if ($field->type_obj instanceof Bxcft_Field_Type_Email) {


    Garrett Hyder
    Participant

    @garrett-eclipse

    Hi @shanebp,

    Sorry for the confusion, I’ve created a bp_group_list_managers that’s a merge of bp_group_list_admins and bp_group_list_mods to provide a single consolidated listing.

    function bp_group_list_managers($group=false) {
        global $groups_template;
        if(empty($group)) {
            $group =& $groups_template->group;
        }
    
        // fetch group admins if 'populate_extras' flag is false
        if (empty($group->args['populate_extras']) || true) {
            $query = new BP_Group_Member_Query(array(
                'group_id'   => $group->id,
                'group_role' => 'admin',
                'type'       => 'alphabetical',
            ));
    
            if (!empty($query->results)) {
                $group->admins = $query->results;
            }
        }
    
        // fetch group mods if 'populate_extras' flag is false
        if (empty($group->args['populate_extras']) || true) {
            $query = new BP_Group_Member_Query(array(
                'group_id'   => $group->id,
                'group_role' => 'mod',
                'type'       => 'alphabetical',
            ));
    
            if (!empty($query->results)) {
                $group->mods = $query->results;
            }
        }
    
        $admins = (array)$group->admins;
        $mods = (array)$group->mods;
    
        usort($admins, 'bp_group_member_sort');
        usort($mods, 'bp_group_member_sort');
    
        $group->managers = array_merge($admins, $mods);
    
        if (!empty($group->managers)) { ?>
            <ul id="group-managers">
                <?php foreach((array)$group->managers as $manager) { ?>
                    <li>
                        <a href="<?php echo bp_core_get_user_domain($manager->user_id, $manager->user_nicename, $manager->user_login); ?>"><?php echo bp_core_fetch_avatar(array('item_id' => $manager->user_id, 'email' => $manager->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname($manager->user_id)))) ?></a>
                    </li>
                <?php } ?>
            </ul>
    <?php } else { ?>
        <span class="activity"><?php _e( 'No Managers', 'buddypress' ) ?></span>
    <?php }
    }

    As you can see I set the type here to alphabetical and was first confused why it did nothing then I realized the BP_Group_Member_Query’s were never even called as I guess populate_extras was set so not empty. This meant that the $group->admins and $group->mods came from the global $group_template->group which wasn’t ordered. I’m curious how to make that global $group_template->group admin/mod lists could be alphabetically ordered by default.

    For now I just amended my method to simply force the BP_Group_Member_Query’s to be used instead which has allowed for the alphabetical ordering.

    Hope that clears things up.

    Thanks


    Garrett Hyder
    Participant

    @garrett-eclipse

    Thanks @shanebp,

    I finally figured that the BP_Group_Member_Query as alphabetical was functioning properly what I’m wondering about now is if I can by default order the admins and mods listings on the $groups_template->group object in alphabetical order?

    Thanks


    Garrett Hyder
    Participant

    @garrett-eclipse

    O crap,

    scratch that I didn’t read the function properly, that was wrapped in a check for populate_extras

        if (empty($group->args['populate_extras'])) {

    So it never even executed and just used the $group from the global $groups_template->group which already had the admins/mods on it.

    So I guess my question is how can you control the order or sort the $group->admins and $group->mods

    Thanks


    Garrett Hyder
    Participant

    @garrett-eclipse

    Hi @henrywright & @danbp,
    For this case I didn’t utilize any coding, simply did a Dropdown field and plugged in all the values. I know not the best approach as it was all manual work but wanted to point out that may be a limit on the number of dropdown options that can be on a field possibly?
    If you have a better approach I’d be happy to hear it.
    Thanks


    Garrett Hyder
    Participant

    @garrett-eclipse

    Thanks @johnjamesjacoby, @danbp, @henrywright, greatly appreciated.


    Garrett Hyder
    Participant

    @garrett-eclipse

    Is there anyone out there? Would love some assistance or at least the knowledge I’m not alone.
    Thanks


    Garrett Hyder
    Participant

    @garrett-eclipse

    Hi @henrywright, this occurred on these forums buddypress.org/support


    Garrett Hyder
    Participant

    @garrett-eclipse


    Garrett Hyder
    Participant

    @garrett-eclipse

    Update – Found an issue with my code when you go to the second page of the Members Groups list it reverts to showing hidden, etc. This is due to the call being done with AJAX which is considered an admin so !is_admin is false. To correct this I’ve updated the if statement to check if DOING_AJAX:

    // Buddypress Filter Hidden Groups from Groups Loop
    function filter_hidden_groups_sql($sql) {
    	if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)){
            $sql_parts = explode('WHERE', $sql);
            $new_sql = $sql_parts[0] . "WHERE g.status != 'hidden' AND" . $sql_parts[1];
    	    return $new_sql;
    	} else {
    		return $sql;
    	}
    }

    Basically this allows the backend admin to list all groups but the front end hides the hidden ones.

    Cheers

Viewing 22 replies - 1 through 22 (of 22 total)
Skip to toolbar