Skip to content

Instantly share code, notes, and snippets.

View toluaddy's full-sized avatar
💭
I may be slow to respond.

toluaddy

💭
I may be slow to respond.
View GitHub Profile
@toluaddy
toluaddy / members-action.php
Created February 3, 2020 12:14
BuddyPress Sort Loop by Last Name
<?php
// Sort loop by last name field.
function alphabetize_by_last_name( $bp_user_query ) {
if ( 'alphabetical' == $bp_user_query->query_vars['type'] ) {
$bp_user_query->uid_clauses['orderby'] = "ORDER BY substring_index( u.value, ' ', -1 )";
}
}
add_action ( 'bp_pre_user_query', 'alphabetize_by_last_name' );
@toluaddy
toluaddy / Buddypress-Group-Check.php
Created February 3, 2020 12:15 — forked from phoopee3/Buddypress-Group-Check.php
Check if a user is part of an existing buddypress group
<?php
// check user against an existing buddypress group
// I needed this in a category.php file to see if
// we were looking at a specific category, and if
// so, check if the user is in a buddypress group
// to ensure they should have access
if ( has_category( 'Some Category') && function_exists( 'groups_is_user_member' ) ) {
$group_id = BP_Groups_Group::group_exists('buddypress-group-slug');
$is_member = groups_is_user_member( wp_get_current_user()->id, $group_id );
if ( !$is_member ) {
@toluaddy
toluaddy / functions.php
Created February 3, 2020 12:15 — forked from BhargavBhandari90/functions.php
Add links to BuddyPress navigation.
<?php
/**
* Add this function to theme's functions.php
*
* Add links to BuddyPress navigation.
* This will add photo, video and music link to BuddyPress navigation.
*
* If you don't want to display "Media" tab, then add following css to
* rtMedia->Settings->Custom CSS:
*
@toluaddy
toluaddy / bp_private_profile.php
Created February 3, 2020 12:18 — forked from nfmohit/bp_private_profile.php
BuddyPress private profile (Redirect to homepage if it is not the current user's profile)
<?php
add_action('template_redirect', 'bp_private_profile');
function bp_private_profile() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( bp_is_user_profile() && ! bp_is_my_profile() ) {
wp_redirect( home_url() );
exit;
}
}
}
@toluaddy
toluaddy / add-group-activity.php
Created February 3, 2020 12:19 — forked from dcavins/add-group-activity.php
Add an activity item for a new custom post type item creation.
<?php
/**
* Create an activity item to appear in a group. Fires once a post has been saved.
*
* @param int $post_ID Post ID.
* @param WP_Post $post Post object.
* @param bool $update Whether this is an existing post being updated or not.
*/
function add_activity_item_for_group( $post_id, $post_object, $update ) {
function custom_filter_notifications_publish_post_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
array_push( $component_names, 'custom' );
<?php
function job_listing_activity_args() {
if ( ! bp_is_active( 'activity' ) ) {
return;
}
add_post_type_support( 'job_listing', 'buddypress-activity' );
bp_activity_set_post_type_tracking_args( 'job_listing', array(
@toluaddy
toluaddy / bpgh-add-user-to-all-ancestors-on-join.php
Created February 3, 2020 12:29 — forked from dcavins/bpgh-add-user-to-all-ancestors-on-join.php
When a user joins a BuddyPress group, this action adds that user to all ancestor groups.
<?php
/* groups_join_group is called whenever someone joins a group. */
add_action('groups_join_group', 'group_join_add_ancestors', 10, 2);
function group_join_add_ancestors( $group_id, $user_id ) {
// I'm assuming that you'll want to join to all ancestors:
$ancestor_ids = hgbp_get_ancestor_group_ids( $group_id );
// To only include groups that the user can visit, use this version:
// $ancestor_ids = hgbp_get_ancestor_group_ids( $group_id, $user_id );
@toluaddy
toluaddy / attachments.php
Created February 3, 2020 12:30 — forked from dcavins/attachments.php
Only allow original uploader or site admin to delete attachments.
<?php if ( bp_docs_is_doc_edit() || bp_docs_is_doc_create() ) : ?>
<?php bp_docs_media_buttons( 'doc_content' ) ?>
<?php endif; ?>
<?php
// Maybe you'll want to do something with main doc ID.
$doc_id = get_the_ID();
?>
<ul id="doc-attachments-ul">
@toluaddy
toluaddy / hgbp-user-can-create-subgroup-depth.php
Created February 3, 2020 12:32 — forked from dcavins/hgbp-user-can-create-subgroup-depth.php
An example of adding "user can" checks on the "create_subgroup" capability
<?php
add_filter( 'bp_user_can', 'my_create_groups_cap_change', 20, 5 );
function my_create_groups_cap_change( $retval, $user_id, $capability, $site_id, $args ) {
if ( 'create_subgroups' == $capability ) {
// We need to know which group is in question.
if ( empty( $args['group_id'] ) ) {
return false;
}