Skip to content

Commit 4492532

Browse files
committed
Add clean up button and logic.
1 parent 292f9f1 commit 4492532

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/js/run.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jQuery( document ).ready(function($) {
3535
$( '.spinner' ).show();
3636
// Empty the results textarea.
3737
resetDisplay();
38-
$( '#footer' ).hide();
3938
test_version = $( 'input[name=phptest_version]:checked' ).val();
4039
only_active = $( 'input[name=active_plugins]:checked' ).val();
4140
var data = {
@@ -53,6 +52,15 @@ jQuery( document ).ready(function($) {
5352
checkStatus();
5453
});
5554
});
55+
56+
$( '#cleanupButton' ).on( 'click', function() {
57+
clearTimeout( timer );
58+
jQuery.get( ajaxurl, { 'action': 'wpephpcompat_clean_up' }, function() {
59+
resetDisplay();
60+
checkStatus();
61+
});
62+
});
63+
5664
});
5765
/**
5866
* Check the scan status and display results if scan is done.
@@ -109,7 +117,7 @@ function checkStatus() {
109117
// Server responded correctly, but the response wasn't valid.
110118
if ( 200 === xhr.status ) {
111119
alert( "Error: " + error + "\nResponse: " + xhr.responseText );
112-
}
120+
}
113121
else { // Server didn't respond correctly.
114122
alert( "Error: " + error + "\nStatus: " + xhr.status );
115123
}
@@ -126,6 +134,7 @@ function resetDisplay() {
126134
jQuery( '#standardMode' ).html('');
127135
jQuery( '#wpe-progress-count' ).text('');
128136
jQuery( '#wpe-progress-active' ).text('');
137+
jQuery( '#footer' ).hide();
129138
}
130139
/**
131140
* Loop through a string and count the total matches.

wpengine-phpcompat.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public static function init() {
6060
add_action( 'wp_ajax_wpephpcompat_start_test', array( self::instance(), 'start_test' ) );
6161
add_action( 'wp_ajax_wpephpcompat_check_status', array( self::instance(), 'check_status' ) );
6262
add_action( 'wpephpcompat_start_test_cron', array( self::instance(), 'start_test' ) );
63+
add_action( 'wp_ajax_wpephpcompat_clean_up', array( self::instance(), 'clean_up' ) );
6364

6465
// Create custom post type.
6566
add_action( 'init', array( self::instance(), 'create_job_queue' ) );
@@ -147,6 +148,21 @@ function check_status() {
147148
}
148149
}
149150

151+
/**
152+
* Remove all database options from the database.
153+
*
154+
* @since 1.3.2
155+
* @action wp_ajax_wpephpcompat_clean_up
156+
*/
157+
function clean_up() {
158+
if ( current_user_can( 'manage_options' ) || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
159+
$wpephpc = new \WPEPHPCompat( __DIR__ );
160+
$wpephpc->clean_after_scan();
161+
delete_option( 'wpephpcompat.scan_results' );
162+
wp_send_json( 'success' );
163+
}
164+
}
165+
150166
/**
151167
* Create custom post type to store the directories we need to process.
152168
*
@@ -301,7 +317,9 @@ function settings_page() {
301317
</p>
302318
<p>
303319
<input style="float: left;" name="run" id="runButton" type="button" value="<?php esc_attr_e( 'Run', 'php-compatibility-checker' ); ?>" class="button-primary" />
304-
<div style="display:none; visibility: visible; float: none;" class="spinner"></div>
320+
<div class="wpe-tooltip"><input style="float: left; margin-left: 5px;" name="run" id="cleanupButton" type="button" value="<?php esc_attr_e( 'Clean up', 'php-compatibility-checker' ); ?>" class="button" />
321+
<span class="wpe-tooltiptext">This will remove all database options related to this plugin, but it will not stop a scan in progress. If you'd like to completly remove all data wait for the scan to finish before hitting this button.</span></div>
322+
<div style="display:none; visibility: visible; float: left;" class="spinner"></div>
305323
</p>
306324
</div>
307325

0 commit comments

Comments
 (0)