Skip to content

Commit

Permalink
Merge pull request #10 from a2hosting/A2CP-422
Browse files Browse the repository at this point in the history
A2CP-422 added wpcli method to expose is_active
  • Loading branch information
jrtaylor-com authored Oct 26, 2023
2 parents 9cd76ec + 4c583b8 commit a48b3c4
Showing 1 changed file with 58 additions and 0 deletions.
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

0 comments on commit a48b3c4

Please sign in to comment.