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

A2CP-422 added wpcli method to expose is_active #10

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Changes from all 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
58 changes: 58 additions & 0 deletions core/A2_Optimized_CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ public function enable($args, $assoc_args) {
}

break;
case 'regenerate_salts':
$optimizations->regenerate_wpconfig_salts();

return WP_CLI::success(esc_html__( $site_type . ' salts have been regenerated.', 'a2-optimized-wp' ));

break;
case 'remove_conf_backups':
$optimizations->enable_wpconfig_cleanup();

return WP_CLI::success(esc_html__( $site_type . ' config backups are scheduled to be removed.', 'a2-optimized-wp' ));
break;
}
}

Expand Down Expand Up @@ -284,6 +295,12 @@ public function disable($args, $assoc_args) {

return WP_CLI::success(esc_html__( $site_type . ' Bcrypt passwords disabled.', 'a2-optimized-wp' ));

break;
case 'remove_conf_backups':
$optimizations->disable_wpconfig_cleanup();

return WP_CLI::success(esc_html__( $site_type . ' No longer removing config backups.', 'a2-optimized-wp' ));

break;
}
}
Expand Down Expand Up @@ -329,6 +346,47 @@ public function site_health($args, $assoc_args) {
}
}

/**
* Returns status of specified security options
*/
public function is_active($args, $assoc_args) {
$optimizations = new A2_Optimized_Optimizations;
$return = array();

$specialMapping = array(
'lock_plugins' => 'lock_editing',
'bcrypt' => 'a2_bcrypt_passwords',
'remove_conf_backups' => 'a2_wpconfig_cleanup',
'xmlrpc' => 'xmlrpc_requests',
);

$output_json = (array_key_exists('format', $assoc_args) && $assoc_args['format'] == 'json');

if (count($args) > 0) {
$slugs = explode(',', $args[0]);

foreach ($slugs as $slug) {
$name = $slug;
if (array_key_exists($slug, $specialMapping)) {
$name = $specialMapping[$slug];
}
$stat = $optimizations->is_active($name, !$output_json);
$return[$slug] = $stat;
}
}

if ($output_json) {
return WP_CLI::line(json_encode($return));
} else {
foreach ($return as $slug => $v) {
echo "$slug is " . ($v === true ? 'Active' : 'Inactive') . "\n\r";
}

return;
}

}

/**
* Returns a site health report for the current site
*/
Expand Down
Loading