<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][6302] trunk/bp-core/bp-core-caps.php: Capabilities:</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/6302">6302</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2012-09-04 13:45:36 +0000 (Tue, 04 Sep 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Capabilities:

* Deprecate role code (was not used in 1.6)
* Update existing capabilities code for parity with bbPress.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcorecapsphp">trunk/bp-core/bp-core-caps.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcorecapsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-caps.php (6301 => 6302)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-caps.php        2012-09-04 02:24:31 UTC (rev 6301)
+++ trunk/bp-core/bp-core-caps.php        2012-09-04 13:45:36 UTC (rev 6302)
</span><span class="lines">@@ -11,41 +11,6 @@
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Adds BuddyPress-specific user roles.
- *
- * This is called on plugin activation.
- *
- * @since BuddyPress (1.6)
- *
- * @uses get_option() To get the default role
- * @uses get_role() To get the default role object
- * @uses add_role() To add our own roles
- * @uses do_action() Calls 'bp_add_roles'
- */
-function bp_add_roles() {
-
-        // Get new role names
-        $moderator_role   = bp_get_moderator_role();
-        $participant_role = bp_get_participant_role();
-
-        // Add the Moderator role and add the default role caps.
-        // Mod caps are added by the bp_add_caps() function
-        $default = get_role( get_option( 'default_role' ) );
-
-        // If role does not exist, default to read cap
-        if ( empty( $default-&gt;capabilities ) )
-                $default-&gt;capabilities = array( 'read' );
-
-        // Moderators are default role + community moderating caps in bp_add_caps()
-        add_role( $moderator_role,   'Community Moderator',   $default-&gt;capabilities );
-
-        // Forum Subscribers are auto added to sites with global communities
-        add_role( $participant_role, 'Community Participant', $default-&gt;capabilities );
-
-        do_action( 'bp_add_roles' );
-}
-
-/**
</del><span class="cx">  * Adds capabilities to WordPress user roles.
</span><span class="cx">  *
</span><span class="cx">  * This is called on plugin activation.
</span><span class="lines">@@ -63,15 +28,10 @@
</span><span class="cx">         if ( ! isset( $wp_roles ) )
</span><span class="cx">                 $wp_roles = new WP_Roles();
</span><span class="cx"> 
</span><del>-        // Loop through available roles
-        foreach( $wp_roles-&gt;roles as $role =&gt; $details ) {
-
-                // Load this role
-                $this_role = get_role( $role );
-
-                // Loop through caps for this role and remove them
-                foreach ( bp_get_caps_for_role( $role ) as $cap ) {
-                        $this_role-&gt;add_cap( $cap );
</del><ins>+        // Loop through available roles and add them
+        foreach( $wp_roles-&gt;role_objects as $role ) {
+                foreach ( bp_get_caps_for_role( $role-&gt;name ) as $cap ) {
+                        $role-&gt;add_cap( $cap );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -96,15 +56,10 @@
</span><span class="cx">         if ( ! isset( $wp_roles ) )
</span><span class="cx">                 $wp_roles = new WP_Roles();
</span><span class="cx"> 
</span><del>-        // Loop through available roles
-        foreach( $wp_roles-&gt;roles as $role =&gt; $details ) {
-
-                // Load this role
-                $this_role = get_role( $role );
-
-                // Loop through caps for this role and remove them
-                foreach ( bp_get_caps_for_role( $role ) as $cap ) {
-                        $this_role-&gt;remove_cap( $cap );
</del><ins>+        // Loop through available roles and remove them
+        foreach( $wp_roles-&gt;role_objects as $role ) {
+                foreach ( bp_get_caps_for_role( $role-&gt;name ) as $cap ) {
+                        $role-&gt;remove_cap( $cap );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -112,31 +67,6 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Removes BuddyPress-specific user roles.
- *
- * This is called on plugin deactivation.
- *
- * @since BuddyPress (1.6)
- *
- * @uses remove_role() To remove our roles
- * @uses do_action() Calls 'bp_remove_roles'
- */
-function bp_remove_roles() {
-
-        // Get new role names
-        $moderator_role   = bp_get_moderator_role();
-        $participant_role = bp_get_participant_role();
-
-        // Remove the Moderator role
-        remove_role( $moderator_role );
-
-        // Remove the Moderator role
-        remove_role( $participant_role );
-
-        do_action( 'bp_remove_roles' );
-}
-
-/**
</del><span class="cx">  * Maps community caps to built in WordPress caps
</span><span class="cx">  *
</span><span class="cx">  * @since BuddyPress (1.6)
</span><span class="lines">@@ -183,10 +113,6 @@
</span><span class="cx">  */
</span><span class="cx"> function bp_get_caps_for_role( $role = '' ) {
</span><span class="cx"> 
</span><del>-        // Get new role names
-        $moderator_role   = bp_get_moderator_role();
-        $participant_role = bp_get_participant_role();
-
</del><span class="cx">         // Which role are we looking for?
</span><span class="cx">         switch ( $role ) {
</span><span class="cx"> 
</span><span class="lines">@@ -199,23 +125,10 @@
</span><span class="cx"> 
</span><span class="cx">                         break;
</span><span class="cx"> 
</span><del>-                // Moderator
-                case $moderator_role :
-                        $caps = array(
-                                // Misc
-                                'bp_moderate',
-                        );
-
-                        break;
-
-                // WordPress Core Roles
</del><span class="cx">                 case 'editor'          :
</span><span class="cx">                 case 'author'          :
</span><span class="cx">                 case 'contributor'     :
</span><span class="cx">                 case 'subscriber'      :
</span><del>-
-                // BuddyPress Participant Role
-                case $participant_role :
</del><span class="cx">                 default                :
</span><span class="cx">                         $caps = array();
</span><span class="cx">                         break;
</span><span class="lines">@@ -241,130 +154,22 @@
</span><span class="cx">  *
</span><span class="cx">  * @return If user is not spam/deleted or is already capable
</span><span class="cx">  */
</span><del>-function bp_global_access_auto_role() {
</del><ins>+function bbp_set_current_user_default_role() {
</ins><span class="cx"> 
</span><del>-        // Bail if not multisite or community is not global
-        if ( !is_multisite() || !bp_allow_global_access() )
</del><ins>+        // Bail if not multisite or not root blog
+        if ( ! is_multisite() || ! bp_is_root_blog() )
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><del>-        // Bail if user is not active
-        if ( bp_is_user_inactive() )
</del><ins>+        // Bail if user is not logged in or already a member
+        if ( ! is_user_logged_in() || is_user_member_of_blog() )
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><del>-        // Bail if user is not logged in
-        if ( !is_user_logged_in() )
-                return;
-
-        // Give the user the 'Forum Participant' role
-        if ( current_user_can( 'bp_masked' ) ) {
-                global $bp;
-
-                // Get the default role
-                $default_role = bp_get_participant_role();
-
-                // Set the current users default role
-                $bp-&gt;current_user-&gt;set_role( $default_role );
-        }
-}
-
-/**
- * The participant role for registered users without roles
- *
- * This is primarily for multisite compatibility when users without roles on
- * sites that have global communities enabled
- *
- * @since BuddyPress (1.6)
- *
- * @param string $role
- * @uses apply_filters()
- * @return string
- */
-function bp_get_participant_role() {
-
-        // Hardcoded participant role
-        $role = 'bp_participant';
-
-        // Allow override
-        return apply_filters( 'bp_get_participant_role', $role );
-}
-
-/**
- * The moderator role for BuddyPress users
- *
- * @since BuddyPress (1.6)
- *
- * @param string $role
- * @uses apply_filters()
- * @return string
- */
-function bp_get_moderator_role() {
-
-        // Hardcoded moderated user role
-        $role = 'bp_moderator';
-
-        // Allow override
-        return apply_filters( 'bp_get_moderator_role', $role );
-}
-
-/**
- * Add the default role and mapped BuddyPress caps to the current user if needed
- *
- * This function will bail if the community is not global in a multisite
- * installation of WordPress, or if the user is marked as spam or deleted.
- *
- * @since BuddyPress (1.6)
- *
- * @uses is_multisite()
- * @uses bp_allow_global_access()
- * @uses bp_is_user_inactive()
- * @uses is_user_logged_in()
- * @uses current_user_can()
- * @uses get_option()
- * @uses bp_get_caps_for_role()
- *
- * @global BuddyPress $bp
- * @return If not multisite, not global, or user is deleted/spammed
- */
-function bp_global_access_role_mask() {
-
-        // Bail if not multisite or community is not global
-        if ( !is_multisite() || !bp_allow_global_access() )
-                return;
-
-        // Bail if user is marked as spam or is deleted
</del><ins>+        // Bail if user is not active
</ins><span class="cx">         if ( bp_is_user_inactive() )
</span><span class="cx">                 return;
</span><span class="cx"> 
</span><del>-        // Normal user is logged in but has no caps
-        if ( is_user_logged_in() &amp;&amp; !current_user_can( 'read' ) ) {
-
-                // Define local variable
-                $mapped_meta_caps = array();
-
-                // Assign user the minimal participant role to map caps to
-                $default_role  = bp_get_participant_role();
-
-                // Get BuddyPress caps for the default role
-                $caps_for_role = bp_get_caps_for_role( $default_role );
-
-                // Set all caps to true
-                foreach ( $caps_for_role as $cap ) {
-                        $mapped_meta_caps[$cap] = true;
-                }
-
-                // Add 'read' cap just in case
-                $mapped_meta_caps['read']      = true;
-                $mapped_meta_caps['bp_masked'] = true;
-
-                // Allow global access caps to be manipulated
-                $mapped_meta_caps = apply_filters( 'bp_global_access_mapped_meta_caps', $mapped_meta_caps );
-
-                // Assign the role and mapped caps to the current user
-                global $bp;
-                $bp-&gt;current_user-&gt;roles[0] = $default_role;
-                $bp-&gt;current_user-&gt;caps     = $mapped_meta_caps;
-                $bp-&gt;current_user-&gt;allcaps  = $mapped_meta_caps;
-        }
</del><ins>+        // Set the current users default role
+        buddypress()-&gt;current_user-&gt;set_role( bp_get_option( 'default_role', 'subscriber' ) );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -423,4 +228,56 @@
</span><span class="cx"> }
</span><span class="cx"> add_filter( 'user_has_cap', '_bp_enforce_bp_moderate_cap_for_admins', 10, 3 );
</span><span class="cx"> 
</span><del>-?&gt;
</del><ins>+/** Deprecated ****************************************************************/
+
+/**
+ * Adds BuddyPress-specific user roles.
+ *
+ * This is called on plugin activation.
+ *
+ * @since BuddyPress (1.6)
+ *
+ * @deprecated since version 1.7
+ */
+function bp_add_roles() {
+        _doing_it_wrong( 'bp_add_roles', __( 'Special community roles no longer exist. Use mapped capabilities instead', 'buddypress' ), '1.7' );
+}
+
+/**
+ * Removes BuddyPress-specific user roles.
+ *
+ * This is called on plugin deactivation.
+ *
+ * @since BuddyPress (1.6)
+ *
+ * @deprecated since version 1.7
+ */
+function bp_remove_roles() {
+        _doing_it_wrong( 'bp_remove_roles', __( 'Special community roles no longer exist. Use mapped capabilities instead', 'buddypress' ), '1.7' );
+}
+
+
+/**
+ * The participant role for registered users without roles
+ *
+ * This is primarily for multisite compatibility when users without roles on
+ * sites that have global communities enabled
+ *
+ * @since BuddyPress (1.6)
+ *
+ * @deprecated since version 1.7
+ */
+function bp_get_participant_role() {
+        _doing_it_wrong( 'bp_get_participant_role', __( 'Special community roles no longer exist. Use mapped capabilities instead', 'buddypress' ), '1.7' );
+}
+
+/**
+ * The moderator role for BuddyPress users
+ *
+ * @since BuddyPress (1.6)
+ *
+ * @deprecated since version 1.7
+ */
+function bp_get_moderator_role() {
+        _doing_it_wrong( 'bp_get_moderator_role', __( 'Special community roles no longer exist. Use mapped capabilities instead', 'buddypress' ), '1.7' );
+}
</ins></span></pre>
</div>
</div>

</body>
</html>