Skip to content

Instantly share code, notes, and snippets.

@dcavins
dcavins / filter-author-link-to-bp-profile.php
Last active February 3, 2020 12:11
Filter the WordPress author link to point to the author's BP profile rather than the WP-standard author post archive.
@dcavins
dcavins / compose.php
Last active September 17, 2022 08:23
Limit access to the private message form if the user has sent too many messages today.
<?php
/**
* BuddyPress - Members Single Messages Compose
*
* @package BuddyPress
* @subpackage bp-legacy
*/
?>
@dcavins
dcavins / disallow-access-to-subscriber-profiles.php
Created March 1, 2018 14:35
Don't allow anyone to visit subscriber profiles.
add_action( 'wp', function() {
if ( bp_is_user() ) {
$user_meta = get_userdata( bp_displayed_user_id() );
if ( in_array( 'subscriber', $user_meta->roles ) ) {
wp_redirect( home_url() );
exit;
}
}
}, 1 );
@dcavins
dcavins / prevent-profile-tab-access.php
Created March 3, 2018 15:01
Don't allow people to see a subscriber's profile tab.
add_action( 'bp_actions', function() {
if ( ! bp_is_user() || is_super_admin() ) {
return;
}
$user_meta = get_userdata( bp_displayed_user_id() );
if ( in_array( 'subscriber', $user_meta->roles ) ) {
bp_core_remove_nav_item( 'profile', 'members' )
}
}, 1 );
@dcavins
dcavins / only-site-admins-can-disassociate-group-docs.php
Last active February 3, 2020 12:23
Edit caps: Only site admins can disassociate group docs.
<?php
add_filter( 'bp_docs_map_meta_caps', function( $caps, $cap, $user_id, $args ) {
if ( 'bp_docs_dissociate_from_group' === $cap ) {
if ( user_can( $user_id, 'bp_moderate' ) ) {
$caps = array( 'exist' );
} else {
$caps = array( 'do_not_allow' );
}
}
return $caps;
@dcavins
dcavins / restrict_doc_creation.php
Last active February 3, 2020 12:22
Only allow certain users to create docs.
<?php
add_filter( 'bp_docs_map_meta_caps', function( $caps, $cap, $user_id, $args ) {
if ( 'bp_docs_create' === $cap ) {
// Site admins
if ( user_can( $user_id, 'bp_moderate' ) ) {
$caps = array( 'exist' );
// If this is a group and the user is a group mod or admin.
} else if ( bp_is_group() && ( bp_group_is_mod() || bp_group_is_admin() ) ) {
$caps = array( 'exist' );
} else {
@dcavins
dcavins / media-left.html
Created November 25, 2019 21:40
Position an image to the left of related text using the grid system.
<div class="Media">
<img src="/wp-content/uploads/sites/6/2019/11/doubtful-kitty.jpg" alt="A cat that doubts your ideas." width="100" height="100" class="Media-figure size-full wp-image-1350" />
<div class="Media-body">
<h4 style="margin-top:0;">This is a headline</h4>
<p>Here's some body text that is very interesting and is much accentuated by having that cool image or icon to the side.</p>
</div>
</div>
@dcavins
dcavins / media-left-vertically-centered.html
Created November 25, 2019 21:42
Position an item to the left of text, vertically centered in comparison to the text
<div class="Media Media--center">
<img src="/wp-content/uploads/sites/6/2019/11/doubtful-kitty.jpg" alt="A cat that doubts your ideas." width="100" height="100" class="Media-figure size-full wp-image-1350" />
<div class="Media-body">
<p>Nullam a volutpat urna, nec posuere dui. Cras quis tortor eget sapien ultricies mollis vel non massa. Aenean accumsan vitae ex et pretium. Maecenas in ipsum non sapien tincidunt scelerisque consequat non turpis. Duis accumsan nisl sit amet sodales vestibulum. Pellentesque in nunc elit. Donec vulputate blandit nunc, quis eleifend leo hendrerit a. Phasellus turpis libero, bibendum ut luctus lacinia, euismod nec nisi. </p>
</div>
</div>
@dcavins
dcavins / media-right.html
Created November 25, 2019 21:43
Position an image to the right of related text.
<div class="Media Media--reverse">
<img src="/wp-content/uploads/sites/6/2019/11/doubtful-kitty.jpg" alt="A cat that doubts your ideas." width="100" height="100" class="Media-figure size-full wp-image-1350" />
<div class="Media-body">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sit amet blandit lacus. Proin bibendum eros ut turpis tempor finibus. Vivamus ac scelerisque lectus. Nullam in justo vel mauris fermentum tempus.</p>
</div>
</div>
@dcavins
dcavins / gtm-add-to-theme.php
Created October 5, 2020 19:24
Add the Google Tag Manager snippets to a WordPress theme's `functions.php` file.
<?php
/**
* Add the Google tag manager script in the header.
*
* @since 1.0.0
*
*/
function prefix_add_google_tag_manager_script() {
if ( function_exists( 'wp_get_environment_type' )
&& 'production' !== wp_get_environment_type() ) {