<?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>One Touch Innovation &#187; Scripting</title>
	<atom:link href="http://www.onetouchinnovation.com/category/scripting/feed" rel="self" type="application/rss+xml" />
	<link>http://www.onetouchinnovation.com</link>
	<description>Home of OtO</description>
	<lastBuildDate>Tue, 04 Dec 2007 13:04:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Extending BBPress Private Forums</title>
		<link>http://www.onetouchinnovation.com/extending-bbpress-private-forums.html</link>
		<comments>http://www.onetouchinnovation.com/extending-bbpress-private-forums.html#comments</comments>
		<pubDate>Mon, 29 Oct 2007 21:22:48 +0000</pubDate>
		<dc:creator>Antoine Khater</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[bbpress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[private forums]]></category>

		<guid isPermaLink="false">http://www.onetouchinnovation.com//extending-bbpress-private-forums</guid>
		<description><![CDATA[Disclaimer This is based on Aditya Naik &#8216;s BBPress Private forums plugin version 5.2, I needed to add a custom role to this website forums so I hacked the code. Aditya Naik is the original writer of the code and all credits goes to him. When to use this hack: If, like me, you need [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Disclaimer </strong>This is based on Aditya Naik &#8216;s <a href="http://www.adityanaik.com/projects/plugins/bb-private-forums/" target="_blank" title="BBpress Private Forums">BBPress Private forums</a> plugin version 5.2, I needed to add a custom role to this website forums so I hacked the code. Aditya Naik is the original writer of the code and all credits goes to him.</p>
<p><strong>When to use this hack: </strong>If, like me, you need to add some private forums in your BBPress setup but you don&#8217;t want to make those users moderators or administrators then here is how to add a custom role.</p>
<p><strong>Difficulty:</strong> Easy <strong>Estimated time:</strong> 10~15 min <strong>Files to edit: </strong>2</p>
<p><span id="more-13"></span></p>
<ol>
<li>Start by downloading and installing BBPress private forums plugin</li>
<li>Decide on the new role name e.g. in my case <em>Translator</em></li>
<li>In your BBPress directory open the &#8220;bb-includes&#8221; directory and backup capabilities.php</li>
<li>Open capabilities.php and go to line 135 (BBPress 0.8.3) you should have something like</li>
</ol>
<pre class="brush: php;">
'member' =&gt; array(
'name' =&gt; __('Member'),
'capabilities' =&gt; array(
'participate' =&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
)),
</pre>
<p>This is the definition of a <em><strong>member</strong></em> for BBPress.</p>
<ol start="5">
<li>Copy these lines and paste them directly after this section then replace the word &#8216;member&#8217; in the first 2 lines by the desired new role name i.e. <em><strong>Translator</strong></em> in my case. Your code should now look like</li>
</ol>
<pre class="brush: php;">
'translator' =&gt; array(
'name' =&gt; __('Translator'),
'capabilities' =&gt; array(
'participate' =&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
)),

'member' =&gt; array(
'name' =&gt; __('Member'),
'capabilities' =&gt; array(
'participate' =&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
)),
</pre>
<p>Wonderful ! what we did so far is crating a new role &#8220;translator&#8221; that is exactly the same as &#8220;member&#8221;. Let&#8217;s now define a new privilege, the new privilege I need for this role is to be able to read the &#8220;Translator&#8217;s forum&#8221; so I defined it as</p>
<pre class="brush: php;">'read_translators_forums' =&gt; true</pre>
<ol start="6">
<li>Add this new created privileged to <strong>EVERY</strong> role already defined in capabilities.php that should read that forum. I added this privilege to all roles but members. For instance my &#8216;translators&#8217; role now looks like that</li>
</ol>
<pre class="brush: php;">
'translator' =&gt; array(
'name' =&gt; __('Translator'),
'capabilities' =&gt; array(
'participate' =&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_translators_forums' =&gt; true,
'read' =&gt; true
)),
</pre>
<p>Notice the coma &#8220;,&#8221; after the priviledge don&#8217;t forget to add it.</p>
<ol start="7">
<li>Good now save your capabilities.php</li>
<li>Browse to BBpress\my-plugins\private-forums and backup private-forums.php</li>
<li>Open private-forums.php</li>
<li>Locate</li>
</ol>
<pre class="brush: php;">
function private_forums_display_role_dropdown($name, $index, $role)
</pre>
<p>and <strong>add</strong> to the select list your new created role, in my case</p>
<pre class="brush: xml;">
&lt;option value=&quot;TRANSLATOR&quot; &lt;?php echo ($role == 'TRANSLATOR') ? 'selected' : '' ; ?&gt;&gt;Translators&lt;/option&gt;
</pre>
<p>My Select list looks like</p>
<pre class="brush: xml;">

&lt;select name=&quot;&lt;?php echo $name . '[' . $index . ']'; ?&gt;&quot; id=&quot;&lt;?php echo $name . '_' . $index ; ?&gt;&quot;&gt;   &lt;option ($role=&quot;=&quot; value=&quot;OPEN&quot;&gt;&gt;Open to all&lt;/option&gt;   &lt;option ($role=&quot;=&quot; value=&quot;MEMBER&quot;&gt;&gt;Registered Members&lt;/option&gt; &lt;option ($role=&quot;=&quot; value=&quot;TRANSLATOR&quot;&gt;&gt;Translators&lt;/option&gt;   &lt;option ($role=&quot;=&quot; value=&quot;MODERATOR&quot;&gt;&gt;Moderators&lt;/option&gt;   &lt;option ($role=&quot;=&quot; value=&quot;ADMINISTRATOR&quot;&gt;&gt;Administrators&lt;/option&gt;  &lt;/select&gt;</pre>
<p>Ok we&#8217;re almost there</p>
<ol start="11">
<li>Now locate</li>
</ol>
<pre class="brush: php;">

function private_forums_check_user_access_to_forum($access) {
</pre>
<p>and add a case for your newly created role with the newly created privilege something like</p>
<pre class="brush: php;">

case 'TRANSLATOR':
return bb_current_user_can('read_translators_forums');
break;
</pre>
<p>My function is</p>
<pre class="brush: php;">

function private_forums_check_user_access_to_forum($access) {
switch($access) {
case 'MODERATOR':
return bb_current_user_can('moderate');
break;
case 'ADMINISTRATOR':
return bb_current_user_can('administrate');
break;
case 'MEMBER':
return bb_current_user_can('participate');
break;
case 'TRANSLATOR':
return bb_current_user_can('read_translators_forums');
break;
case 'OPEN':
return true;
break;
default:
return true;
}
</pre>
<p>All you still have to do now is activate the plugin and enjoy it.</p>
<p><strong>N.B.:</strong> If you feel uneasy about editing <em>capabilities.php </em>there is another (better?) way to <a href="http://bbpress.org/forums/topic/adding-a-new-user-type?replies=6#post-9210" target="_blank">add a role using a bbpress</a> plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onetouchinnovation.com/extending-bbpress-private-forums.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
