Skip to content

Instantly share code, notes, and snippets.

View imath's full-sized avatar
:octocat:
building the Retraceur PHP software!

imath imath

:octocat:
building the Retraceur PHP software!
View GitHub Profile
@imath
imath / bpgmq.php
Created November 4, 2013 03:39
This is the complete class for the BuddyPress Codex article : Group Meta Queries: Usage Example. You can test it copying it in the functions.php of your active theme
<?php
/* you can copy & paste from here */
//it's important to check the BP_Group_Extension is available
if( class_exists( 'BP_Group_Extension' ) ) :
/**
* This is a quick and dirty class to illustrate "bpgmq"
* bpgmq stands for BuddyPress Group Meta Query...
* The goal is to store a groupmeta in order to let the community administrator
@imath
imath / functions.php
Created September 17, 2013 14:38
Example of use of Bowe Codes to add your very own BuddyPress shortcodes. You can paste the above code in the functions.php of your active theme
<?php
/**
* Building a new BuddyPress shortcode
* using Bowe Codes built-in "API"
*
* You'll need Bowe Codes : http://wordpress.org/plugins/bowe-codes/
* And BuddyPress 1.7+
*/
@imath
imath / gist:6048371
Created July 21, 2013 12:05
A reply to one of my blog comment to force alphabetical order for bc_members shortcode. See http://imathi.eu/2011/05/15/bowe-codes/comment-page-1/#comment-17190
<?php
/** begining of code to copy paste in functions.php of active theme **/
/**
* Forces the order of bc_members to be alphabetical if an alpha class has been added
*
* Using the class argument of bc_members allows to only filter the members_args
* if the class 'alpha' prepends my_members class. Keeping my_members class will maintain
* css rules.
@imath
imath / user_restrict.php
Created June 22, 2013 15:15
A reply to one of my blog's comment. The goal is to restrict the content to a BuddyPress member and to run nested shortcode. Example of use : [user_restrict user_id="3"][bc_groups][/user_restrict]
<?php
/*
Restricting content to the user_id
Requires BuddyPress 1.7 & Bowe Codes 2.0.1
*/
class Restrict_Content_User_Shortcode{
function __construct() {
$this->setup_filters();
}
@imath
imath / bpmh-custom.php
Last active December 18, 2015 20:29
This is a skeleton to create a BP My Home (version 2.0) widget. You can use it in your plugin or in the functions.php file of your active theme.
<?php
/**
* 1- Extending WP_Widget
*
* Make sure to prefix your class with BPMH_
* and to add a classname prefixed by bpmh-
*
*/
class BPMH_Widget_Custom extends WP_Widget {
@imath
imath / gist:5154740
Created March 13, 2013 18:21
Quick tip to Neutralize WordPress post revisions without modifying wp-config.php
<?php
function no_revions_for_posts() {
// see https://twitter.com/pixenjoy/status/311512790760308736
remove_post_type_support('post', 'revisions');
}
add_action( 'init', 'no_revions_for_posts', 99 );
?>
@imath
imath / functions-avatar.php
Created March 4, 2013 16:03
A BuddyPress trick in reply to http://buddypress.org/support/topic/display-only-members-who-have-uploaded-avatar/ : the goal is to only loop through the members who actually uploaded an avatar (instead of using gravatar). !important Make sure to backup your db before running init_evo_meta(). Once init_evo_meta() ran, make sure to delete it and l…
<?php
/************* beginning of the code to paste in the functions.php of the active theme *************/
/*
the function to to display only the users that actually uploaded an avatar
see http://buddypress.org/support/topic/display-only-members-who-have-uploaded-avatar/
*/
function evo_list_uploaded_avatars(){
@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
{
@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 / 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;