Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add include experimental option in admin #874

Merged
merged 6 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 14 additions & 6 deletions includes/Admin/Admin_AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@
$checks = is_null( $checks ) ? array() : $checks;
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );

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

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

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L115

Added line #L115 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L118

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

Expand Down Expand Up @@ -183,12 +186,13 @@
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 = 1 === filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT );
$runner = Plugin_Request_Utility::get_runner();

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

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L189-L195

Added lines #L189 - L195 were not covered by tests

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

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

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

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L210

Added line #L210 was not covered by tests
$runner->set_check_slugs( $checks );
$runner->set_plugin( $plugin );
$runner->set_categories( $categories );
Expand Down Expand Up @@ -255,7 +260,10 @@
$checks = is_null( $checks ) ? array() : $checks;
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );

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

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

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_AJAX.php#L263

Added line #L263 was not covered by tests

try {
$runner->set_experimental_flag( $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#L266

Added line #L266 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
Loading