latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Detaching s2member filters from bbpress forum

Home Forums Community Forum Detaching s2member filters from bbpress forum

This topic contains 7 replies, has 2 voices. Last updated by  Fitted Web Design 4 years, 7 months ago.

Topic Author Topic
Posted: Monday May 21st, 2012 at 9:13 pm #14123

I know you aren’t here to give support for bbPress, but this is more about how to selectively detach s2member’s security filters within the loop (I think). Plus, it looks like you’re using bbPress on this site so I thought you might have some insight.

Typically on my site, I only want people to see what they have permissions to view. For example, in a wordpress category view, posts don’t appear in the list unless the user can access it. That’s fine. However, in the bbPress forums listings (single-forum.php), I *do* want all forums to appear, regardless of actual access permissions. Then, have it display a little locked icon next to forums that they don’t have access to. If they click into a secure forum, it would redirect to the s2member options page as normal for pages they can’t access.

What it comes down to, I think, is to detach s2member’s filters for that specific forum list view, then reattach them for everything else.

I’m not exactly sure where to even do this inside the bbPress templates, but maybe if you can point me in the right direction of how to do it for a standard WP category view, then I can figure it out for bbPress.

I tried using the approach

detach_s2member_query_filters();
query_posts('yada-yada');

But I think, maybe, since bbPress uses get_posts, that approach doesn’t really work? I tried it before the

<?php while ( have_posts() ) : the_post(); ?>

line in the single-forums.php template, but it was pulling other posts from elsewhere in the site rather than the forums. Maybe I don’t know how to use query_posts to get the bbPress forums?

I also tried unchecking the box for Alternate View Protection box for “Filter ALL WordPress® queries; protecting all Alternative Views.” which worked, but also left almost all of my secure content elsewhere on the site open to the public. Maybe there’s a way to choose precisely what alternate views are/are not being protected and I could apply that to the bbPress forum listing view?

Hoping you have some insight.

(Sorry for the tl;dr style post. I tried to include all of the information you might want. Thanks!)

Kenny

List Of Topic Replies

Viewing 7 replies - 1 through 7 (of 7 total)
Author Replies
Author Replies
Posted: Tuesday May 22nd, 2012 at 10:13 pm #14233

Hi Kenny.

Don’t worry about the length, as long as it’s helpful to understand the problem, it’s very welcome, otherwise I have to exchange a few comments before I have enough data to know what to suggets.

About your situation, you have tried what I would have, so I’ll email Jason asking him.

If you remove the alt. views restriction, you can still protect the content in the rest of the site as long as you don’t mind the title of your posts being listed in archives or the home page, because if you use the “more” tag WP provides, then placing it at the top of the post will prevent the content from showing in the list and if a user without access tries opening the post, he’ll be sent to the Membership Options Page.

Here’s a plugin that automates adding the more tag to everything: http://wordpress.org/extend/plugins/auto-more-tag/

I hope that helps!

Posted: Tuesday May 22nd, 2012 at 10:29 pm #14235

Thanks, Cristian.

Good idea with the MORE tag, but I’m already using that to secure specific parts of posts, so it would be confusing to add another MORE tag at the tops of posts. (Instead of securing the entire post with a ccap, I secured everything after the MORE tag. That allows for the client to tease some of his content to the public and gives a simple command in the wp editor to lock a portion of his content.)

Looking into it, I think it might be solved by running a custom bbPress loop and filtering it to show only items the user canNOT access. Since the current loop outputs what they CAN access, I’d end up with two listings, but all-in-all showing all of the possible forums. Grouping them by access might even end up being visually helpful. But I don’t know if the s2member filters can be detached from a bbPress query. Come to think of it, I don’t even know how to make that query. (I think it has something to do with BB_Query() or bbp_get_forum(). )

Though, the perfect solution is still to simply show the whole list together in the original loop, since my action to display the lock icon next to secure forums is working just fine.

BTW, you can see this all working at http://www.zackpetroc.com

Posted: Wednesday May 23rd, 2012 at 4:25 am #14303

Nice work. :)

When I mentioned the more tag, I didn’t know you were already using it. You shouldn’t use it more than one in a post. If you want to show a teaser instead of nothing, that’s perfectly alright.

About having two lists in bbPress, one for can and another for cannot, it could work, but I don’t know how to do it either. You’d need to look in the bbPress code.

I already emailed Jason, so he may leave a comment when he gets to it. :)

Posted: Thursday May 24th, 2012 at 2:59 am #14409

Jason told me he’d have to research this on bbPress’ side to provide a solution, so there’s no suggestion off the top of his head.

I guess you have a clearer picture than him with this at the moment, since you’ve been studying their code already. Maybe bbPress support can give you an idea to achieve what you want?

Posted: Thursday May 24th, 2012 at 3:04 am #14410

Thanks for continuing to follow up. I’ve posted a couple of times at the bbPress forums without luck. :(

Posted: Thursday May 24th, 2012 at 4:11 am #14422

:/

Posted: Friday Jun 1st, 2012 at 4:54 pm #15200

Here’s a step possibly in the right direction. But I’m not sure how we’d detach/reattach s2member’s security. Unfortunately, there aren’t a lot of bbPress code examples around. Thoughts?

From the bbPress code:

/**
 * The main forum loop.
 *
 * WordPress makes this easy for us.
 *
 * @since bbPress (r2464)
 *
 * @param mixed $args All the arguments supported by {@link WP_Query}
 * @uses WP_Query To make query and get the forums
 * @uses bbp_get_forum_post_type() To get the forum post type id
 * @uses bbp_get_forum_id() To get the forum id
 * @uses get_option() To get the forums per page option
 * @uses current_user_can() To check if the current user is capable of editing
 *                           others' forums
 * @uses apply_filters() Calls 'bbp_has_forums' with
 *                        bbPres::forum_query::have_posts()
 *                        and bbPres::forum_query
 * @return object Multidimensional array of forum information
 */
function bbp_has_forums( $args = '' ) {
	global $bbp;

	// Make sure we're back where we started
	wp_reset_postdata();

	// Setup possible post__not_in array
	$post_stati[] = 'publish';

	// Super admin get whitelisted post statuses
	if ( is_super_admin() ) {
		$post_stati = array( 'publish', 'private', 'hidden' );

	// Not a super admin, so check caps
	} else {

		// Check if user can read private forums
		if ( current_user_can( 'read_private_forums' ) )
			$post_stati[] = 'private';

		// Check if user can read hidden forums
		if ( current_user_can( 'read_hidden_forums' ) )
			$post_stati[] = 'hidden';
	}

	// The default forum query for most circumstances
	$default = array (
		'post_type'      => bbp_get_forum_post_type(),
		'post_parent'    => bbp_get_forum_id(),
		'post_status'    => implode( ',', $post_stati ),
		'posts_per_page' => get_option( '_bbp_forums_per_page', 15 ),
		'orderby'        => 'menu_order',
		'order'          => 'ASC'
	);

	// Parse the default against what is requested
	$bbp_f = wp_parse_args( $args, $default );

	// Filter the forums query to allow just-in-time modifications
	$bbp_f = apply_filters( 'bbp_has_forums_query', $bbp_f );

	// Run the query
	$bbp->forum_query = new WP_Query( $bbp_f );

	return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
}
Viewing 7 replies - 1 through 7 (of 7 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.