Making WordPress.org

Changeset 1408


Ignore:
Timestamp:
03/17/2015 09:50:09 PM (10 years ago)
Author:
ocean90
Message:

Profiles: Add association handler for Polyglots.

see #519.

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

    r438 r1408  
    140140                    $association_id = $this->handle_wordcamp_association();
    141141                    break;
     142                case 'polyglots':
     143                    $association_id = $this->handle_polyglots_association();
     144                    break;
    142145                default:
    143146                    $association_id = '-1 Unrecognized association source.';
     
    192195        }
    193196
     197        /**
     198         * Handles incoming associations for Polyglots/translate.wordpress.org.
     199         *
     200         * Payload: (beyond 'action' and 'source')
     201         *  user_id:     User ID
     202         *  association: Slug for group/association
     203         *  command:     Either 'add' or 'remove'
     204         */
     205        private function handle_polyglots_association() {
     206            $user = get_user_by( 'id', $_POST['user_id'] );
     207
     208            if ( ! $user ) {
     209                return '-1 Association reported for unrecognized user: ' . sanitize_text_field( $_POST['user_id'] );
     210            }
     211
     212            $association = sanitize_key( $_POST['association'] );
     213
     214            $associated_associations = array( 'translation-editor', 'translation-contributor' );
     215
     216            if ( ! in_array( $association, $associated_associations ) ) {
     217                return '-1 Unrecognized association type';
     218            }
     219
     220            if ( ! $group_id = BP_Groups_Group::group_exists( $association ) ) {
     221                return '-1 Association does not exist: ' . $association;
     222            }
     223
     224            if ( 'add' == $_POST['command'] ) {
     225                groups_join_group( $group_id, $user->ID );
     226                groups_accept_invite( $user->ID, $group_id );
     227            } elseif ( 'remove' == $_POST['command'] ) {
     228                groups_leave_group( $group_id, $user->ID );
     229            } else {
     230                return '-1 Unknown association command';
     231            }
     232
     233            return 1;
     234        }
     235
    194236    } /* /class WPOrg_Profiles_Association_Handler */
    195237} /* if class_exists */
Note: See TracChangeset for help on using the changeset viewer.