diff --git a/bin/modify-profile-data.php b/bin/modify-profile-data.php new file mode 100644 index 0000000..fc55035 --- /dev/null +++ b/bin/modify-profile-data.php @@ -0,0 +1,104 @@ +prepare( " + SELECT id, value + FROM `$table` + WHERE field_id = %d", + XProfile\FIELD_IDS['team_names'] + ); + + $rows = $wpdb->get_results( $query, ARRAY_A ); + + foreach ( $rows as $row ) { + $updated = false; + $chosen_teams = (array) maybe_unserialize( $row['value'] ); + + if ( empty( $chosen_teams ) ) { + continue; + } + + $original_team_count = count( $chosen_teams ); // Can't do this in the loop because it would be reduced when team are removed. + + for ( $i = 0; $i < $original_team_count; $i++ ) { + /* + * Postfix 'Team' to all team names -- e.g., 'Support' => 'Support Team' -- to make it obvious that + * we're referring to an official Make team, not supporting a private plugin/theme. + */ + if ( 'Team' !== substr( $chosen_teams[ $i ], -4 ) ) { + $updated = true; + $chosen_teams[ $i ] .= ' Team'; + } + + // Clarify name of Theme Review Team to remove ambiguity. + if ( 'Themes Team' === $chosen_teams[ $i ] ) { + $updated = true; + $chosen_teams[ $i ] = 'Theme Review Team'; + } + + // Clarify name of WP-CLI Team to remove ambiguity. + if ( 'CLI Team' === $chosen_teams[ $i ] ) { + $updated = true; + $chosen_teams[ $i ] = 'WP-CLI Team'; + } + + // Remove users from closed groups, because the vast majority of them are not actually members. + if ( 'Plugins Team' === $chosen_teams[ $i ] || 'Security Team' === $chosen_teams[ $i ] ) { + $updated = true; + unset( $chosen_teams[ $i ] ); + } + } + + if ( $updated ) { + // Reindex the array after `unset()`, otherwise `serialize()` will create blank items. + $chosen_teams = array_values( $chosen_teams ); + + $wpdb->update( + $table, + array( 'value' => maybe_serialize( $chosen_teams ) ), + array( 'id' => $row['id'] ) + ); + } + } +}