@@ -94,16 +94,26 @@ function start_test() {
9494
9595 $ wpephpc = new \WPEPHPCompat ( __DIR__ );
9696
97+ foreach ( array ( 'test_version ' , 'only_active ' ) as $ key ) {
98+ if ( isset ( $ _POST [ $ key ] ) ) {
99+ $ $ key = sanitize_text_field ( $ _POST [ $ key ] );
100+ }
101+ }
102+
103+ // New scan!
97104 if ( isset ( $ _POST ['startScan ' ] ) ) {
98- $ test_version = sanitize_text_field ( $ _POST [ ' test_version ' ] );
99- $ only_active = sanitize_text_field ( $ _POST [ ' only_active ' ] );
105+ // Make sure we clean up after the last test.
106+ $ wpephpc -> clean_after_scan ( );
100107
108+ // Fork so we can close the connection.
109+ $ this ->fork_scan ( $ test_version , $ only_active );
110+ } else {
101111 $ wpephpc ->test_version = $ test_version ;
102112 $ wpephpc ->only_active = $ only_active ;
103- $ wpephpc ->clean_after_scan ();
113+
114+ $ wpephpc ->start_test ();
104115 }
105116
106- $ wpephpc ->start_test ();
107117 wp_die ();
108118 }
109119 }
@@ -162,6 +172,40 @@ function check_status() {
162172 }
163173 }
164174
175+ /**
176+ * Make an Ajax call to start the scan in the background.
177+ *
178+ * @since 1.3.2
179+ * @param string $test_version Version of PHP to test.
180+ * @param string $only_active Scan only active plugins or all?
181+ * @return null
182+ */
183+ function fork_scan ( $ test_version , $ only_active ) {
184+ $ query = array (
185+ 'action ' => 'wpephpcompat_start_test ' ,
186+ );
187+
188+ // Keep track of these variables.
189+ $ body = array (
190+ 'test_version ' => $ test_version ,
191+ 'only_active ' => $ only_active ,
192+ );
193+
194+ // Instantly return!
195+ $ args = array (
196+ 'timeout ' => 0.01 ,
197+ 'blocking ' => false ,
198+ 'body ' => $ body ,
199+ 'cookies ' => $ _COOKIE ,
200+ 'sslverify ' => apply_filters ( 'https_local_ssl_verify ' , false ),
201+ );
202+
203+ // Build our URL.
204+ $ url = add_query_arg ( $ query , admin_url ( 'admin-ajax.php ' ) );
205+ // POST.
206+ wp_remote_post ( esc_url_raw ( $ url ), $ args );
207+ }
208+
165209 /**
166210 * Remove all database options from the database.
167211 *
0 commit comments