Changeset 12678 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin-post.php
- Timestamp:
- 06/28/2023 02:11:16 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin-post.php
r12671 r12678 21 21 $team_ids = array_map( 'intval', $team_ids ); 22 22 23 $updated = 'success'; 24 $message = null; 25 $invite = false; 23 $updated = 'success'; 24 $message = null; 25 $invite = false; 26 $github_username = false; 26 27 27 28 if ( ! $team_ids ) { 28 29 $updated = 'error'; 29 30 $message = 'No teams selected'; 30 } elseif ( 31 preg_match( '!^https://profiles.wordpress.org/(?<slug>[^/]+)!i', $input, $m ) || 32 ! is_email( $input ) 33 ) { 31 } elseif ( is_email( $input ) ) { 32 $invite = $input; 33 } elseif ( preg_match( '!^https://github.com/(?<slug>[^/]+)!i', $input, $m ) ) { 34 $gh_user = api( '/users/' . $m['slug'] ); 35 $github_username = $gh_user->login ?? false; 36 $invite = $gh_user->id ?? 0; 37 } else { 38 preg_match( '!^https://profiles.wordpress.org/(?<slug>[^/]+)!i', $input, $m ); 39 34 40 $user = get_user_by( 'slug', $m['slug'] ?? $input ); 35 $github_details = json_decode( $wpdb->get_var( $wpdb->prepare(36 'SELECT user_details FROM wporg_github_users WHERE user_id = %d',41 $github_details = $wpdb->get_row( $wpdb->prepare( 42 'SELECT github_user, user_details FROM wporg_github_users WHERE user_id = %d', 37 43 $user->ID 38 ) ) ); 44 ) ); 45 if ( $github_details ) { 46 $github_details->user_details = json_decode( $github_details->user_details ); 47 } 39 48 40 if ( ! $user || ! $github_details ) {49 if ( ! $user || ! $github_details || ! $github_details->user_details ) { 41 50 $updated = 'no-github'; 42 51 } else { 43 $invite = $github_details->id; 52 $invite = $github_details->user_details->id; 53 $github_username = $github_details->github_user; 44 54 } 45 } elseif ( is_email( $input ) ) {46 $invite = $input;47 } else {48 $updated = 'error';49 55 } 50 56 … … 52 58 $result = invite_member( $invite, $team_ids ); 53 59 54 if ( $result->id ) { 55 // Note that it was invited via this site.. 56 $invited_gh_users = get_option( 'invited_gh_users', [] ); 57 $invited_gh_users[] = $result->id; 58 update_option( 'invited_gh_users', $invited_gh_users ); 60 if ( 61 is_wp_error( $result ) && 62 $github_username && 63 'Invitee is already a part of this org' === $result->get_error_data( 'api_error' )->errors[0]->message ?? '' 64 ) { 65 // Already a GitHub member, just add them to the team. 66 $result = add_to_team( $github_username, $team_ids ); 67 $message = 'User already a GitHub member, Added to team(s).'; 68 } 59 69 60 delete_site_transient( 'gh_invites' ); 70 if ( ! is_wp_error( $result ) ) { 71 if ( ! empty( $result->id ) ) { 72 // Note that it was invited via this site.. 73 $invited_gh_users = get_option( 'invited_gh_users', [] ); 74 $invited_gh_users[] = $result->id; 75 update_option( 'invited_gh_users', $invited_gh_users ); 76 77 delete_site_transient( 'gh_invites' ); 78 } 61 79 62 80 // Log it to Slack.
Note: See TracChangeset
for help on using the changeset viewer.