Skip to content

Commit

Permalink
phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidperezgar committed May 16, 2022
1 parent 615d221 commit 3267c36
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
*/
class Health_WPVulnerability {

/**
* Construct Class for Health Kit
*/
public function __construct() {
add_filter( 'site_status_tests', array( $this, 'add_vulnerability_tests' ) );
}

/**
* Add vulnerability tests in Health
*
* @param array $tests Actual tests.
* @return array
*/
public function add_vulnerability_tests( $tests ) {
$tests['direct']['wpvulnerability_core'] = array(
'label' => __( 'WP Vulnerability Core' ),
Expand All @@ -38,6 +47,11 @@ public function add_vulnerability_tests( $tests ) {
return $tests;
}

/**
* Tests for Vulnerability in Core
*
* @return array
*/
public function test_vulnerability_core() {
$result = array(
'label' => __( 'There are no vulnerabilities in WordPress Core.' ),
Expand All @@ -53,17 +67,17 @@ public function test_vulnerability_core() {
'actions' => '',
'test' => 'wpvulnerability_core',
);
$core_vulnerabilities = wpvulnerability_get_core();

$core_vulnerabilities = wpvulnerability_get_core();
if ( ! empty( $core_vulnerabilities ) ) {
$result['status'] = 'critical';
$result['label'] = __( 'There are vulnerabilities in WordPress Core.', 'wpvulnerability' );
$result['status'] = 'critical';
$result['label'] = __( 'There are vulnerabilities in WordPress Core.', 'wpvulnerability' );
$result['description'] = sprintf(
'<p>%1$s</p> %2$s',
__( 'We have found vulnerabilities in WordPress Core.', 'wpvulnerability' ),
$this->get_html_vulnerabilities( $core_vulnerabilities )
);
$result['actions'] .= sprintf(
$result['actions'] .= sprintf(
'<p><a href="%s">%s</a></p>',
esc_url( admin_url( 'update-core.php' ) ),
__( 'Update WordPress Core' )
Expand All @@ -73,6 +87,11 @@ public function test_vulnerability_core() {
return $result;
}

/**
* Tests for Vulnerability in Themes
*
* @return array
*/
public function test_vulnerability_themes() {
$result = array(
'label' => __( 'There are no vulnerabilities in Themes.' ),
Expand All @@ -88,9 +107,9 @@ public function test_vulnerability_themes() {
'actions' => '',
'test' => 'wpvulnerability_themes',
);
$html_vuln = '';
$vuln_themes = array();
$themes = wp_get_themes();

$html_vuln = '';
$themes = wp_get_themes();
foreach ( $themes as $slug => $theme ) {
$slug = sanitize_title( $slug );
$theme_vulnerability = wpvulnerability_get_theme( $slug, $theme->get( 'Version' ) );
Expand All @@ -101,14 +120,14 @@ public function test_vulnerability_themes() {
}

if ( ! empty( $html_vuln ) ) {
$result['status'] = 'critical';
$result['label'] = __( 'There are vulnerabilities in Themes.', 'wpvulnerability' );
$result['status'] = 'critical';
$result['label'] = __( 'There are vulnerabilities in Themes.', 'wpvulnerability' );
$result['description'] = sprintf(
'<p>%1$s</p> %2$s',
__( 'We have found vulnerabilities in Themes.', 'wpvulnerability' ),
$html_vuln
);
$result['actions'] .= sprintf(
$result['actions'] .= sprintf(
'<p><a href="%s">%s</a></p>',
esc_url( admin_url( 'update-core.php' ) ),
__( 'Update Themes' )
Expand All @@ -117,6 +136,12 @@ public function test_vulnerability_themes() {

return $result;
}

/**
* Tests for Vulnerability in Plugins
*
* @return array
*/
public function test_vulnerability_plugins() {
$result = array(
'label' => __( 'There are no vulnerabilities in Plugins.' ),
Expand All @@ -132,9 +157,9 @@ public function test_vulnerability_plugins() {
'actions' => '',
'test' => 'wpvulnerability_plugins',
);
$plugins = get_plugins();
$vuln_plugins = array();
$html_vuln = '';

$plugins = get_plugins();
$html_vuln = '';
foreach ( $plugins as $key => $plugin ) {
if ( empty( $plugin['TextDomain'] ) && isset( $plugin['file_path'] ) ) {
$folder_name = explode( '/', $plugin['file_path'] );
Expand All @@ -150,14 +175,14 @@ public function test_vulnerability_plugins() {
}

if ( ! empty( $html_vuln ) ) {
$result['status'] = 'critical';
$result['label'] = __( 'There are vulnerabilities in Plugins.', 'wpvulnerability' );
$result['status'] = 'critical';
$result['label'] = __( 'There are vulnerabilities in Plugins.', 'wpvulnerability' );
$result['description'] = sprintf(
'<p>%1$s</p> %2$s',
__( 'We have found vulnerabilities in Plugins.', 'wpvulnerability' ),
$html_vuln
);
$result['actions'] .= sprintf(
$result['actions'] .= sprintf(
'<p><a href="%s">%s</a></p>',
esc_url( admin_url( 'update-core.php' ) ),
__( 'Update Plugins' )
Expand All @@ -167,12 +192,18 @@ public function test_vulnerability_plugins() {
return $result;
}

/**
* Convert vulnerabilities in html
*
* @param array $vulnerabilities Vulnerabilites.
* @return html
*/
private function get_html_vulnerabilities( $vulnerabilities ) {
$html = '<table>';
foreach ( $vulnerabilities as $vulnerability ) {
foreach ( $vulnerability['source'] as $source ) {
$html .= '<tr>';
$html .= '<td style="background-color:#FAEDE8;padding: 4px 15px 4px 0;"><strong>' . esc_html( $vulnerability['name'] ) . '<br/>' . esc_html( $source['name'] ) . '<br/>' . esc_html( $source['date'] ) . '</strong></td>';
$html .= '<td style="background-color:#FAEDE8;padding: 4px 15px 4px 0;"><strong>' . esc_html( $vulnerability['name'] ) . '<br/>' . esc_html( $source['name'] ) . '<br/>' . esc_html( $source['date'] ) . '</strong></td>';
$html .= '<td style="background-color:#FAEDE8;padding: 4px 15px 4px 0;">' . esc_html( $source['description'] ) . '</td>';
$html .= '</tr>';
}
Expand Down
2 changes: 1 addition & 1 deletion wpvulnerability.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function wpvul_plugin_init() {

require_once WPVULNERABILITY_PLUGIN_PATH . '/includes/helpers-api.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/includes/class-plugins-wpvulnerability.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/includes/class-health-vulnerability.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/includes/class-health-wpvulnerability.php';

// Initialize our plugin.
new Plugins_WPVulnerability();

0 comments on commit 3267c36

Please sign in to comment.