Making WordPress.org


Ignore:
Timestamp:
09/20/2018 08:08:57 AM (8 years ago)
Author:
vedjain
Message:

Profiles Association Handler: Add handler for meetup-organizer association.

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

    r1458 r7683  
    156156                                        $association_id = $this->handle_wordcamp_association();
    157157                                        break;
     158                                case 'meetups' :
     159                                        $association_id = $this->handle_meetup_association();
     160                                        break;
    158161                                case 'polyglots':
    159162                                        $association_id = $this->handle_polyglots_association();
     
    212215
    213216                /**
     217                 * Handles incoming associations for Meetup.
     218                 *
     219                 * Payload: (beyond 'action' and 'source')
     220                 *  users:       List of users login
     221                 *  association: Group slug
     222                 * @return int|string
     223                 */
     224                private function handle_meetup_association() {
     225
     226                        if ( ( ! isset( $_POST['users'] ) || ( ! is_array( $_POST['users'] ) ) ) ) {
     227                                return '-1 Users does not exist: ';
     228                        }
     229
     230                        $association = sanitize_key( $_POST['association'] );
     231                        $associated_associations = array( 'meetup-organizer' );
     232
     233                        if ( ! in_array( $association, $associated_associations ) ) {
     234                                return '-1 Unrecognized association type';
     235                        }
     236
     237                        if ( ! $group_id = BP_Groups_Group::group_exists( $association ) ) {
     238                                return '-1 Association does not exist: ' . $association;
     239                        }
     240
     241                        foreach ( $_POST['users'] as $user ) {
     242                                $user = get_user_by( 'login', $user );
     243                                if ( 'add' == $_POST['command'] ) {
     244                                        groups_join_group( $group_id, $user->ID );
     245                                        groups_accept_invite( $user->ID, $group_id );
     246                                } elseif ( 'remove' == $_POST['command'] ) {
     247                                        groups_leave_group( $group_id, $user->ID );
     248                                } else {
     249                                        return '-1 Unknown association command';
     250                                }
     251                        }
     252
     253                        return 1;
     254
     255                }
     256
     257                /**
    214258                 * Handles incoming associations for Polyglots/translate.wordpress.org.
    215259                 *
Note: See TracChangeset for help on using the changeset viewer.