Skip to content

Instantly share code, notes, and snippets.

@r-a-y

r-a-y/blogs.php

Last active Mar 15, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.