Skip to content

Commit

Permalink
phpcs and transients fix
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercasares committed Sep 23, 2024
1 parent 8176a67 commit 27b5ee0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 39 deletions.
4 changes: 2 additions & 2 deletions wpvulnerability-adminms.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function wpvulnerability_create_admin_page() {
'mariadb' => 0,
'mysql' => 0,
'imagemagick' => 0,
'curl' => 0
'curl' => 0,
);

$wpvulnerability_values = array_map( 'sanitize_text_field', wp_unslash( $_POST['wpvulnerability-analyze'] ) );
Expand Down Expand Up @@ -191,7 +191,7 @@ function wpvulnerability_create_admin_page() {
'mariadb' => $wpvulnerability_sanitized_values['mariadb'],
'mysql' => $wpvulnerability_sanitized_values['mysql'],
'imagemagick' => $wpvulnerability_sanitized_values['imagemagick'],
'curl' => $wpvulnerability_sanitized_values['curl']
'curl' => $wpvulnerability_sanitized_values['curl'],
)
);

Expand Down
2 changes: 1 addition & 1 deletion wpvulnerability-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function wpvulnerability_html_software( $type ) {
'mariadb' => 'MariaDB',
'mysql' => 'MySQL',
'imagemagick' => 'ImageMagick',
'curl' => 'curl'
'curl' => 'curl',
);

// Check if the type is valid and get the software name.
Expand Down
76 changes: 40 additions & 36 deletions wpvulnerability-run.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ function wpvulnerability_update_database_data() {
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-themes.php';
require_once WPVULNERABILITY_PLUGIN_PATH . '/wpvulnerability-software.php';

wpvulnerability_delete_transients();

// Update core, plugins, and themes vulnerabilities.
wpvulnerability_core_get_vulnerabilities_clean();
wpvulnerability_plugin_get_vulnerabilities_clean();
Expand Down Expand Up @@ -105,7 +107,7 @@ function wpvulnerability_expired_database_data() {

// Check and update core, plugins, and themes vulnerabilities if cache has expired.
$components = array(
'core' => 'wpvulnerability-core-cache',
'core' => 'wpvulnerability-core-cache',
'plugin' => 'wpvulnerability-plugins-cache',
'theme' => 'wpvulnerability-themes-cache',
);
Expand Down Expand Up @@ -151,6 +153,8 @@ function wpvulnerability_activation() {
$add_option = $is_multisite ? 'add_site_option' : 'add_option';
$update_option = $is_multisite ? 'update_site_option' : 'update_option';

wpvulnerability_delete_transients();

// Add wpvulnerability-config option if it does not exist.
if ( ! $config_key( 'wpvulnerability-config' ) ) {
$default_config = array(
Expand Down Expand Up @@ -306,41 +310,41 @@ function wpvulnerability_deactivation() {
* @return void
*/
function wpvulnerability_delete_transients() {
global $wpdb;

// Determine if the site is multisite.
$is_multisite = is_multisite();

// Define the prefix according to whether it is multisite or not.
$transient_prefix = $is_multisite ? '_site_transient_wpvulnerability_' : '_transient_wpvulnerability_';

// Prepare the LIKE pattern securely.
$like_pattern = $wpdb->esc_like($transient_prefix) . '%';

// Secure query to get all transients starting with the specified prefix.
$transients = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
$like_pattern
)
);

if (empty($transients)) {
// No matching transients found.
return;
}

foreach ($transients as $transient) {
if ($is_multisite) {
// For multisite, delete using delete_site_transient.
$transient_name = str_replace('_site_transient_', '', $transient);
delete_site_transient($transient_name);
} else {
// For single sites, delete using delete_transient.
$transient_name = str_replace('_transient_', '', $transient);
delete_transient($transient_name);
}
}
global $wpdb;

// Determine if the site is multisite.
$is_multisite = is_multisite();

// Define the prefix according to whether it is multisite or not.
$transient_prefix = $is_multisite ? '_site_transient_wpvulnerability_' : '_transient_wpvulnerability_';

// Prepare the LIKE pattern securely.
$like_pattern = $wpdb->esc_like( $transient_prefix ) . '%';

// Secure query to get all transients starting with the specified prefix.
$transients = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
$like_pattern
)
);

if ( empty( $transients ) ) {
// No matching transients found.
return;
}

foreach ( $transients as $transient ) {
if ( $is_multisite ) {
// For multisite, delete using delete_site_transient.
$transient_name = str_replace( '_site_transient_', '', $transient );
delete_site_transient( $transient_name );
} else {
// For single sites, delete using delete_transient.
$transient_name = str_replace( '_transient_', '', $transient );
delete_transient( $transient_name );
}
}
}

/**
Expand Down

0 comments on commit 27b5ee0

Please sign in to comment.