@@ -78,16 +78,27 @@ function start_test() {
7878
7979 $ wpephpc = new \WPEPHPCompat ( __DIR__ );
8080
81+ foreach ( array ( 'test_version ' , 'only_active ' ) as $ key ) {
82+ if ( isset ( $ _POST [ $ key ] ) ) {
83+ $ $ key = sanitize_text_field ( $ _POST [ $ key ] );
84+ }
85+ }
86+
87+ // New scan!
8188 if ( isset ( $ _POST ['startScan ' ] ) ) {
82- $ test_version = sanitize_text_field ( $ _POST [ ' test_version ' ] );
83- $ only_active = sanitize_text_field ( $ _POST [ ' only_active ' ] );
89+ // Make sure we clean up after the last test.
90+ $ wpephpc -> clean_after_scan ( );
8491
92+ // Fork so we can close the connection.
93+ $ this ->fork_scan ( $ test_version , $ only_active );
94+ }
95+ else {
8596 $ wpephpc ->test_version = $ test_version ;
8697 $ wpephpc ->only_active = $ only_active ;
87- $ wpephpc ->clean_after_scan ();
98+
99+ $ wpephpc ->start_test ();
88100 }
89101
90- $ wpephpc ->start_test ();
91102 wp_die ();
92103 }
93104 }
@@ -147,6 +158,41 @@ function check_status() {
147158 wp_die ();
148159 }
149160 }
161+
162+ /**
163+ * Make an Ajax call to start the scan in the background.
164+ *
165+ * @since 1.1.2
166+ * @param string $test_version Version of PHP to test.
167+ * @param string $only_active Scan only active plugins or all?
168+ * @return null
169+ */
170+ function fork_scan ( $ test_version , $ only_active ) {
171+ $ query = array (
172+ 'action ' => 'wpephpcompat_start_test ' ,
173+ );
174+
175+ // Keep track of these variables.
176+ $ body = array (
177+ 'test_version ' => $ test_version ,
178+ 'only_active ' => $ only_active ,
179+ );
180+
181+ // Instantly return!
182+ $ args = array (
183+ 'timeout ' => 0.01 ,
184+ 'blocking ' => false ,
185+ 'body ' => $ body ,
186+ 'cookies ' => $ _COOKIE ,
187+ 'sslverify ' => apply_filters ( 'https_local_ssl_verify ' , false ),
188+ );
189+
190+ // Build our URL.
191+ $ url = add_query_arg ( $ query , admin_url ( 'admin-ajax.php ' ) );
192+
193+ // POST.
194+ wp_remote_post ( esc_url_raw ( $ url ), $ args );
195+ }
150196
151197 /**
152198 * Create custom post type to store the directories we need to process.
0 commit comments