Permalink
Browse files

Capabilities:

* Remove roles and move everything to mapped capabilities.
* First pass at admin-side forum capability manager.
* Deprecate moderator, anonymous, and participant roles and associated functions.
* Deprecate add/remove role/cap functions.
* More cap mapping needed for users that are not explicitly blocked.
* Adds cap check to forms for topic-tag adding/editing.
* See #1939

git-svn-id: http://bbpress.svn.wordpress.org/branches/plugin@4164 9866e705-20ec-0310-96e7-cbb4277adcfb
  • Loading branch information...
johnjamesjacoby
johnjamesjacoby committed Aug 21, 2012
1 parent 6ddbfee commit 2bb335ea1d6d31e7b3cb59b29d0b0499a1247dc8
View
@@ -63,21 +63,14 @@
add_action( 'bbp_admin_menu', 'bbp_admin_separator' );
// Activation
-add_action( 'bbp_activation', 'bbp_activating', 1 );
-add_action( 'bbp_activation', 'bbp_add_roles', 1 );
-add_action( 'bbp_activation', 'bbp_add_caps', 2 );
add_action( 'bbp_activation', 'bbp_add_options', 1 );
add_action( 'bbp_activation', 'flush_rewrite_rules' );
// Deactivation
-add_action( 'bbp_deactivation', 'bbp_remove_caps', 1 );
-add_action( 'bbp_deactivation', 'bbp_remove_roles', 2 );
add_action( 'bbp_deactivation', 'flush_rewrite_rules' );
add_action( 'bbp_deactivation', 'bbp_deactivated' );
-//
-add_action( 'bbp_new_site', 'bbp_add_roles', 2 );
-add_action( 'bbp_new_site', 'bbp_add_caps', 4 );
+// New Site
add_action( 'bbp_new_site', 'bbp_add_options', 6 );
add_action( 'bbp_new_site', 'bbp_create_initial_content', 8 );
add_action( 'bbp_new_site', 'flush_rewrite_rules' );
@@ -111,7 +104,7 @@ function bbp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
switch_to_blog( $blog_id );
// Do the bbPress activation routine
- do_action( 'bbp_new_site' );
+ do_action( 'bbp_new_site', $blog_id, $user_id, $domain, $path, $site_id, $meta );
// restore original blog
restore_current_blog();
View
@@ -97,6 +97,7 @@ private function includes() {
require( $this->admin_dir . 'bbp-forums.php' );
require( $this->admin_dir . 'bbp-topics.php' );
require( $this->admin_dir . 'bbp-replies.php' );
+ require( $this->admin_dir . 'bbp-users.php' );
}
/**
@@ -1184,20 +1185,6 @@ public static function update_screen() {
switch ( $action ) {
case 'bbpress-update' :
- // @todo more update stuff here, evaluate performance
-
- // Remove roles and caps
- bbp_remove_roles();
- bbp_remove_caps();
-
- // Make sure roles, capabilities, and options exist
- bbp_add_roles();
- bbp_add_caps();
- bbp_add_options();
-
- // Ensure any new permalinks are created
- flush_rewrite_rules();
-
// Ensure proper version in the DB
bbp_version_bump();
@@ -693,11 +693,10 @@ private function setup_globals() {
/** User Section ******************************************************/
- $default_role = ( is_multisite() && get_option( '_bbp_allow_global_access' ) ) ? bbp_get_participant_role() : get_option( 'default_role' );
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => 'role',
- 'default' => $default_role
+ 'default' => get_option( 'default_role' )
);
}
View
@@ -20,10 +20,6 @@
*/
class BBP_Users_Admin {
- /** Variables *************************************************************/
-
- /** Functions *************************************************************/
-
/**
* The bbPress users admin loader
*
@@ -32,8 +28,7 @@ class BBP_Users_Admin {
* @uses BBP_Users_Admin::setup_globals() Setup the globals needed
* @uses BBP_Users_Admin::setup_actions() Setup the hooks and actions
*/
- function __construct() {
- $this->setup_globals();
+ public function __construct() {
$this->setup_actions();
}
@@ -47,6 +42,9 @@ function __construct() {
*/
function setup_actions() {
+ // Admin styles
+ add_action( 'admin_head', array( $this, 'admin_head' ) );
+
// User profile edit/display actions
add_action( 'edit_user_profile', array( $this, 'user_profile_forums' ) );
add_action( 'show_user_profile', array( $this, 'user_profile_forums' ) );
@@ -56,14 +54,6 @@ function setup_actions() {
add_action( 'edit_user_profile_update', array( $this, 'user_profile_update' ) );
}
- /**
- * Admin globals
- *
- * @since bbPress (r2646)
- * @access private
- */
- function setup_globals() { }
-
/**
* Add some general styling to the admin area
*
@@ -74,7 +64,33 @@ function setup_globals() { }
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses sanitize_html_class() To sanitize the classes
*/
- function admin_head() { }
+ public function admin_head() {
+ ?>
+
+ <style type="text/css" media="screen">
+ /*<![CDATA[*/
+ div.bbp-user-capabilities {
+ float: left;
+ margin: 0 20px 0 0;
+ }
+ body.rtl div.bbp-user-capabilities {
+ float: right;
+ margin: 0 0 0 20px;
+ }
+
+ div.bbp-user-capabilities h4 {
+ margin: 0 0 10px;
+ }
+
+ p.bbp-default-caps-wrapper {
+ clear: both;
+ margin: 80px -10px 0;
+ }
+ /*]]>*/
+ </style>
+
+ <?php
+ }
/**
* Responsible for saving additional profile options and settings
@@ -85,7 +101,64 @@ function admin_head() { }
* @uses do_action() Calls 'bbp_user_profile_update'
* @return bool Always false
*/
- function user_profile_update( $user_id ) { }
+ public function user_profile_update( $user_id ) {
+
+ // Bail if no user
+ if ( empty( $user_id ) )
+ return;
+
+ // Load up the user
+ $user = new WP_User( $user_id );
+ $user_role = bbp_get_user_role( $user_id );
+
+ // Either reset caps for role
+ if ( ! empty( $_POST['bbp-default-caps'] ) ) {
+
+ // Remove all caps
+ foreach ( bbp_get_capability_groups() as $group ) {
+ foreach ( bbp_get_capabilities_for_group( $group ) as $capability ) {
+ $user->remove_cap( $capability );
+ }
+ }
+
+ // Maybe use users new role
+ if ( ! empty( $_POST['role'] ) ) {
+ $new_role = get_role( $_POST['role'] );
+ $new_role = isset( $new_role->name ) ? $new_role->name : '';
+
+ if ( $new_role != $user_role ) {
+ $user_role = $new_role;
+ }
+ }
+
+ // Add back caps for current role
+ if ( !empty( $user_role ) ) {
+ foreach ( bbp_get_caps_for_role( $user_role ) as $capability ) {
+ $user->add_cap( $capability );
+ }
+ }
+
+ // Or set caps individually
+ } else {
+
+ // Loop through capability groups
+ foreach ( bbp_get_capability_groups() as $group ) {
+
+ // Loop through capabilities
+ foreach ( bbp_get_capabilities_for_group( $group ) as $capability ) {
+
+ // Maybe add cap
+ if ( ! empty( $_POST['_bbp_' . $capability] ) && ! $user->has_cap( $capability ) ) {
+ $user->add_cap( $capability );
+
+ // Maybe remove cap
+ } elseif ( empty( $_POST['_bbp_' . $capability] ) && $user->has_cap( $capability ) ) {
+ $user->remove_cap( $capability );
+ }
+ }
+ }
+ }
+ }
/**
* Responsible for saving additional profile options and settings
@@ -96,6 +169,58 @@ function user_profile_update( $user_id ) { }
* @uses do_action() Calls 'bbp_user_profile_forums'
* @return bool Always false
*/
- function user_profile_forums( $profileuser ) { }
+ public function user_profile_forums( $profileuser ) {
+
+ // Bail if current user cannot edit users
+ if ( ! current_user_can( 'edit_user', $profileuser->ID ) )
+ return;
+
+ // Noop WordPress additional caps output area
+ add_filter( 'additional_capabilities_display', '__return_false' ); ?>
+
+ <h3><?php _e( 'Forum Capabilities', 'bbpress' ); ?></h3>
+
+ <table class="form-table">
+ <tbody>
+ <tr>
+ <th><?php _e( 'This user can:', 'bbpress' ); ?></th>
+
+ <td>
+ <fieldset>
+ <legend class="screen-reader-text"><span><?php _e( 'Additional Capabilities', 'bbpress' ); ?></span></legend>
+
+ <?php foreach ( bbp_get_capability_groups() as $group ) : ?>
+
+ <div class="bbp-user-capabilities">
+ <h4><?php bbp_capability_group_title( $group ); ?></h4>
+
+ <?php foreach ( bbp_get_capabilities_for_group( $group ) as $capability ) : ?>
+
+ <label for="_bbp_<?php echo $capability; ?>">
+ <input id="_bbp_<?php echo $capability; ?>" name="_bbp_<?php echo $capability; ?>" type="checkbox" id="_bbp_<?php echo $capability; ?>" value="1" <?php checked( user_can( $profileuser->ID, $capability ) ); ?> />
+ <?php bbp_capability_title( $capability ); ?>
+ </label>
+ <br />
+
+ <?php endforeach; ?>
+
+ </div>
+
+ <?php endforeach; ?>
+
+ <p class="bbp-default-caps-wrapper">
+ <input type="submit" name="bbp-default-caps" class="button" value="<?php _e( 'Reset to Default', 'bbpress' ); ?>"/>
+ </p>
+
+ </fieldset>
+ </td>
+ </tr>
+
+ </tbody>
+ </table>
+
+ <?php
+ }
}
+new BBP_Users_Admin();
endif; // class exists
Oops, something went wrong.

0 comments on commit 2bb335e

Please sign in to comment.