Skip to content

Instantly share code, notes, and snippets.

View imath's full-sized avatar
🔌
Contributing to #BuddyPress

imath imath

🔌
Contributing to #BuddyPress
View GitHub Profile
@imath
imath / bp_loggedin_user_shortcode.php
Created November 26, 2012 08:58
displaying BuddyPress user's home page link if he's connected into a WordPress post, page or text widget
<?php
/*** displaying BuddyPress user's home page link if he's connected into a WordPress post, page or text widget ***/
/*********
Beginning of the code to paste in the functions.php of your active theme
**********/
@imath
imath / bp-customize-registration.php
Created December 16, 2012 18:11
This is a BuddyPress gist. Using it in your active theme will allow you to manage a regular WordPress user meta in the registration form. Just above the profile fields form, you'll see a new text input 'Usermeta'. You can customize the different references to a random user meta i used (bp_cr_usermeta) by your own.
<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/****
You should paste this into a file (in the example below : bp-customize-registration.php )
in your active theme's folder, then depending if your theme is a child theme or not you should
use this code in your functions.php to include the trick
@imath
imath / bp-search-post-cats.php
Last active December 11, 2015 09:48
adds some categories to BP Default header search (dropdown options) in order to search within this categories...
<?php
/*** based on http://buddydev.com/buddypress/making-buddypress-activity-searchable/ ***/
/* simply paste what follows in your functions.php file */
add_filter( 'bp_search_form_type_select_options', 'kendyman_seventeen_options', 10, 1);
function kendyman_seventeen_options( $options ) {
$args = array(
@imath
imath / bp-tag-nav-item.php
Created February 2, 2013 18:09
In reply to this topic : http://bp-fr.net/groupes/utilisation-configuration-optimisation-de-buddypress/forum/topic/comment-ajouter-un-nouveau-critere-de-tri-aux-topic/ . Adding a new nav item to BuddyPress Forum dir (in case of bbPress 1.2 powered forums..) for a given topic tag.
<?php
/*** Beginning of the code to paste into the functions.php of your BuddyPress theme / child theme ***/
/**
* Hooks bp_forums_directory_group_types and adds a forum directory nav item
*
* @global $wp_taxonomy_object
* @uses $wp_taxonomy_object->get_term_by() to fetch tag datas by name
* @uses bb_get_tag_link() to get permalink for the given tag id.
* @author imath
@imath
imath / mathieu-hides-member.php
Created February 3, 2013 14:25
this is a little BuddyPress trick to hide friends nav and activity friends subnav to members visiting other member profiles. It's a reply to this topic : http://bp-fr.net/groupes/utilisation-configuration-optimisation-de-buddypress/forum/topic/supprimer-longlet-amis-de-la-fiche-dun-membre/
<?php
/**** beginning of the code to copy in the functions.php file of active theme ****/
function mathieu_hides_friends_nav( $nav_items, $nav_items_args ) {
if( is_super_admin() )
return $nav_items;
if( bp_is_user() && !bp_is_my_profile() )
return false;
@imath
imath / imath-pm-friends-only.php
Last active May 3, 2023 06:24
I was writing my second BuddyPress tutorial for wpformation.com when i realized it could be helpful for a community admin to restrict private messages to friends only...
<?php
/*** beginning of the code to paste in your functions.php ***/
function imath_pm_button_only_if_friends( $button ) {
if( is_super_admin() )
return $button;
if( 'is_friend' != friends_check_friendship_status( bp_displayed_user_id(), bp_loggedin_user_id() ) )
return false;
@imath
imath / bastien-delete-own-topic.php
Created February 5, 2013 13:48
Allows members to delete their own topic in BuddyPress group forums. I advise you to be very careful with this script as BuddyPress normaly only allows group admin or super admin to delete topics.
<?php
/** Beginning of the code to copy in the functions.php of your active theme **/
function bastien_own_topic_delete() {
if( bp_get_the_topic_is_mine() && ( !bp_is_item_admin() || !bp_is_item_mod() || !bp_current_user_can( 'bp_moderate' ) ) ) {
?>
<div class="admin-links" style="margin-right:50px!important">
@imath
imath / bp-function-restrict-group-activity-comments.php
Last active December 13, 2015 19:59
BuddyPress trick to disallow group activity comments or comment replies to non members of the group
<?php
/*** beginning of the code to paste in the functions.php of your theme ***/
function imath_wants_you_to_be_in_group_to_comment_group_activities( $can_comment ) {
global $activities_template;
if( !is_super_admin() && $activities_template->activity->component == 'groups' && !groups_is_user_member( bp_loggedin_user_id(), $activities_template->activity->item_id ) )
$can_comment = false;
@imath
imath / gist:5049922
Created February 27, 2013 17:48
A simple BuddyPress trick to avoid saving activities when members are becoming friends or when a member joins a group.
<?php
/* beginning of the code to paste in the functions.php of your active theme */
function imath_activivity_dont_save( $activity_object ) {
// friendship_created is fired when a member accepts a friend request
// joined_group is fired when a member joins a group.
$exclude = array( 'friendship_created', 'joined_group');
// if the activity type is empty, it stops BuddyPress BP_Activity_Activity::save() function
@imath
imath / tmp-functions.php
Last active December 14, 2015 10:59
This is a quick and dirty attempt in order to use the custom page template (an Admin can define in the WP Editor template select box) with BuddyPress 1.7 Theme Compat. I think the main challenge is not in loading the custom template, but it's too understand how the theme is rendering the layout. For instance : twentyeleven and twentytwelve are u…
<?php
/*
beginning of the code to paste in the functions.php of the active theme (twentyten, twentyeleven or twentytwelve)
If you want to adapt it to your theme, you'll need to check if it uses some body_class to render its layout and eventually
adapt lines 70 to 101.
*/
class Imath_WP_Editor_Template
{