Skip to content

Instantly share code, notes, and snippets.

@dcavins
dcavins / bp-docs-filter-edit-setting-default.php
Created November 27, 2017 17:54
Change the default setting for the "edit" access level.
<?php
add_filter( 'bp_docs_get_access_options', 'wpsupp_edit_default_access_settings', 10, 4 );
function wpsupp_edit_default_access_settings( $options, $settings_field, $doc_id, $group_id ) {
// Only change the "edit" setting default
if ( 'edit' === $settings_field ) {
foreach ( $options as $id => $settings ) {
// 90 is the id of the "creator" level. Set that to be default. Others, not the default.
if ( 90 === $id ) {
$options[$id]['default'] = 1;
} else {
@dcavins
dcavins / docs-create-cap-mirror-group-setting.php
Created November 9, 2017 18:38
Set the "bp_docs_create" dynamically when in a group.
<?php
function my_docs_create_follow_group_associate_setting( $caps, $cap, $user_id, $args ) {
if ( 'bp_docs_create' == $cap && $group_id = bp_get_current_group_id() ) {
// In a group, only set this cap if the user can associate a doc with the group.
if ( current_user_can( 'bp_docs_associate_with_group', $group_id ) ) {
$caps[] = 'exist';
} else {
$caps[] = 'do_not_allow';
}
}
@dcavins
dcavins / restrict-friends-tab-access.php
Created October 23, 2017 17:39
Prevent access to the "Friends" tab of a member profile, unless it's the user's own profile.
<?php
function bpcodex_remove_member_friends_nav_tab() {
// Stop now if:
// This isn't a user profile
// This is the current user's profile
// The user is a site admin
if ( ! bp_is_user() || bp_is_my_profile() || is_super_admin() ) {
return;
}
@dcavins
dcavins / add-group-activity.php
Created October 19, 2017 20:52
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 ) {
@dcavins
dcavins / two-column-layout-many-items.html
Last active April 2, 2018 21:37
More items than will fit in a single row, but you know you want 1/2 width columns on medium-width screens or larger.
<div class="Grid Grid--guttersLg Grid--full med-Grid--1of2">
<div class="Grid-cell">
1/2
</div>
<div class="Grid-cell">
1/2
</div>
<div class="Grid-cell">
1/2
</div>
@dcavins
dcavins / one-third-width-column-other-flex-width.html
Last active September 22, 2017 16:56
Specify one column to be 1/3 width, let the other column take up the rest of the space, and break to a single column on medium-width screens and smaller.
<div class="Grid Grid--guttersLg Grid--full med-Grid--fit">
<div class="Grid-cell">
2/3
</div>
<div class="Grid-cell u-1of3">
1/3
</div>
</div>
@dcavins
dcavins / one-third-columns-med-break.html
Last active September 22, 2017 16:55
Three column layout that breaks to a single column on medium-width screens and smaller.
<div class="Grid Grid--guttersLg Grid--full med-Grid--fit">
<div class="Grid-cell">
1/3
</div>
<div class="Grid-cell">
1/3
</div>
<div class="Grid-cell">
1/3
</div>
@dcavins
dcavins / bpgh-add-user-to-all-ancestors-on-join.php
Created September 20, 2017 17:08
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 );
@dcavins
dcavins / bp-docs-attachments-order-by-title.php
Created July 11, 2017 16:25
Order BP Doc attachment list alphabetically by title.
<?php
add_filter( 'bp_docs_get_doc_attachments_args', 'dc_order_docs_attachments_by_title' );
function dc_order_docs_attachments_by_title( $args ) {
$args['orderby'] = 'title';
$args['order'] = 'ASC';
return $args;
}
@dcavins
dcavins / bp-custom.php
Created July 1, 2017 12:44
Change BP Docs default read setting.
<?php
add_filter( 'bp_docs_get_default_access_options', 'my_change_docs_default_access_levels' );
function my_change_docs_default_access_levels( $defaults ) {
$defaults['read'] = 'loggedin';
return $defaults;
}