Changeset 4330
- Timestamp:
- 11/04/2012 02:11:16 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/admin/users.php
r4309 r4330 49 49 // User profile edit/display actions 50 50 add_action( 'edit_user_profile', array( $this, 'secondary_role_display' ) ); 51 52 // Show advanced capabilities53 if ( bbp_use_advanced_capability_editor() ) {54 55 // Admin styles56 add_action( 'admin_head', array( $this, 'admin_head' ) );57 58 // User profile edit/display actions59 add_action( 'edit_user_profile', array( $this, 'advanced_capability_display' ) );60 61 // Noop WordPress additional caps output area62 add_filter( 'additional_capabilities_display', '__return_false' );63 }64 }65 66 /**67 * Add some general styling to the admin area68 *69 * @since bbPress (r2464)70 *71 * @uses bbp_get_forum_post_type() To get the forum post type72 * @uses bbp_get_topic_post_type() To get the topic post type73 * @uses bbp_get_reply_post_type() To get the reply post type74 * @uses sanitize_html_class() To sanitize the classes75 */76 public function admin_head() {77 ?>78 79 <style type="text/css" media="screen">80 /*<![CDATA[*/81 div.bbp-user-capabilities {82 margin: 0 10px 10px;83 display: inline-block;84 vertical-align: top;85 }86 87 div.bbp-user-capabilities h4 {88 margin: 0 0 10px;89 }90 91 p.bbp-default-caps-wrapper {92 clear: both;93 margin: 80px -10px 0;94 }95 /*]]>*/96 </style>97 98 <?php99 51 } 100 52 … … 150 102 <?php 151 103 } 152 153 /**154 * Responsible for displaying bbPress's advanced capability interface.155 *156 * Hidden by default. Must be explicitly enabled.157 *158 * @since bbPress (r2464)159 *160 * @param WP_User $profileuser User data161 * @uses do_action() Calls 'bbp_user_profile_forums'162 * @return bool Always false163 */164 public function advanced_capability_display( $profileuser ) {165 166 // Bail if current user cannot edit users167 if ( ! current_user_can( 'edit_user', $profileuser->ID ) )168 return; ?>169 170 <table class="form-table">171 <tbody>172 <tr>173 <th><?php _e( 'This user can:', 'bbpress' ); ?></th>174 175 <td>176 <fieldset>177 <legend class="screen-reader-text"><span><?php _e( 'Additional Capabilities', 'bbpress' ); ?></span></legend>178 179 <?php foreach ( bbp_get_capability_groups() as $group ) : ?>180 181 <div class="bbp-user-capabilities">182 <h4><?php bbp_capability_group_title( $group ); ?></h4>183 184 <?php foreach ( bbp_get_capabilities_for_group( $group ) as $capability ) : ?>185 186 <label for="_bbp_<?php echo $capability; ?>">187 <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 ) ); ?> />188 <?php bbp_capability_title( $capability ); ?>189 </label>190 <br />191 192 <?php endforeach; ?>193 194 </div>195 196 <?php endforeach; ?>197 198 <p class="bbp-default-caps-wrapper">199 <input type="submit" name="bbp-default-caps" class="button" value="<?php esc_attr_e( 'Reset to Default', 'bbpress' ); ?>"/>200 </p>201 202 </fieldset>203 </td>204 </tr>205 206 </tbody>207 </table>208 209 <?php210 }211 104 } 212 105 new BBP_Users_Admin(); -
trunk/includes/core/actions.php
r4316 r4330 225 225 add_action( 'make_spam_user', 'bbp_make_spam_user' ); 226 226 227 // User capabilities228 add_action( 'bbp_profile_update', 'bbp_profile_update_ capabilities' );227 // User role 228 add_action( 'bbp_profile_update', 'bbp_profile_update_role' ); 229 229 230 230 // Hook WordPress admin actions to bbPress profiles on save -
trunk/includes/core/capabilities.php
r4314 r4330 14 14 // Exit if accessed directly 15 15 if ( !defined( 'ABSPATH' ) ) exit; 16 17 /**18 * Whether or not to show advanced capability editing when editing a user.19 *20 * @since bbPress (r4290)21 *22 * @param bool $default23 * @return bool24 */25 function bbp_use_advanced_capability_editor( $default = false ) {26 return (bool) apply_filters( 'bbp_use_advanced_capability_editor', $default );27 }28 29 /** Output ********************************************************************/30 31 /**32 * Return the capability groups33 *34 * @since bbPress (r4163)35 *36 * @return array of groups37 */38 function bbp_get_capability_groups() {39 return apply_filters( 'bbp_get_capability_groups', array(40 'primary',41 'forums',42 'topics',43 'replies',44 'topic_tags'45 ) );46 }47 48 /**49 * Return capabilities for the group50 *51 * @since bbPress (r4163)52 *53 * @param string $group54 * @return array of capabilities55 */56 function bbp_get_capabilities_for_group( $group = '' ) {57 switch ( $group ) {58 case 'primary' :59 return bbp_get_primary_capabilities();60 break;61 case 'forums' :62 return bbp_get_forums_capabilities();63 break;64 case 'topics' :65 return bbp_get_topics_capabilities();66 break;67 case 'replies' :68 return bbp_get_replies_capabilities();69 break;70 case 'topic_tags' :71 return bbp_get_topic_tags_capabilities();72 break;73 default :74 return array();75 break;76 }77 }78 79 /**80 * Output the human readable capability group title81 *82 * @since bbPress (r4163)83 *84 * @param string $group85 * @uses bbp_get_capability_group_title()86 */87 function bbp_capability_group_title( $group = '' ) {88 echo bbp_get_capability_group_title( $group );89 }90 /**91 * Return the human readable capability group title92 *93 * @since bbPress (r4163)94 *95 * @param string $group96 * @return string97 */98 function bbp_get_capability_group_title( $group = '' ) {99 100 // Default return value to capability group101 $retval = $group;102 103 switch( $group ) {104 case 'primary' :105 $retval = __( 'Primary capabilities', 'bbpress' );106 break;107 case 'forums' :108 $retval = __( 'Forum capabilities', 'bbpress' );109 break;110 case 'topics' :111 $retval = __( 'Topic capabilites', 'bbpress' );112 break;113 case 'topic_tags' :114 $retval = __( 'Topic tag capabilities', 'bbpress' );115 break;116 case 'replies' :117 $retval = __( 'Reply capabilities', 'bbpress' );118 break;119 }120 121 return apply_filters( 'bbp_get_capability_group_title', $retval, $group );122 }123 124 /**125 * Output the human readable capability title126 *127 * @since bbPress (r4163)128 *129 * @param string $group130 * @uses bbp_get_capability_title()131 */132 function bbp_capability_title( $capability = '' ) {133 echo bbp_get_capability_title( $capability );134 }135 /**136 * Return the human readable capability title137 *138 * @since bbPress (r4163)139 *140 * @param string $capability141 * @return string142 */143 function bbp_get_capability_title( $capability = '' ) {144 145 // Default return value to capability146 $retval = $capability;147 148 switch( $capability ) {149 150 // Primary151 case 'spectate' :152 $retval = __( 'Spectate forum discussion', 'bbpress' );153 break;154 case 'participate' :155 $retval = __( 'Participate in forums', 'bbpress' );156 break;157 case 'moderate' :158 $retval = __( 'Moderate entire forum', 'bbpress' );159 break;160 case 'throttle' :161 $retval = __( 'Skip forum throttle check', 'bbpress' );162 break;163 case 'view_trash' :164 $retval = __( 'View items in forum trash', 'bbpress' );165 break;166 167 // Forum caps168 case 'read_forum' :169 $retval = __( 'View forum', 'bbpress' );170 break;171 case 'edit_forum' :172 $retval = __( 'Edit forum', 'bbpress' );173 break;174 case 'trash_forum' :175 $retval = __( 'Trash forum', 'bbpress' );176 break;177 case 'delete_forum' :178 $retval = __( 'Delete forum', 'bbpress' );179 break;180 case 'moderate_forum' :181 $retval = __( 'Moderate forum', 'bbpress' );182 break;183 case 'publish_forums' :184 $retval = __( 'Create forums', 'bbpress' );185 break;186 case 'edit_forums' :187 $retval = __( 'Edit their own forums', 'bbpress' );188 break;189 case 'edit_others_forums' :190 $retval = __( 'Edit all forums', 'bbpress' );191 break;192 case 'delete_forums' :193 $retval = __( 'Delete their own forums', 'bbpress' );194 break;195 case 'delete_others_forums' :196 $retval = __( 'Delete all forums', 'bbpress' );197 break;198 case 'read_private_forums' :199 $retval = __( 'View private forums', 'bbpress' );200 break;201 case 'read_hidden_forums' :202 $retval = __( 'View hidden forums', 'bbpress' );203 break;204 205 // Topic caps206 case 'read_topic' :207 $retval = __( 'View topic', 'bbpress' );208 break;209 case 'edit_topic' :210 $retval = __( 'Edit topic', 'bbpress' );211 break;212 case 'trash_topic' :213 $retval = __( 'Trash topic', 'bbpress' );214 break;215 case 'moderate_topic' :216 $retval = __( 'Moderate topic', 'bbpress' );217 break;218 case 'delete_topic' :219 $retval = __( 'Delete topic', 'bbpress' );220 break;221 case 'publish_topics' :222 $retval = __( 'Create topics', 'bbpress' );223 break;224 case 'edit_topics' :225 $retval = __( 'Edit their own topics', 'bbpress' );226 break;227 case 'edit_others_topics' :228 $retval = __( 'Edit others topics', 'bbpress' );229 break;230 case 'delete_topics' :231 $retval = __( 'Delete own topics', 'bbpress' );232 break;233 case 'delete_others_topics' :234 $retval = __( 'Delete others topics', 'bbpress' );235 break;236 case 'read_private_topics' :237 $retval = __( 'View private topics', 'bbpress' );238 break;239 240 // Reply caps241 case 'read_reply' :242 $retval = __( 'Read reply', 'bbpress' );243 break;244 case 'edit_reply' :245 $retval = __( 'Edit reply', 'bbpress' );246 break;247 case 'trash_reply' :248 $retval = __( 'Trash reply', 'bbpress' );249 break;250 case 'delete_reply' :251 $retval = __( 'Delete reply', 'bbpress' );252 break;253 case 'publish_replies' :254 $retval = __( 'Create replies', 'bbpress' );255 break;256 case 'edit_replies' :257 $retval = __( 'Edit own replies', 'bbpress' );258 break;259 case 'edit_others_replies' :260 $retval = __( 'Edit others replies', 'bbpress' );261 break;262 case 'delete_replies' :263 $retval = __( 'Delete own replies', 'bbpress' );264 break;265 case 'delete_others_replies' :266 $retval = __( 'Delete others replies', 'bbpress' );267 break;268 case 'read_private_replies' :269 $retval = __( 'View private replies', 'bbpress' );270 break;271 272 // Topic tag caps273 case 'manage_topic_tags' :274 $retval = __( 'Remove tags from topics', 'bbpress' );275 break;276 case 'edit_topic_tags' :277 $retval = __( 'Edit topic tags', 'bbpress' );278 break;279 case 'delete_topic_tags' :280 $retval = __( 'Delete topic tags', 'bbpress' );281 break;282 case 'assign_topic_tags' :283 $retval = __( 'Assign tags to topics', 'bbpress' );284 break;285 }286 287 return apply_filters( 'bbp_get_capability_title', $retval, $capability );288 }289 16 290 17 /** Mapping *******************************************************************/ -
trunk/includes/forums/capabilities.php
r4249 r4330 27 27 'delete_posts' => 'delete_forums', 28 28 'delete_others_posts' => 'delete_others_forums' 29 ) );30 }31 32 /**33 * Return forum post-type capabilities, used when registering the post type34 *35 * @since bbPress (r4163)36 *37 * @return array of forums capabilities38 */39 function bbp_get_forums_capabilities() {40 return apply_filters( 'bbp_get_forums_capabilities', array(41 'publish_forums',42 'edit_forums',43 'edit_others_forums',44 'delete_forums',45 'delete_others_forums',46 'read_private_forums',47 'read_hidden_forums'48 29 ) ); 49 30 } -
trunk/includes/replies/capabilities.php
r4249 r4330 26 26 'delete_posts' => 'delete_replies', 27 27 'delete_others_posts' => 'delete_others_replies' 28 ) );29 }30 31 /**32 * Get the reply post-type capabilities33 *34 * @since bbPress (r4163)35 *36 * @return array of replies capabilities37 */38 function bbp_get_replies_capabilities() {39 return apply_filters( 'bbp_get_replies_capabilities', array(40 'publish_replies',41 'edit_replies',42 'edit_others_replies',43 'delete_replies',44 'delete_others_replies',45 'read_private_replies'46 28 ) ); 47 29 } -
trunk/includes/topics/capabilities.php
r4249 r4330 48 48 49 49 /** 50 * Return topic post-type capabilities, used when registering the post type51 *52 * @since bbPress (r4163)53 *54 * @return array of topics capabilities55 */56 function bbp_get_topics_capabilities() {57 return apply_filters( 'bbp_get_topics_capabilities', array(58 'publish_topics',59 'edit_topics',60 'edit_others_topics',61 'delete_topics',62 'delete_others_topics',63 'read_private_topics'64 ) );65 }66 67 /**68 * Return topic-tag taxonomy capabilities, used when registering the taxonomy69 *70 * @since bbPress (r4163)71 *72 * @return array of topic-tag capabilities73 */74 function bbp_get_topic_tags_capabilities() {75 return apply_filters( 'bbp_get_topic_tags_capabilities', array(76 'manage_topic_tags',77 'edit_topic_tags',78 'delete_topic_tags',79 'assign_topic_tags'80 ) );81 }82 83 /**84 50 * Maps topic capabilities 85 51 * … … 283 249 } 284 250 285 return apply_filters( 'bbp_map_topic_ Tag_meta_caps', $caps, $cap, $user_id, $args );286 } 251 return apply_filters( 'bbp_map_topic_tag_meta_caps', $caps, $cap, $user_id, $args ); 252 } -
trunk/includes/users/capabilities.php
r4319 r4330 9 9 * @subpackage Capabilities 10 10 */ 11 12 /**13 * Get the primary bbPress capabilities14 *15 * @since bbPress (r4163)16 *17 * @return array of primary capabilities18 */19 function bbp_get_primary_capabilities() {20 return apply_filters( 'bbp_get_primary_capabilities', array(21 22 // Current caps23 'spectate',24 'participate',25 'moderate',26 'throttle',27 'view_trash',28 29 // Legacy caps30 'banned',31 'blocked',32 'bozo'33 ) );34 }35 11 36 12 /** … … 70 46 71 47 /** 72 * Remove all bbPress capabilities for a given user73 *74 * @since bbPress (r4221)75 *76 * @param int $user_id77 * @return boolean True on success, false on failure78 */79 function bbp_remove_user_caps( $user_id = 0 ) {80 81 // Bail if no user was passed82 if ( empty( $user_id ) )83 return false;84 85 // Load up the user86 $user = new WP_User( $user_id );87 88 // Remove all caps89 foreach ( bbp_get_capability_groups() as $group )90 foreach ( bbp_get_capabilities_for_group( $group ) as $capability )91 $user->remove_cap( $capability );92 93 // Success94 return true;95 }96 97 /**98 * Remove all bbPress capabilities for a given user99 *100 * @since bbPress (r4221)101 *102 * @param int $user_id103 * @return boolean True on success, false on failure104 */105 function bbp_reset_user_caps( $user_id = 0 ) {106 107 // Bail if no user was passed108 if ( empty( $user_id ) )109 return false;110 111 // Bail if current user cannot edit this user112 if ( ! current_user_can( 'edit_user', $user_id ) )113 return false;114 115 // Remove all caps for user116 bbp_remove_user_caps( $user_id );117 118 // Load up the user119 $user = new WP_User( $user_id );120 121 // User has no role so bail122 if ( ! isset( $user->roles ) )123 return false;124 125 // Use first user role126 $caps = bbp_get_caps_for_role( array_shift( $user->roles ) );127 128 // Add caps for the first role129 foreach ( $caps as $cap => $value )130 $user->add_cap( $cap, $value );131 132 // Success133 return true;134 }135 136 /**137 * Save all bbPress capabilities for a given user138 *139 * @since bbPress (r4221)140 *141 * @param type $user_id142 * @return boolean143 */144 function bbp_save_user_caps( $user_id = 0 ) {145 146 // Bail if no user was passed147 if ( empty( $user_id ) )148 return false;149 150 // Bail if current user cannot edit this user151 if ( ! current_user_can( 'edit_user', $user_id ) )152 return false;153 154 // Load up the user155 $user = new WP_User( $user_id );156 157 // Loop through capability groups158 foreach ( bbp_get_capability_groups() as $group ) {159 foreach ( bbp_get_capabilities_for_group( $group ) as $capability ) {160 161 // Maybe add cap162 if ( ! empty( $_POST['_bbp_' . $capability] ) && ! $user->has_cap( $capability ) ) {163 $user->add_cap( $capability, true );164 165 // Maybe remove cap166 } elseif ( empty( $_POST['_bbp_' . $capability] ) && $user->has_cap( $capability ) ) {167 $user->add_cap( $capability, false );168 }169 }170 }171 172 // Success173 return true;174 }175 176 /**177 48 * Helper function hooked to 'bbp_edit_user_profile_update' action to save or 178 49 * update user roles and capabilities. … … 184 55 * @usse bbp_save_user_caps() to save caps 185 56 */ 186 function bbp_profile_update_ capabilities( $user_id = 0 ) {57 function bbp_profile_update_role( $user_id = 0 ) { 187 58 188 59 // Bail if no user ID was passed … … 190 61 return; 191 62 192 // Bail if advanced capability editor is off 193 if ( ! empty( $_POST['bbp-forums-role'] ) ) { 63 // Bail if no role 64 if ( ! isset( $_POST['bbp-forums-role'] ) ) 65 return; 194 66 195 196 197 67 // Fromus role we want the user to have 68 $new_role = sanitize_text_field( $_POST['bbp-forums-role'] ); 69 $forums_role = bbp_get_user_role( $user_id ); 198 70 199 // Set the new forums role 200 if ( $new_role != $forums_role ) { 201 202 // Remove any interim form user capabilities 203 bbp_remove_user_caps( $user_id ); 204 205 // Set the users new forums role 206 bbp_set_user_role( $user_id, $new_role ); 207 } 208 } 209 210 // Save additional capabilities 211 if ( bbp_use_advanced_capability_editor() ) { 212 213 // Either reset caps for role 214 if ( ! empty( $_POST['bbp-default-caps'] ) ) { 215 bbp_reset_user_caps( $user_id ); 216 217 // Or set caps individually 218 } else { 219 bbp_save_user_caps( $user_id ); 220 } 71 // Set the new forums role 72 if ( $new_role != $forums_role ) { 73 bbp_set_user_role( $user_id, $new_role ); 221 74 } 222 75 } … … 259 112 return; 260 113 261 // Remove any interim bbPress caps262 bbp_remove_user_caps( $user_id );263 264 114 // Assign the default role to the current user 265 115 bbpress()->current_user->add_role( bbp_get_default_role() ); -
trunk/templates/bbp-default/bbpress/form-user-edit.php
r4307 r4330 148 148 <legend><?php _e( 'User Role', 'bbpress' ); ?></legend> 149 149 150 <?php do_action( 'bbp_user_edit_before_role' ); ?> 151 150 152 <?php if ( is_multisite() && is_super_admin() && current_user_can( 'manage_network_options' ) ) : ?> 151 153 … … 162 164 <?php bbp_get_template_part( 'form', 'user-roles' ); ?> 163 165 164 <?php if ( bbp_use_advanced_capability_editor() ) : ?> 165 166 <?php bbp_get_template_part( 'form', 'user-capabilities' ); ?> 167 168 <?php endif; ?> 166 <?php do_action( 'bbp_user_edit_after_role' ); ?> 169 167 170 168 </fieldset>
Note: See TracChangeset
for help on using the changeset viewer.