Skip to content

Instantly share code, notes, and snippets.

@dcavins
dcavins / bp_docs_unlink.1.patch
Created March 4, 2015 01:57
Unlink BP Docs from Groups
@dcavins
dcavins / bp_docs_unlink.2.patch
Created March 4, 2015 16:06
Unlink BP Docs from Groups
@dcavins
dcavins / bp_docs_test_permissions.1.patch
Created March 4, 2015 16:17
Use factory method for user creation
diff --git tests/test-permissions.php tests/test-permissions.php
index a8f766f..9b44cad 100644
--- tests/test-permissions.php
+++ tests/test-permissions.php
@@ -42,7 +42,7 @@ class BP_Docs_Tests_Permissions extends BP_Docs_TestCase {
* @group map_meta_cap
*/
public function test_loggedin_user_can_bp_docs_create() {
- $u = $this->create_user();
+ $u = $this->factory->user->create();
@dcavins
dcavins / search_where_filter
Created April 17, 2015 19:14
Modify the search "WHERE" statement in WordPress
add_filter('posts_search', 'what_the_search', $priority = 10, $accepted_args = 2);
function what_the_search( $search, $query ){
if ( $query->is_search ) {
$towrite = PHP_EOL . '$search: ' . print_r( $search, TRUE );
// $search looks like:
// AND (((wp_posts.post_title LIKE '%walking%') OR (wp_posts.post_content LIKE '%walking%'))) AND (wp_posts.post_password = '')
$fp = fopen('what_the_search.txt', 'a');
fwrite($fp, $towrite);
fclose($fp);
}
@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 {