Skip to content

Commit

Permalink
Add experimental option in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Feb 17, 2025
1 parent c334a5f commit 4d1c189
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
16 changes: 16 additions & 0 deletions assets/js/plugin-check-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
return;
}

const includeExperimental = document.getElementById(
'plugin-check__include-experimental'
);

// Handle disabling the Check it button when a plugin is not selected.
function canRunChecks() {
if ( '' === pluginsList.value ) {
Expand Down Expand Up @@ -125,6 +129,10 @@
'action',
pluginCheck.actionSetUpRuntimeEnvironment
);
pluginCheckData.append(
'include-experimental',
includeExperimental && includeExperimental.checked ? 1 : 0
);

for ( let i = 0; i < data.checks.length; i++ ) {
pluginCheckData.append( 'checks[]', data.checks[ i ] );
Expand Down Expand Up @@ -193,6 +201,10 @@
pluginCheckData.append( 'nonce', pluginCheck.nonce );
pluginCheckData.append( 'plugin', pluginsList.value );
pluginCheckData.append( 'action', pluginCheck.actionGetChecksToRun );
pluginCheckData.append(
'include-experimental',
includeExperimental && includeExperimental.checked ? 1 : 0
);

for ( let i = 0; i < categoriesList.length; i++ ) {
if ( categoriesList[ i ].checked ) {
Expand Down Expand Up @@ -291,6 +303,10 @@
pluginCheckData.append( 'plugin', plugin );
pluginCheckData.append( 'checks[]', check );
pluginCheckData.append( 'action', pluginCheck.actionRunChecks );
pluginCheckData.append(
'include-experimental',
includeExperimental && includeExperimental.checked ? 1 : 0
);

return fetch( ajaxurl, {
method: 'POST',
Expand Down
23 changes: 17 additions & 6 deletions includes/Admin/Admin_AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ public function set_up_environment() {
$checks = is_null( $checks ) ? array() : $checks;
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );

$include_experimental = filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT );
$include_experimental = ( 1 === absint( $include_experimental ) );

Check warning on line 116 in includes/Admin/Admin_AJAX.php

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L115-L116

Added lines #L115 - L116 were not covered by tests

try {
$runner->set_experimental_flag( $include_experimental );

Check warning on line 119 in includes/Admin/Admin_AJAX.php

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L119

Added line #L119 was not covered by tests
$runner->set_check_slugs( $checks );
$runner->set_plugin( $plugin );

Expand Down Expand Up @@ -183,12 +187,14 @@ public function get_checks_to_run() {
wp_send_json_error( $valid_request, 403 );
}

$categories = filter_input( INPUT_POST, 'categories', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
$categories = is_null( $categories ) ? array() : $categories;
$checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
$checks = is_null( $checks ) ? array() : $checks;
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$runner = Plugin_Request_Utility::get_runner();
$categories = filter_input( INPUT_POST, 'categories', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
$categories = is_null( $categories ) ? array() : $categories;
$checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
$checks = is_null( $checks ) ? array() : $checks;
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$include_experimental = filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT );
$include_experimental = ( 1 === absint( $include_experimental ) );
$runner = Plugin_Request_Utility::get_runner();

Check warning on line 197 in includes/Admin/Admin_AJAX.php

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L190-L197

Added lines #L190 - L197 were not covered by tests

if ( is_null( $runner ) ) {
$runner = new AJAX_Runner();
Expand All @@ -203,6 +209,7 @@ public function get_checks_to_run() {
}

try {
$runner->set_experimental_flag( $include_experimental );

Check warning on line 212 in includes/Admin/Admin_AJAX.php

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L212

Added line #L212 was not covered by tests
$runner->set_check_slugs( $checks );
$runner->set_plugin( $plugin );
$runner->set_categories( $categories );
Expand Down Expand Up @@ -255,7 +262,11 @@ public function run_checks() {
$checks = is_null( $checks ) ? array() : $checks;
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );

$include_experimental = filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT );
$include_experimental = ( 1 === absint( $include_experimental ) );

Check warning on line 266 in includes/Admin/Admin_AJAX.php

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L265-L266

Added lines #L265 - L266 were not covered by tests

try {
$runner->set_experimental_flag( $include_experimental );

Check warning on line 269 in includes/Admin/Admin_AJAX.php

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L269

Added line #L269 was not covered by tests
$runner->set_check_slugs( $checks );
$runner->set_plugin( $plugin );
$results = $runner->run();
Expand Down
7 changes: 7 additions & 0 deletions includes/Admin/Admin_Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ public function render_page() {
$user_enabled_categories = get_user_setting( 'plugin_check_category_preferences', implode( '__', $this->get_default_check_categories_to_be_selected() ) );
$user_enabled_categories = explode( '__', $user_enabled_categories );

$check_repo = new Default_Check_Repository();

$non_experimental_collection = $check_repo->get_checks( Check_Repository::TYPE_ALL );
$complete_collection = $check_repo->get_checks( Check_Repository::TYPE_ALL + Check_Repository::INCLUDE_EXPERIMENTAL );

$has_experimental_checks = ( count( $non_experimental_collection ) !== count( $complete_collection ) );

require WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'templates/admin-page.php';
}

Expand Down
3 changes: 2 additions & 1 deletion includes/Checker/AJAX_Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ protected function get_check_exclude_slugs_param() {
* @return bool Returns true to include experimental checks else false.
*/
protected function get_include_experimental_param() {
return false;
$include_experimental = filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT );
return ( 1 === absint( $include_experimental ) );
}

/**
Expand Down
8 changes: 8 additions & 0 deletions templates/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
<?php } ?>
</table>
<?php } ?>

<?php if ( $has_experimental_checks ) { ?>
<h4><?php esc_attr_e( 'Other Options', 'plugin-check' ); ?></h4>
<p>
<input type="checkbox" value="include-experimental" id="plugin-check__include-experimental" /> <?php esc_html_e( 'Include Experimental Checks', 'plugin-check' ); ?>
</p>
<?php } ?>

</form>

<?php } else { ?>
Expand Down

0 comments on commit 4d1c189

Please sign in to comment.