Skip to content

Instantly share code, notes, and snippets.

@r-a-y
Last active March 15, 2017 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-a-y/2b0d574c46ce5b3ce83319d55be175be to your computer and use it in GitHub Desktop.
Save r-a-y/2b0d574c46ce5b3ce83319d55be175be to your computer and use it in GitHub Desktop.
Modify SQL query for BP's Sites Directory
<?php
/**
* Modify BP's site query for non-super-admins.
*/
add_action( 'bp_include', function() {
// If you're doing checks against More Privacy Options, make sure MPO is active.
if ( ! class_exists( 'ds_more_privacy_options' ) ) {
return;
}
// Modify the SQL query.
add_filter( 'bp_after_blogs_get_blogs_parse_args', function( $retval ) {
add_filter( 'query', 'my_filter_blogs_query' );
return $retval;
} );
// Remove our SQL query.
add_filter( 'bp_blogs_get_blogs', function( $retval ) {
remove_filter( 'query', 'my_filter_blogs_query' );
return $retval;
} );
} );
/**
* Show all blogs regardless of "Site Visibility" setting.
*
* "Allow search engines to index this site" should not equate to hiding the
* blog from the Sites directory!
*/
function my_filter_blogs_query( $retval ) {
// Check for the 'public' clause. If the clause doesn't exist, bail.
if ( false === strpos( $retval, 'wb.public = 1' ) ) {
return $retval;
}
// Modify the SQL query to your liking.
// This example removes the 'public' clause entirely, but you might want to do something different.
$retval = str_replace( ' AND wb.public = 1', '', $retval );
return $retval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment