Changeset 11792 for sites/trunk/profiles.wordpress.org/public_html/wp-content/plugins/wporg-profiles-association-handler/wporg-profiles-association-handler.php
- Timestamp:
- 04/26/2022 05:15:59 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/profiles.wordpress.org/public_html/wp-content/plugins/wporg-profiles-association-handler/wporg-profiles-association-handler.php
r7683 r11792 161 161 case 'polyglots': 162 162 $association_id = $this->handle_polyglots_association(); 163 break; 164 case 'generic-badge': 165 $association_id = $this->handle_badge_association(); 163 166 break; 164 167 default: … … 294 297 } 295 298 299 /** 300 * Handles incoming associations for the generic '{assign|remove}_badge()' functions. See pub/profile-helpers.php. 301 * 302 * Payload: (beyond 'action' and 'source') 303 * user: User ID/email/login 304 * badge: Slug for group/association 305 * command: Either 'add' or 'remove' 306 */ 307 private function handle_badge_association() { 308 $user = wp_unslash( $_POST['user'] ?? '' ); 309 310 // Handle login/email as input.. 311 if ( ! is_numeric( $user ) ) { 312 $_user = get_user_by( 'login', $user ); 313 if ( ! $_user && is_email( $user ) ) { 314 $_user = get_user_by( 'email', $user ); 315 } 316 317 $user = $_user->ID ?? $user; 318 } 319 320 $user = get_user_by( 'id', $user ); 321 if ( ! $user ) { 322 status_header( 400 ); 323 return '-1 Association requested for unrecognized user: ' . sanitize_text_field( $_POST['user'] ); 324 } 325 326 $badge = sanitize_key( $_POST['badge'] ?? '' ); 327 $group_id = BP_Groups_Group::group_exists( $badge ); 328 if ( ! $badge || ! $group_id ) { 329 status_header( 400 ); 330 return '-1 Association does not exist: ' . $badge; 331 } 332 333 if ( 'add' == $_POST['command'] ) { 334 groups_join_group( $group_id, $user->ID ); 335 groups_accept_invite( $user->ID, $group_id ); 336 } elseif ( 'remove' == $_POST['command'] ) { 337 groups_leave_group( $group_id, $user->ID ); 338 } else { 339 status_header( 400 ); 340 return '-1 Unknown association command'; 341 } 342 343 // NOTE: Actual response from `groups_join_group()` & `groups_leave_group()` set in cookies. 344 return 1; 345 } 346 296 347 } /* /class WPOrg_Profiles_Association_Handler */ 297 348 } /* if class_exists */
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)