<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>stefano &#187; buddypress</title> <atom:link href="http://www.stefanoforenza.com/tag/buddypress/feed/" rel="self" type="application/rss+xml" /><link>http://www.stefanoforenza.com</link> <description>Abbattuta l&#039;Accademia della Crusca gli SMS vinceranno</description> <lastBuildDate>Sun, 05 May 2013 00:47:22 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.5.1</generator> <item><title>How to create Private (and moderated) Forums BuddyPress and BBPress</title><link>http://www.stefanoforenza.com/how-to-create-private-and-moderated-forums-buddypress-and-bbpress/</link> <comments>http://www.stefanoforenza.com/how-to-create-private-and-moderated-forums-buddypress-and-bbpress/#comments</comments> <pubDate>Wed, 04 Feb 2009 04:57:16 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[php]]></category> <category><![CDATA[bbpress]]></category> <category><![CDATA[buddypress]]></category> <category><![CDATA[wordpress]]></category> <category><![CDATA[wordpress mu]]></category> <category><![CDATA[[HOW TO] get the damn thing working]]></category> <guid
isPermaLink="false">http://www.stefanoforenza.com/?p=290</guid> <description><![CDATA[If you develop on BuddyPress, you&#8217;re likely to get stuck while trying to get per-forum permissions. Indeed, it seems there&#8217;s not yet a way to make BBPress read the BuddyPress groups and hide the froums belonging to private  groups I had to develop a way myself. Furthermore, I needed to give forum moderation rights to the moderators of each group in BuddyPress on a per-forum basis. This is a quick and dirty tutorial for future ...]]></description> <content:encoded><![CDATA[<p>If you develop on BuddyPress, you&#8217;re likely to get stuck while trying to get per-forum permissions.</p><p>Indeed, it seems there&#8217;s not yet a way to make BBPress read the BuddyPress groups and hide the froums belonging to private  groups I had to develop a way myself.</p><p>Furthermore, I needed to give forum moderation rights to the moderators of each group in BuddyPress on a per-forum basis.</p><p>This is a quick and dirty tutorial for future reference. Keep in mind I am using the bleeding edge (svn) versions of WordPress Mu, BuddyPress and BBPress.</p><p>At the end of this tutorial <strong>your BBpress will hide any forum associated with a non-public user group, and group moderators will have the needed  privileges in BBPress as well</strong> (without manual intervention).</p><p><strong>Note: </strong>I assume you <strong>already work</strong> with those three softwares and <strong>you know how</strong> to install them, install plugins, etc.</p><p><strong>First</strong>: install WordPress Mu 2.7 (it&#8217;s not stable yet, so you&#8217;ll have to get it somewhere from svn)</p><p><strong>Second:</strong> Install BuddyPress bleeding edge version on top of WordPress.</p><p><strong>Third:</strong> Download the svn version of BBPress and decompress it in a sub folder.</p><p><a
href="http://bbpress.org/forums/topic/wordpress-and-bbpress-integration-101">Be sure to properly integrate BBPress with WordPress</a>. (<a
href="http://jimgroom.org/bavawiki/index.php?title=Integrating_WPMu%2C_BuddyPress%2C_and_bbPress">further reading here</a>)</p><p>When you get everything working, download the <a
href="http://bbpress.org/plugins/topic/hidden-forums/">Hidden Forums plugin</a> and install it in BBPress.</p><p>Now, open the <em>hidden-forums/hidden-forums.php</em> file and replace everything from the top to the &#8220;<em>/*    stop  editing  here    */</em>&#8221; mark with:</p><pre>require_once( 'bp_integration.php' );</pre><p>When you&#8217;re done, create a new file named &#8220;<em>bp_integration.php</em>&#8221; in the same folder and copy paste the following code. Save everything, activate, and you&#8217;re done <img
src='http://www.stefanoforenza.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p><pre>&lt;?php
//settings
global $bp;
$bp['groups']['table_name_groupmeta'] = 'wp_bp_groups_groupmeta';
$bp['groups']['table_name'] = 'wp_bp_groups';
$bp['groups']['table_name_members'] = 'wp_bp_groups_members';
$bp_integration_privileges = array(); //ids of forums the logged user can moderate
function bp_integration_apply_user_permissions()
{
    global $hidden_forums, $bb_current_user;
    global $bbdb, $bp;
    global $bp_integration_privileges;
    $query = "
    SELECT group.id as id, group.enable_forum as enable_forum, meta.meta_value as forum_id FROM `{$bp['groups']['table_name']}` as `group`
    INNER JOIN `{$bp['groups']['table_name_groupmeta']}` as meta
        ON group.id = meta.group_id AND meta.meta_key = 'forum_id' AND group.status != 'public'
    ";
    $private_groups = $bbdb-&gt;get_results( $query );
    $user_id=(!empty($bb_current_user)) ? intval($bb_current_user-&gt;ID) : 0;
    // hide these forums, list by comma seperated number
    $hidden_forums['hidden_forums']=array();
    foreach ( $private_groups as $group )
    {
        $hidden_forums['hidden_forums'][] = $group-&gt;forum_id;
    }
    $allowed_group = bp_integration_allowed_forums($user_id);
    $moderator_in = bp_integration_user_privileges($user_id);
    foreach ( $allowed_group as $allowed )
    {
        foreach ( $private_groups as $group )
        {
            if ( $group-&gt;id == $allowed-&gt;group_id &amp;&amp; $group-&gt;enable_forum )
            {
                $hidden_forums['allow_users'][$group-&gt;forum_id][] = $user_id;
            }
        }
    }
    foreach ( $moderator_in as $moderated )
    {
        foreach ( $private_groups as $group )
        {
            if ( $group-&gt;id == $moderated-&gt;group_id &amp;&amp; $group-&gt;enable_forum )
            {
                $bp_integration_privileges[] = $group-&gt;forum_id;
            }
        }
    }
    $hidden_forums['allow_roles']['all_forums']=array('keymaster');
    $hidden_forums['allow_users']['all_forums'] = array();
}
add_action('bb_init','bp_integration_apply_user_permissions',199);
function bp_integration_user_privileges ( $user_id, $limit = false, $page = false, $get_total = true, $as_col = false )
{
    global $bbdb, $bp;
    if ( $limit &amp;&amp; $page )
        $pag_sql = $bbdb-&gt;prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
			$group_sql = $bbdb-&gt;prepare( "
SELECT DISTINCT group_id
FROM " . $bp['groups']['table_name_members'] . "
WHERE user_id = %d AND inviter_id = 0 AND is_banned = 0
AND ( is_admin = 1 OR is_mod = 1 )
{$pag_sql}
", $user_id );
    return $paged_groups = $bbdb-&gt;get_results( $group_sql );
}
function bp_integration_allowed_forums( $user_id, $limit = false, $page = false, $get_total = true, $as_col = false ) {
		global $bbdb, $bp;
		if ( $limit &amp;&amp; $page )
			$pag_sql = $bbdb-&gt;prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
			$group_sql = $bbdb-&gt;prepare( "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND inviter_id = 0 AND is_banned = 0{$pag_sql}", $user_id );
		return $paged_groups = $bbdb-&gt;get_results( $group_sql );
	}
function bp_integration_moderators_privileges ()
{
    global $bb_current_user, $forum,$topic_id;
    global $bp_integration_privileges;
    $args = func_get_args();
     $moderator_skills = array(
		'moderate' =&gt; true,
		'participate' =&gt; true,
		'manage_tags' =&gt; true,			//+
        /* ??!?! seems not work
		'delete_topics' =&gt; true,		//+
		'close_topics' =&gt; true,			//+
		'stick_topics' =&gt; true,			//+
		'move_topics' =&gt; false,			//+
         */
        /* ??!?! seems to work */
        'delete_topic' =&gt; true,		//+
		'close_topic' =&gt; true,			//+
		'stick_topic' =&gt; true,			//+
		'move_topic' =&gt; false,
		'view_by_ip' =&gt; false,			//+
		'edit_closed' =&gt; true,			//+
		'edit_deleted' =&gt; true,			//+
		'browse_deleted' =&gt; true,		//+
		'edit_others_tags' =&gt; true,		//+
		'edit_others_topics' =&gt; true,	//+
		'delete_posts' =&gt; true,			//+
		'throttle' =&gt; true,				//+
		'ignore_edit_lock' =&gt; true,		//+
		'edit_others_posts' =&gt; true,	//+
		'edit_favorites' =&gt; true,
		'edit_tags' =&gt; true,
		'edit_topics' =&gt; true,
		'edit_posts' =&gt; true,
		'edit_profile' =&gt; true,
		'write_topics' =&gt; true,
		'write_posts' =&gt; true,
		'change_password' =&gt; true,
		'read' =&gt; true
	);
    if ( ! in_array($args[1], array_keys($moderator_skills)) )
    {
        //echo '&lt;pre&gt;';var_dump( $args[1] );echo '&lt;/pre&gt;';
        return $args[0];
    }
    if (!$bb_current_user || in_array('keymaster',$bb_current_user-&gt;roles) || in_array('administrator',$bb_current_user-&gt;roles))
    {
		return $args[0];
    }
    //--------&gt; OK, LET'S GO !
    // prevents forum moderators to stick a topic to the forum's front page
    if ( $args[1] == 'stick_topic' )
    {
        global $super;
        $super = 0;
    }
	if (empty($forum)) {
		$topic = get_topic($topic_id);
		$forum_id = $topic-&gt;forum_id;
	} else {
        $forum_id = $forum-&gt;forum_id;
    }
    if ( !$forum_id ) return $args[0];
    if ( in_array( $forum_id, $bp_integration_privileges ))
    {
        $args[0] = $moderator_skills[ $args[1] ];
    }
    return $args[0];
}
add_filter('bb_current_user_can','bp_integration_moderators_privileges',10,25);
?&gt;</pre>]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/how-to-create-private-and-moderated-forums-buddypress-and-bbpress/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>