Created
June 18, 2015 01:41
-
-
Save benjaminniess/578118e0c0c20bf94fd5 to your computer and use it in GitHub Desktop.
Fix BBPress bug raised here https://bbpress.org/forums/topic/bbpress-breaks-wp_query-in-certain-cases/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: 4m - BBpress fix | |
* Plugin URI: http://4mation.com.au | |
* Description: Fix queries when user is not logged in. | |
* Version: 1.0 | |
* Author: 4mation | |
* Author URI: http://www.4mationtechnologies.com.au | |
* License: A "Slug" license name e.g. GPL2 | |
*/ | |
// don't load directly | |
if ( !defined('ABSPATH') ) { | |
die('-1'); | |
} | |
Class FmBbpressFix { | |
function __construct() { | |
add_filter( 'bbp_exclude_forum_ids', array( __CLASS__, 'fixQuery' ), 10, 3 ); | |
} | |
/** | |
* Fix a bug from BBPress. | |
* When a classic get_posts query is launched, BBP adds a meta_query with private forums ids that prevents the others results to be shown | |
*/ | |
public static function fixQuery( $retval, $forum_ids, $type = '' ) { | |
if ( $type != 'meta_query' ) { | |
return $retval; | |
} | |
if ( !is_array( $retval ) || !isset( $retval['compare'] ) || $retval['compare'] != 'NOT IN' ) { | |
return $retval; | |
} | |
// Use not exists instead of not in which means that non logged in users will not see any forums instead of any private forums | |
$retval['compare'] = 'NOT EXISTS'; | |
return $retval; | |
} | |
} | |
new FmBbpressFix(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment