Skip to content

Instantly share code, notes, and snippets.

@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-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 / 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 / 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 / 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 / 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 / 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 / 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 / add-roles-to-avatar-classes.php
Created December 14, 2017 16:02
Add the user's roles to the classes applied to a BuddyPress avatar.
<?php
add_filter( 'bp_get_member_avatar', 'my_add_user_level_to_avatars', 10, 2 );
/**
* @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg.
* @param array $r Array of parsed arguments. See {@link bp_get_member_avatar()}.
*/
function my_add_user_level_to_avatars( $value, $r ) {
global $members_template;
// The args have already been parsed in bp_get_member_avatar. We'll use them except for the css class.
@dcavins
dcavins / example-custom-registration-field.php
Last active December 14, 2017 15:24
Add custom field to registration form.
<?php
function my_custom_section_registration() {
?>
<div id="sa-interest-opt-in" class="register-section checkbox">
<label><input type="text" name="my_custom_input" id="my_custom_input" /> Label text.</label>
</div>
<?php
}