Skip to content

Instantly share code, notes, and snippets.

Avatar

Brajesh Singh sbrajesh

View GitHub Profile
@sbrajesh
sbrajesh / buddypress-xprofile-field-sum.php
Created September 24, 2021 08:18
Calculate sum of given BuddyPress Xprofile field for all the user on the site
View buddypress-xprofile-field-sum.php
/**
* Shortcode to sum all the values of the given xprofile field.
*
* @param int|string $field field id or name.
*
* Example 1:- Total Cows owned by our members [xprofile-field-sum field="Number of Cows you Own"]
* Example 2:- Total Cows owned by our members [xprofile-field-sum field=32]
*/
add_shortcode( 'xprofile-field-sum', function ( $atts = array(), $content = '' ) {
@sbrajesh
sbrajesh / same-gender-user-visibility-buddypress.php
Created December 14, 2020 21:57
BuddyPress same gender users visibility
View same-gender-user-visibility-buddypress.php
<?php
/**
* Filters Users based on Gender. Make sure only users of same genders are visible.
*/
class BuddyDev_Same_Gender_Based_Member_Filter {
/**
* Boot
*
* @return BuddyDev_Same_Gender_Based_Member_Filter
@sbrajesh
sbrajesh / buddypress-filter-multi-select-profile-field-value.php
Last active June 8, 2020 20:30
Filter BuddyPress Multi select value to add extra markup
View buddypress-filter-multi-select-profile-field-value.php
/**
* Filter BuddyPress multi select value and add spans around for custom styling.
*
* @see https://buddydev.com/support/forums/topic/add-extra-css-on-a-profile-field/
*/
add_filter( 'bp_get_the_profile_field_value', function ( $value ) {
global $field;
if ( empty( $field ) || 'multiselectbox' !== $field->type ) {
return $value;
}
@sbrajesh
sbrajesh / member-type-activity-rate-limit.php
Created May 13, 2020 09:28
Rate limiting based on member type using bp-activity-rate-limiter
View member-type-activity-rate-limit.php
/**
* Get time/count for the user
*
* @param int $user_id user id.
*
* @return array
*/
function buddydev_get_activity_mtype_based_rates( $user_id ) {
@sbrajesh
sbrajesh / profile-loop.php
Created May 9, 2020 00:23
profile-loop.php for BuddyPress bp-legacy with edit group link
View profile-loop.php
<?php
/**
* BuddyPress - Members Profile Loop
*
* @package BuddyPress
* @subpackage bp-legacy
* @version 3.0.0
*/
/** This action is documented in bp-templates/bp-legacy/buddypress/members/single/profile/profile-wp.php */
@sbrajesh
sbrajesh / bp-profile-photo-successful-upload-redirection-helper.php
Created April 11, 2020 01:37
Redirect User after successful profile photo upload on BuddyPress
View bp-profile-photo-successful-upload-redirection-helper.php
/**
* Redirect after successful upload of profile photo on BuddyPress.
*/
class BP_Profile_Photo_Successful_Upload_Redirection_Helper {
/**
* Singleton instance.
*
* @var BP_Profile_Photo_Successful_Upload_Redirection_Helper
@sbrajesh
sbrajesh / buddypress-moderation-tools-white-list-users.php
Created March 12, 2020 06:35
White list users from BuddyPress Moderation
View buddypress-moderation-tools-white-list-users.php
/**
* BuddyPress Moderation Tools:- White List users
*
* All contents from whitelisted users are disabled from reporting.
*/
add_filter( 'bpmts_is_user_whitelisted', function ( $is, $user_id ) {
$white_listed_user_ids = [ 1, 2, 3 ];// add your own ids.
if ( in_array( $user_id, $white_listed_user_ids ) ) {
View Recount all members to account excluded member types
add_filter( 'bp_core_get_active_member_count', function ( $count ) {
// protect from errro if plugin is disabled.
if ( ! class_exists( 'BPMTP_Member_Types_Pro' ) ) {
return $count;
}
// optimize.
$current_count = get_transient( 'bpmtp_all_active_members' );
if ( false !== $current_count ) {
View show media with MediaPress activity comments
/**
* Attach media with comments on a mediapress activity.
*
* @param int $comment_id comment id.
* @param array $r args.
* @param BP_Activity_Activity $activity activity object.
*/
function mpp_custom_comment_posted( $comment_id, $r, $activity ) {
@sbrajesh
sbrajesh / bp-user-redirect.php
Created August 11, 2019 21:56
Redirect BuddyPress User to their activity instead of home page
View bp-user-redirect.php
/**
* Redirect users to login if not not logged, otherwise, redirect to user activity.
*/
function buddydev_custom_user_home_page() {
if ( ! is_user_logged_in() ) {
bp_core_redirect( wp_login_url( site_url( '/' ) ) );
}