Skip to content

Instantly share code, notes, and snippets.

View sbrajesh's full-sized avatar

Brajesh Singh sbrajesh

View GitHub Profile
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 ) {
/**
* 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
/**
* 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( '/' ) ) );
}
@sbrajesh
sbrajesh / custom-redirect-bp-autoactivate.php
Created May 15, 2019 16:23
Custom redirect after auto activation/auto login
/**
* Redirect user to some page on site when automatically activated and logged in.
*
* @param string $url url to redirect to.
* @param int $user_id user id.
*
* @return string
*/
function buddydev_custom_activation_redirect( $url, $user_id ) {
@sbrajesh
sbrajesh / bp-custom.php
Created February 27, 2019 05:17
Empty bp-custom.php for your own usage
<?php
// your php custom code goes below this line.
@sbrajesh
sbrajesh / user-report-message-thread.php
Created February 19, 2019 06:01
Add user report button in message thread.
/**
* Add block/unblock button on single message thread.
*/
function buddydev_show_user_report_button_on_message_thread() {
// only message involving single user can be blocked.
if ( ! function_exists( 'bpmts_report_button' ) || ! bp_is_my_profile() ) {
return;
}
@sbrajesh
sbrajesh / gist:cc37e8794527f86046e1d880490d974b
Created January 9, 2019 23:15
BuddyPress Private Message Rate Limiter, Role based customization
/**
* Get the applicable limit for the given role.
*
* @param string $role role name.
*
* @return array
*/
function buddydev_custom_get_role_based_message_limit( $role ) {
@sbrajesh
sbrajesh / gist:42843929a5b89c3065ee2ae6b1e6a904
Created December 11, 2018 03:23
Use a text field as a way to link to other users profile on BuddyPress
class BP_Other_User_As_Profile_Field {
/**
* Field id, replace with actual field id.
*
* @var string
*/
private $field_id = 25; // Chang it with actual field id.
@sbrajesh
sbrajesh / hv2.php
Created November 5, 2018 13:31
Featured Member Expiration based on role
/**
* Class BP_Featured_Member_Expirable_Membership
*
* @author Ravi Sharma
*/
class BP_Featured_Member_Expirable_Membership{
/**
* Singleton Instance
@sbrajesh
sbrajesh / current-group-autojoin-for-bp-ajax-registration.php
Created October 4, 2018 13:33
Auto join user to current group when using BuddyPress Ajax Registration plugin.
/**
* Auto join user to current group when using BuddyPress Ajax Registration plugin.
*
* @param int $user_id user id.
*/
function buddydev_auto_join_current_group_on_activation( $user_id ) {
if ( bp_is_group() ) {
groups_join_group( groups_get_current_group()->id, $user_id );