Skip to content

Instantly share code, notes, and snippets.

@shanebp
shanebp / custom-notification.php
Created October 27, 2020 17:50 — forked from modemlooper/custom-notification.php
BuddyPress add custom notification
<?php
// this is to add a fake component to BuddyPress. A registered component is needed to add notifications
function custom_filter_notifications_get_registered_components( $component_names = array() ) {
// Force $component_names to be an array
if ( ! is_array( $component_names ) ) {
$component_names = array();
}
// Add 'custom' component to registered components array
@shanebp
shanebp / bp-profile-tab-and-subnav.php
Last active June 28, 2023 18:11
BuddyPress add profile tab and subnav
function add_animal_tabs() {
global $bp;
bp_core_new_nav_item( array(
'name' => 'Animals',
'slug' => 'animals',
'parent_url' => $bp->displayed_user->domain,
'parent_slug' => $bp->profile->slug,
'screen_function' => 'animals_screen',
'position' => 200,
@shanebp
shanebp / gist:0cea91fd3b8cf36ed0a3629392c2ffad
Created June 16, 2021 17:30
Send notifications to friends when a new event is created with BP Simple Events free version
function pat_filter_notifications_get_registered_components( $component_names = array() ) {
if ( ! is_array( $component_names ) ) {
$component_names = array();
}
array_push( $component_names, 'events' );
return $component_names;
@shanebp
shanebp / gist:b73343e9c9a6509d2bbc47de80c881c1
Last active January 19, 2023 02:37
add last_activity timestamp to all BP members
/*
* Paste in your theme functions.php or in bp-custom.php.
* Load the site in a browser
* Remove from your theme functions.php or bp-custom.php.
*/
function buddypress_add_last_activity() {
$members = get_users( 'fields=ID' );
// $members = get_users( 'fields=ID&role=subscriber' );
@shanebp
shanebp / api.php
Created November 10, 2021 16:21 — forked from dexit/api.php
Disable WordPress REST API endpoints
// Remove init rest routes
remove_action( 'rest_api_init', 'create_initial_rest_routes', 0 );
// Remove oembed rest routes
function remove_json_api () {
// Remove the REST API lines from the HTML Header
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
/*
If you are using BP 2.1+, this will insert a Country selectbox.
Add the function to bp-custom.php and then visit .../wp-admin/users.php?page=bp-profile-setup
Remove this function after the field is created.
*/
function bp_add_custom_country_list() {
if ( !xprofile_get_field_id_from_name('Country') && 'bp-profile-setup' == $_GET['page'] ) {
@shanebp
shanebp / BP_Group_Extension-example
Last active May 26, 2021 16:26
example of using BP_Group_Extension
/* example of using BP_Group_Extension
* replace 'test' with something else - remember that it is case-sensitive
* checks for any selected Group Types in the 'Settings' step
*/
function test_add_group_extension() {
if ( bp_is_active( 'groups' ) ) :
@shanebp
shanebp / gist:5561044
Last active May 20, 2021 08:48
add subnav link to profile -> friends
add_action( 'bp_setup_nav', 'add_videos_subnav_tab', 100 );
function add_videos_subnav_tab() {
global $bp;
bp_core_new_subnav_item( array(
'name' => 'Videos',
'slug' => 'videos',
'parent_url' => trailingslashit( bp_loggedin_user_domain() . 'friends' ),
@shanebp
shanebp / list_groups_on_members_loop.php
Created July 22, 2016 15:49
List a member's groups on the Members Directory
function shanebp_user_groups(){
$group_ids = groups_get_user_groups( bp_get_member_user_id() );
foreach( $group_ids["groups"] as $id ) {
$group = groups_get_group( array( 'group_id' => $id ) );
echo '<a href=' . trailingslashit( bp_get_groups_directory_permalink() . $group->slug . '/' ) . '>' . $group->name . '<a/><br>';
@shanebp
shanebp / BuddyPress > Nouveau > Add Count to Group Tab
Last active May 20, 2021 08:45
Try to add a count bubble next to a custom group tab added via BP_Group_Extension
// Using the Nouveau template pack
// Add a count bubble on a custom tab on a user profile is straightforward
$count = get_the_count_profile( $group_id );
$class = ( 0 === $count ) ? 'no-count' : 'count';
$name = sprintf( __( 'Events <span class="%s">%s</span>', 'bp-simple-events' ), esc_attr( $class ), number_format_i18n( $count ) );