Skip to content

Instantly share code, notes, and snippets.

@dcavins
dcavins / sample-cpt-menu
Created May 5, 2015 17:44
Declaring a Sample CPT and Custom Menu
// Create the CPT using special caps
add_action( 'init', 'register_cpt_sample_cpt' );
function register_cpt_sample_cpt() {
$labels = array(
'name' => _x( 'Sample CPT', 'sample_cpt' ),
'singular_name' => _x( 'Sample CPT', 'sample_cpt' ),
'add_new' => _x( 'Add New', 'sample_cpt' ),
'add_new_item' => _x( 'Add New Sample CPT', 'sample_cpt' ),
'edit_item' => _x( 'Edit Sample CPT', 'sample_cpt' ),
'new_item' => _x( 'New Sample CPT', 'sample_cpt' ),
@dcavins
dcavins / group_save_filter
Last active August 29, 2015 14:23
Capture group args at group creation
add_action( 'groups_group_after_save', 'bp_45123590' );
function bp_45123590( $group_args ) {
$towrite = PHP_EOL . 'newly created group args: ' . print_r( $group_args, TRUE );
$fp = fopen('groups_group_after_save_args.txt', 'a');
fwrite($fp, $towrite);
fclose($fp);
}
@dcavins
dcavins / bp-docs-install-update-script.php
Created July 23, 2015 19:58
Do some data cleaning/unification on activation or upgrade.
<?php
function bp_docs_upgrade_script_1_9() {
global $wpdb;
$bp = buddypress();
// Clean the meta_values that got grossed up in BP 2.0
$wpdb->update( $bp->groups->table_name_groupmeta,
array( 'meta_key' => 'bp-docs' ),
array( 'meta_key' => 'bpdocs' )
@dcavins
dcavins / troubleshoot-parent-dropdown-menu.php
Last active January 5, 2016 18:05
Dump the $WP_Query args out to the page for BP Docs queries
// We use the priority of 30 because bp_docs_access_protection kicks in at priority 28.
add_action( 'pre_get_posts', 'troubleshoot_parent_doc_dropdown', 30 );
function troubleshoot_parent_doc_dropdown( $wp_query ) {
if ( $wp_query->query['post_type'] == bp_docs_get_post_type_name() ) {
echo '<pre>'; var_dump( $wp_query->query_vars ); echo '</pre>';
}
}
@dcavins
dcavins / wp_expose_hooked_functions.php
Created January 11, 2016 20:42
See what functions are hooked to a WordPress filter.
// Utility filter to see what's attached to a filter:
function dc_wp_show_hooked_filters() {
// Set the hook name you're checking out here.
$hook_name = 'pre_get_posts';
global $wp_filter;
echo '<pre class="filter-dump">';
var_dump( $wp_filter[$hook_name] );
echo '</pre>';
}
add_action( 'wp_head', 'dc_wp_show_hooked_filters' );
@dcavins
dcavins / show_filters.php
Created March 5, 2016 15:15
Show the hook attached to a specific filter
function dc_wp_show_hooked_filters(){
global $wp_filter;
$filter_name = 'bp_core_fetch_avatar_no_grav';
echo '<pre class="filter-dump">';
var_dump( $wp_filter[$filter_name] );
echo '</pre>';
}
add_action( 'wp_head', 'dc_wp_show_hooked_filters' );
@dcavins
dcavins / BP Docs Folders Enabled Checks
Created April 10, 2016 13:15
Checking that Doc folders are enabled and can run.
<?php
if ( bp_docs_enable_folders() ) {
echo PHP_EOL . "Folders are enabled generally.";
} else {
echo PHP_EOL . "Folders are disabled generally.";
}
if ( bp_docs_enable_folders_for_current_context() ) {
echo PHP_EOL . "Folders are enabled for current context.";
} else {
@dcavins
dcavins / xprofile-input-changes.html
Created June 1, 2016 17:46
Changes to the radio button, checkbox and date box Xprofile input types.
<!-- Checkbox inputs, before changes -->
<div class="editfield field_2 field_core-makeup optional-field visibility-public alt field_type_checkbox">
<div class="checkbox">
<label for="field_2">Core makeup</label>
<label for="field_11_0"><input name="field_2[]" id="field_11_0" value="Goat" type="checkbox">Goat</label>
<label for="field_12_1"><input name="field_2[]" id="field_12_1" value="Rhinoceros" type="checkbox">Rhinoceros</label>
<label for="field_13_2"><input name="field_2[]" id="field_13_2" value="Slow Loris" type="checkbox">Slow Loris</label>
</div>
</div>
@dcavins
dcavins / all-doc-breadcrumb-item.php
Created September 22, 2016 16:21
Add "All Docs" breadcrumb item to user profile breadcrumbs.
<?php
function add_all_docs_to_user_directory_breadcrumb( $crumbs ) {
if ( bp_is_user() ) {
array_unshift( $crumbs, sprintf( '<a href="%s">All Docs</a>', bp_docs_get_archive_link() ) );
}
return $crumbs;
}
add_filter( 'bp_docs_directory_breadcrumb', 'add_all_docs_to_user_directory_breadcrumb' );
@dcavins
dcavins / comment-logic-nesting.diff
Created November 16, 2016 15:52
Fix for allowing competing comment access settings to coexist peaceably.
diff --git includes/templates/docs/single/comments.php includes/templates/docs/single/comments.php
index b11ff29..8b5d42d 100644
--- includes/templates/docs/single/comments.php
+++ includes/templates/docs/single/comments.php
@@ -21,35 +21,44 @@ foreach ( (array)$comments as $comment ) {
?>
-<?php if ( current_user_can( 'bp_docs_read_comments' ) ) : ?>
+<?php if ( current_user_can( 'bp_docs_read_comments' ) || current_user_can( 'bp_docs_post_comments' ) ) : ?>