0

I'm trying to add a tab and form to a BuddyPress/BuddyBoss group. I'm able to add the tab, but the page just doesn't display. I get a 404, and the page logic is never run.

What's strange is this code works for another tab.

I've tried turning the access to True. I've tried a variety of settings for the path. I'm running out of ideas.

<?php
add_action('bp_init', 'setup_group_edit_nav');
function setup_group_edit_nav() {
    global $bp;

    if(bp_is_active('groups') && !empty($bp->groups->current_group)) {
        $group_type = bp_groups_get_group_type($bp->groups->current_group->id);

        //Make changes only to the group.
        if(cannxi_is_comp($group_type)) {
            //add the Edit Company to the manage tab.
            //$group_link = group_base_slug($bp) .  '/admin/';
            $user_access = $bp->groups->current_group->user_has_access && can_change_comp_settings();

            $current_group = groups_get_current_group();
            $admin_link = trailingslashit(bp_get_group_permalink($current_group).'admin');
            //error_log('Amin_link'.$admin_link);
            error_log(print_r($user_access, TRUE));
            //$user_access = $bp->groups->current_group->user_has_access;
            //var_dump($admin_link);
            bp_core_new_subnav_item(
                array(
                    'name'            => __('Company Details', 'cannxi'),
                    'slug'            => 'group-company-edit',
                    'default_subnav_slug' => 'group-company-edit',
                    'parent_url'      => $admin_link,
                    'parent_slug'     => $bp->groups->current_group->slug . '_manage',
                    'screen_function' => 'cannxi_group_show_manage_comp_details_tab',
                    'position'        => 1,
                    'user_has_access' => $user_access,
                )
            );
        }
    }
}



/**
 *
 */
function cannxi_group_manage_comp_title() {
    echo 'Company Details';
}


/**
 * Load the Jobs tab template for the Groups.
 */
function cannxi_group_manage_comp_content() {
    error_log(__FUNCTION__);
    echo "test";
    bp_core_load_template('groups/groups-manage-companies-details');
    //bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'groups/groups-manage-companies-details' ) );
    buddyforms_ge_locate_template('groups/groups-manage-companies-details.php');

    $attached_post_id = groups_get_groupmeta(bp_get_current_group_id(), 'group_post_id');
//$attached_post_type  = groups_get_groupmeta( bp_get_current_group_id(), 'group_type' );
//$attached_form_slug  = get_post_meta( $attached_post_id, '_bf_form_slug', true );
//$group_permalink  = bp_get_group_permalink( groups_get_current_group() ) . bp_current_action();
    ?>
    <div id="bf_aptg2" class="bf_main_aptg">
        <?php
        $args = array(
            'post_type' => 'company_listings',
            'post_id'   => $attached_post_id,
            'form_slug' => 'company_website',
        );

        echo buddyforms_create_edit_form($args);
        ?>
    </div>
    <?php
}


function can_change_comp_settings() {

    $buddyforms_aptg = groups_get_groupmeta(bp_get_current_group_id(), 'buddyforms-aptg');
    if(isset($buddyforms_aptg['can-create'])) {
        switch($buddyforms_aptg['can-create']) {
            case 'admin' :
                if(groups_is_user_admin(bp_loggedin_user_id(), bp_get_current_group_id())) {
                    return TRUE;
                }
                break;
            case 'mod' :
                if(
                    groups_is_user_mod(bp_loggedin_user_id(), bp_get_current_group_id()) ||
                    groups_is_user_admin(bp_loggedin_user_id(), bp_get_current_group_id())) {
                    return TRUE;
                }
                break;
            case 'member' :
            default :
                if(groups_is_user_member(bp_loggedin_user_id(), bp_get_current_group_id())) {
                    return TRUE;
                }
                break;
        }
    }
    return FALSE;
}
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.