@@ -84,16 +84,20 @@ public function maybe_handle_requests(): void {
8484 /**
8585 * Build HTML for OAuth connection status on settings screen.
8686 *
87- * @param string $menu_slug Settings page slug.
87+ * @param string $menu_slug Settings page slug.
88+ * @param array $query_args Optional query args for OAuth callback and button URLs.
8889 * @return string
8990 */
90- public static function get_status_html ( string $ menu_slug ): string {
91+ public static function get_status_html ( string $ menu_slug, array $ query_args = array () ): string {
9192 $ api = new Kit_API ();
9293 $ settings = new Kit_Settings ();
9394 $ settings_url = add_query_arg (
94- array (
95- 'page ' => $ menu_slug ,
96- 'tab ' => 'kit ' ,
95+ array_merge (
96+ array (
97+ 'page ' => $ menu_slug ,
98+ 'tab ' => 'kit ' ,
99+ ),
100+ $ query_args
97101 ),
98102 admin_url ( 'admin.php ' )
99103 );
@@ -127,10 +131,9 @@ public static function get_status_html( string $menu_slug ): string {
127131 );
128132 }
129133
130- $ settings ->delete_credentials ();
131-
132134 return sprintf (
133- '<p>%1$s</p><p><a class="button button-primary" href="%2$s">%3$s</a></p> ' ,
135+ '<p>%1$s</p><p>%2$s</p><p><a class="button button-primary" href="%3$s">%4$s</a></p> ' ,
136+ esc_html__ ( 'Kit is connected, but we could not verify the account right now. ' , 'glue-link ' ),
134137 esc_html ( $ account ->get_error_message () ),
135138 esc_url ( $ oauth_url ),
136139 esc_html__ ( 'Reconnect to Kit ' , 'glue-link ' )
@@ -150,10 +153,13 @@ public static function get_status_html( string $menu_slug ): string {
150153
151154 $ disconnect_url = wp_nonce_url (
152155 add_query_arg (
153- array (
154- 'page ' => $ menu_slug ,
155- 'tab ' => 'kit ' ,
156- 'glue_link_oauth_disconnect ' => 1 ,
156+ array_merge (
157+ array (
158+ 'page ' => $ menu_slug ,
159+ 'tab ' => 'kit ' ,
160+ 'glue_link_oauth_disconnect ' => 1 ,
161+ ),
162+ $ query_args
157163 ),
158164 admin_url ( 'admin.php ' )
159165 ),
@@ -191,13 +197,20 @@ private function is_settings_page(): bool {
191197 * @return string
192198 */
193199 private function get_settings_url (): string {
194- return add_query_arg (
195- array (
196- 'page ' => $ this ->menu_slug ,
197- 'tab ' => 'kit ' ,
198- ),
199- admin_url ( 'admin.php ' )
200+ $ args = array (
201+ 'page ' => $ this ->menu_slug ,
202+ 'tab ' => 'kit ' ,
200203 );
204+
205+ // Preserve wizard step, if present, so OAuth callbacks return to the intended step.
206+ if ( isset ( $ _GET ['step ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
207+ $ step = absint ( wp_unslash ( $ _GET ['step ' ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
208+ if ( $ step > 0 ) {
209+ $ args ['step ' ] = $ step ;
210+ }
211+ }
212+
213+ return add_query_arg ( $ args , admin_url ( 'admin.php ' ) );
201214 }
202215
203216 /**
0 commit comments