Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylian committed Nov 25, 2015
1 parent 21f5e92 commit 007125a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# buddypress_group_taxonomy
A simple WordPress plugin for attaching buddypress groups to posts as categories
#Buddypress-group-taxonomy

This plugin creates a custom taxonomy from the Buddypress groups so you can assign posts to them.

## Installation and

Just place the .php file in `yourdomain.com/wp-content/plugins/` and enable it on the WordPress backend.

## Backend usage

It adds dropdown selector to assign a buddypress group on the backend post edit page automatically. You can assign one group at the time.

Only groups the current user is assigned to are displayed. Groups deleted from buddypress itself are automatcally removed including their assignments.

## Theme usage

### Display group assignements

Add the following within the post loop to display a link to display the assigment linked to the taxonomy overview page:

`<?php printBuddypressGroupAssignment('This post is assigned to the group %s.'); ?>`

Text can be adjusted where `%s` is the placeholder for the link. Optionally there is a 2nd parameter to pass a specific post object directly.

There is an optional 3rd parameter to either link to the real Buddypress group page (true, default) or to the group taxonomy (false).

### Link list of all terms of buddypress_group taxonomy

To display a link list of all buddypress groups of the taxonomy:

`<?php printBuddyPressGroups('All groups'); ?>`

The text is optional and placed before the list. Groups that have no post assigned are not displayed.

### Display all posts assigned to a group

Place on the theme's `page.php` (normally the page for the real Buddypress groups):

`<?php printPostsByBuddypressGroupTax(); ?>`

It automatically takes the current Buddypress group and gets the posts assigned to the buddypress_group taxonomy term of the same name.

Alternatively the slug of the Buddypress group can be passed as a parameter.

`<?php printPostsByBuddypressGroupTax('<slug ofthe group to get>'); ?>`




28 changes: 17 additions & 11 deletions buddypress-group-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Author: Malte Müller
Author URI: http://www.maltem.de
License: GPLv2 or later
Version: 1.1
Version: 1.2
*/

/************************
Expand All @@ -16,7 +16,6 @@
/*
* Registers the taxonomy
*/

function bpgroups_taxonomy_init() {
// create a new taxonomy
register_taxonomy(
Expand Down Expand Up @@ -67,7 +66,8 @@ function bpgroups_meta_box_callback($post) {
if (bp_has_groups()) :
while (bp_groups()) : bp_the_group();
$groupname = bp_get_group_name();

$groupslug = bp_get_group_slug();

// Set group as taxonomy term if not already done
$termexists = term_exists($groupname, 'buddypress_groups');
if (empty($termexists)) {
Expand All @@ -78,9 +78,9 @@ function bpgroups_meta_box_callback($post) {
if (groups_is_user_member(get_current_user_id(), bp_get_group_id())) {
$buddypressgroups[] = array(
'name' => $groupname,
'slug' => strtolower($groupname)
'slug' => $groupslug
);
$checkgroups[] = strtolower($groupname);
$checkgroups[] = strtolower($groupslug);
}
endwhile;
endif;
Expand Down Expand Up @@ -167,18 +167,24 @@ function bpgroups_save_meta_box_data($post_id) {
*
* @param text $text Text for the link. Use %s as placeholder for the link, e.g 'Dieser Beitrag ist mit der Gruppe %s verknüpft.' (default)
* @param obj $obj Optionally a specicific post object, if not set the current post in the loop
* @param bool $linkbuddypressgroup True for linking to the real Buddypress group page, false for the group taxonomy.
*/
function printBuddypressGroupAssignment($text = 'Dieser Beitrag ist mit der Gruppe %s verknüpft.', $obj = NULL) {
function printBuddypressGroupAssignment($text = 'Dieser Beitrag ist mit der Gruppe %s verknüpft.', $obj = NULL, $linkbuddypressgroup = true) {
global $post;
if(!is_null($obj)) {
$obj = $post;
}
$groups = wp_get_object_terms(array($post->ID), array('buddypress_groups'));
if ($groups) {
$group = $groups[0]->name;
if ($group != 'keine') {
$grouplink = get_term_link($groups[0]);
$link = '<a href="'. esc_url($grouplink).'" title="'.esc_attr($group).'">'.esc_html($group).'</a>';
$group_name = $groups[0]->name;
$group_slug = $groups[0]->slug;
if ($group_slug != 'keine') {
if($linkbuddypressgroup && function_exists('bp_get_groups_root_slug')) {
$group_link = get_bloginfo('url') . '/' . bp_get_groups_root_slug() . '/' . $group_slug;
} else {
$group_link = get_term_link($groups[0]);
}
$link = '<a href="'. esc_url($group_link).'" title="'.esc_attr($group_name).'">'.esc_html($group_name).'</a>';
if(is_null($text)) {
$text = 'Gruppe: %s';
}
Expand Down Expand Up @@ -250,4 +256,4 @@ function printPostsByBuddypressGroupTax($groupslug = NULL) {
}
}
}
}
}

0 comments on commit 007125a

Please sign in to comment.