Changeset 12747
- Timestamp:
- 07/18/2023 05:41:27 AM (14 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-moderators.php
r12012 r12747 21 21 add_filter( 'bbp_map_primary_meta_caps', array( $this, 'map_meta_caps' ), 10, 4 ); 22 22 add_action( 'bbp_post_request', array( $this, 'edit_user_handler' ), 0 ); 23 24 // Allow moderators to manage user roles. 25 add_filter( 'bbp_get_caps_for_role', array( $this, 'bbp_get_caps_for_role' ), 10, 2 ); 26 27 // Limit which roles a moderator can assign to a user. Before bbp_profile_update_role(). 28 add_action( 'bbp_profile_update', array( $this, 'bbp_profile_update' ), 1 ); 23 29 24 30 // Append 'view=all' to forum, topic, and reply URLs in moderator views. … … 185 191 } 186 192 187 if ( 'promote_user' === $cap || 'promote_users' === $cap ) { 188 // Only keymasters can promote users. 189 $caps = array( 'keep_gate' ); 190 } else { 191 $caps = array( 'moderate' ); 192 } 193 $caps = array( 'moderate' ); 193 194 } 194 195 break; … … 196 197 197 198 return $caps; 199 } 200 201 /** 202 * Allow (global) moderators to assign roles to users. 203 * 204 * @param array $caps Role capabilities. 205 * @param string $role Role name. 206 * @return array 207 */ 208 function bbp_get_caps_for_role( $caps, $role ) { 209 if ( 210 $role === bbp_get_moderator_role() && 211 Plugin::get_instance()->is_main_forums 212 ) { 213 $caps['promote_users'] = true; 214 } 215 216 return $caps; 217 } 218 219 /** 220 * Limit the site/forum roles a moderator can set. 221 */ 222 public function bbp_profile_update() { 223 // Keymasters need no special handling. 224 if ( bbp_is_user_keymaster( get_current_user_id() ) ) { 225 return; 226 } 227 228 $new_forum_role = sanitize_key( $_POST['bbp-forums-role'] ?? '' ); 229 230 // Prevent setting any roles. 231 unset( $_POST['role'], $_POST['bbp-forums-role'] ); 232 233 $allowed_roles = array( 234 bbp_get_participant_role(), 235 bbp_get_spectator_role(), 236 bbp_get_blocked_role() 237 ); 238 239 // If it's an allowed role, add it back so it can be processed by bbp_profile_update_role(). 240 if ( in_array( $new_forum_role, $allowed_roles, true ) ) { 241 $_POST['bbp-forums-role'] = $new_forum_role; 242 } 198 243 } 199 244 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php
r12292 r12747 42 42 43 43 /** 44 * Define whether this is the global forums, or a locale forum. 45 * ie. https://wordpress.org/support/ 46 * 47 * @var bool 48 */ 49 public $is_main_forums = false; 50 51 /** 44 52 * Always return the same instance of this plugin. 45 53 * … … 67 75 $this->audit_log = new Audit_Log; 68 76 77 // Set a flag to indicate whether this is the global forums, or a locale forum. 78 $this->is_main_forums = ( 79 defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) && 80 WPORG_SUPPORT_FORUMS_BLOGID == get_current_blog_id() 81 ); 82 69 83 // These modifications are specific to https://wordpress.org/support/ 70 $blog_id = get_current_blog_id(); 71 if ( $blog_id && defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) && WPORG_SUPPORT_FORUMS_BLOGID == $blog_id ) { 84 if ( $this->is_main_forums ) { 72 85 $this->dropin = new Dropin; 73 86 $this->support_compat = new Support_Compat; 74 87 75 88 // Only load Performance_Optimizations if necessary. 76 $this->performance = new Performance_Optimizations;89 $this->performance = new Performance_Optimizations; 77 90 78 91 // Ratings_Compat is loaded by Theme_Directory_Compat or … … 82 95 } 83 96 97 // Only load the Block Support if the Blocks Everywhere plugin is available. 84 98 if ( class_exists( 'Automattic\Blocks_Everywhere\Blocks_Everywhere' ) ) { 85 $this->blocks = new Blocks;99 $this->blocks = new Blocks; 86 100 } 87 101
Note: See TracChangeset
for help on using the changeset viewer.