Skip to content

Instantly share code, notes, and snippets.

View sbrajesh's full-sized avatar

Brajesh Singh sbrajesh

View GitHub Profile
@sbrajesh
sbrajesh / disallow-special-characters-in-buddypress-user-name
Created September 28, 2023 08:35
Disallows special characters in BuddyPress username
/**
* Disallow special characters in BuddyPres username.
*/
add_filter( 'bp_core_validate_user_signup', function ( $results ) {
if ( empty( $results ) || empty( $results['errors'] ) ) {
return $results;
}
$username = $results['user_name'];
@sbrajesh
sbrajesh / buddypress-limit-characters-in-group-description.php
Created August 25, 2023 21:15
Limits the number of characters allowed in BuddyPress Group description
// For Group creation.
add_action( 'groups_action_sort_creation_steps', function () {
$allowed_length = 225; // how may characters are allowed?
$step = wp_unslash( bp_action_variable( 1 ) );
if ( empty( $_POST['save'] ) ) {
return;
}
@sbrajesh
sbrajesh / member-types-field-options-sort.php
Created August 8, 2023 09:44
custom sorting BuddyPress member types in the member type field by their creation order in member types pro
// custom sorting of member types on registration page
// by the creation order in member types pro plugin.
add_filter( 'bp_xprofile_member_type_field_allowed_types', function ( $member_types, $registered_types ) {
if ( empty( $member_types ) || ! function_exists( 'bpmtp_get_active_member_type_entries' ) ) {
return $member_types;
}
// find all our active types(Member Types Pro plugin)
$active_type_objects = bpmtp_get_active_member_type_entries();
// sort by post_id(it is similar to creation order)
@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
/**
* 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
<?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
/**
* 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
/**
* 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
<?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
/**
* 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
/**
* 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 ) ) {