Skip to content

Commit 9905f34

Browse files
authored
Merge pull request #874 from WordPress/add-experimental-admin-option
Add include experimental option in admin
2 parents 4cdda05 + c384b24 commit 9905f34

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

assets/js/plugin-check-admin.js

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
return;
2323
}
2424

25+
const includeExperimental = document.getElementById(
26+
'plugin-check__include-experimental'
27+
);
28+
2529
// Handle disabling the Check it button when a plugin is not selected.
2630
function canRunChecks() {
2731
if ( '' === pluginsList.value ) {
@@ -125,6 +129,10 @@
125129
'action',
126130
pluginCheck.actionSetUpRuntimeEnvironment
127131
);
132+
pluginCheckData.append(
133+
'include-experimental',
134+
includeExperimental && includeExperimental.checked ? 1 : 0
135+
);
128136

129137
for ( let i = 0; i < data.checks.length; i++ ) {
130138
pluginCheckData.append( 'checks[]', data.checks[ i ] );
@@ -193,6 +201,10 @@
193201
pluginCheckData.append( 'nonce', pluginCheck.nonce );
194202
pluginCheckData.append( 'plugin', pluginsList.value );
195203
pluginCheckData.append( 'action', pluginCheck.actionGetChecksToRun );
204+
pluginCheckData.append(
205+
'include-experimental',
206+
includeExperimental && includeExperimental.checked ? 1 : 0
207+
);
196208

197209
for ( let i = 0; i < categoriesList.length; i++ ) {
198210
if ( categoriesList[ i ].checked ) {
@@ -291,6 +303,10 @@
291303
pluginCheckData.append( 'plugin', plugin );
292304
pluginCheckData.append( 'checks[]', check );
293305
pluginCheckData.append( 'action', pluginCheck.actionRunChecks );
306+
pluginCheckData.append(
307+
'include-experimental',
308+
includeExperimental && includeExperimental.checked ? 1 : 0
309+
);
294310

295311
return fetch( ajaxurl, {
296312
method: 'POST',

includes/Admin/Admin_AJAX.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public function set_up_environment() {
112112
$checks = is_null( $checks ) ? array() : $checks;
113113
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
114114

115+
$include_experimental = 1 === filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT );
116+
115117
try {
118+
$runner->set_experimental_flag( $include_experimental );
116119
$runner->set_check_slugs( $checks );
117120
$runner->set_plugin( $plugin );
118121

@@ -183,12 +186,13 @@ public function get_checks_to_run() {
183186
wp_send_json_error( $valid_request, 403 );
184187
}
185188

186-
$categories = filter_input( INPUT_POST, 'categories', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
187-
$categories = is_null( $categories ) ? array() : $categories;
188-
$checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
189-
$checks = is_null( $checks ) ? array() : $checks;
190-
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
191-
$runner = Plugin_Request_Utility::get_runner();
189+
$categories = filter_input( INPUT_POST, 'categories', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
190+
$categories = is_null( $categories ) ? array() : $categories;
191+
$checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
192+
$checks = is_null( $checks ) ? array() : $checks;
193+
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
194+
$include_experimental = 1 === filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT );
195+
$runner = Plugin_Request_Utility::get_runner();
192196

193197
if ( is_null( $runner ) ) {
194198
$runner = new AJAX_Runner();
@@ -203,6 +207,7 @@ public function get_checks_to_run() {
203207
}
204208

205209
try {
210+
$runner->set_experimental_flag( $include_experimental );
206211
$runner->set_check_slugs( $checks );
207212
$runner->set_plugin( $plugin );
208213
$runner->set_categories( $categories );
@@ -255,7 +260,10 @@ public function run_checks() {
255260
$checks = is_null( $checks ) ? array() : $checks;
256261
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
257262

263+
$include_experimental = 1 === filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT );
264+
258265
try {
266+
$runner->set_experimental_flag( $include_experimental );
259267
$runner->set_check_slugs( $checks );
260268
$runner->set_plugin( $plugin );
261269
$results = $runner->run();

includes/Admin/Admin_Page.php

+10
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ public function render_page() {
284284
$user_enabled_categories = get_user_setting( 'plugin_check_category_preferences', implode( '__', $this->get_default_check_categories_to_be_selected() ) );
285285
$user_enabled_categories = explode( '__', $user_enabled_categories );
286286

287+
$check_repo = new Default_Check_Repository();
288+
289+
$collection = $check_repo->get_checks( Check_Repository::TYPE_ALL | Check_Repository::INCLUDE_EXPERIMENTAL )->filter(
290+
static function ( Check $check ) {
291+
return $check->get_stability() === Check::STABILITY_EXPERIMENTAL;
292+
}
293+
);
294+
295+
$has_experimental_checks = count( $collection ) > 0;
296+
287297
require WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'templates/admin-page.php';
288298
}
289299

includes/Checker/AJAX_Runner.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ protected function get_check_exclude_slugs_param() {
104104
* @return bool Returns true to include experimental checks else false.
105105
*/
106106
protected function get_include_experimental_param() {
107-
return false;
107+
$include_experimental = filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT );
108+
return ( 1 === absint( $include_experimental ) );
108109
}
109110

110111
/**

templates/admin-page.php

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
<?php } ?>
6161
</table>
6262
<?php } ?>
63+
64+
<?php if ( $has_experimental_checks ) { ?>
65+
<h4><?php esc_attr_e( 'Other Options', 'plugin-check' ); ?></h4>
66+
<p>
67+
<label><input type="checkbox" value="include-experimental" id="plugin-check__include-experimental" /> <?php esc_html_e( 'Include Experimental Checks', 'plugin-check' ); ?></label>
68+
</p>
69+
<?php } ?>
70+
6371
</form>
6472

6573
<?php } else { ?>

0 commit comments

Comments
 (0)