Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| MigrationSSO | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| get_magic_login_url | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace NewfoldLabs\WP\Module\Migration\Services; |
| 3 | |
| 4 | use NewFoldLabs\WP\Module\SSO\SSO_Helpers; |
| 5 | /** |
| 6 | * Migration SSO service |
| 7 | */ |
| 8 | class MigrationSSO { |
| 9 | |
| 10 | /** |
| 11 | * Get SSO link |
| 12 | */ |
| 13 | public static function get_magic_login_url() { |
| 14 | $args = array( |
| 15 | 'role' => 'administrator', |
| 16 | 'orderby' => 'ID', |
| 17 | 'order' => 'ASC', |
| 18 | 'number' => 1, // Limit the query to 1 user |
| 19 | 'fields' => 'ID', // Retrieve only the ID field |
| 20 | ); |
| 21 | |
| 22 | $user_query = new \WP_User_Query( $args ); |
| 23 | |
| 24 | // Get the results |
| 25 | $user_ids = $user_query->get_results(); |
| 26 | |
| 27 | // Create token |
| 28 | $token = SSO_Helpers::generateToken( $user_ids[0] ); |
| 29 | |
| 30 | // Save token |
| 31 | SSO_Helpers::saveToken( $token ); |
| 32 | |
| 33 | $query_string = http_build_query( |
| 34 | array( |
| 35 | 'action' => SSO_Helpers::ACTION, |
| 36 | 'token' => $token, |
| 37 | ) |
| 38 | ); |
| 39 | |
| 40 | $response = rest_ensure_response( admin_url( '/admin-ajax.php' ) . "?{$query_string}" ); |
| 41 | return $response; |
| 42 | } |
| 43 | } |