Skip to content

Commit

Permalink
WordPress Coding Standar Compatibility (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercasares authored Sep 10, 2023
2 parents 3dc4c7b + 1de55e7 commit 635719e
Show file tree
Hide file tree
Showing 13 changed files with 637 additions and 745 deletions.
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: javiercasares, davidperez, lbonomo
Tags: security, vulnerability, site-health
Requires at least: 4.1
Tested up to: 6.3
Stable tag: 2.0.3
Stable tag: 2.0.4
Requires PHP: 5.6
Version: 2.0.3
Version: 2.0.4
License: EUPL v1.2
License URI: https://www.eupl.eu/1.2/en/

Expand Down Expand Up @@ -71,6 +71,9 @@ First of all, peace of mind. Investigate what the vulnerability is and, above al

== Changelog ==

= 2.0.4 =
* WordPress Coding Standards 3.0.0 compatible.

= 2.0.3 =
* Validate secure requests to the API.
* Reduce API timeout request time from 10.0 seconds to 2.5 seconds.
Expand Down
1 change: 1 addition & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @package WPVulnerability
* @version 2.0.0
*/

if ( defined( 'ABSPATH' ) && defined( 'WP_UNINSTALL_PLUGIN' ) ) {

/**
Expand Down
74 changes: 32 additions & 42 deletions wpvulnerability-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
*
* @version 2.0.0
*/

defined( 'ABSPATH' ) || die( 'No script kiddies please!' );

/**
* Load the settings to be available always.
*
*
* @version 2.0.0
*
*
* @return array|false An array containing the WPVulnerability settings if they exist, or false if they don't.
*/
$wpvulnerability_settings = get_option( 'wpvulnerability-config' );

/**
* Enqueues the WPVulnerability admin CSS file on all admin pages.
*
*
* @version 2.0.0
*
*
* @return void
*/
function wpvulnerability_admin_enqueue_scripts() {
Expand All @@ -32,7 +33,6 @@ function wpvulnerability_admin_enqueue_scripts() {
array(),
WPVULNERABILITY_PLUGIN_VERSION
);

}
add_action( 'admin_enqueue_scripts', 'wpvulnerability_admin_enqueue_scripts' );

Expand All @@ -41,14 +41,13 @@ function wpvulnerability_admin_enqueue_scripts() {
* This function generates the HTML output for the WPVulnerability settings page in the WP-Admin.
*
* @since 2.0.0
*
*
* @return void
*/
function wpvulnerability_create_admin_page() {

$wpvulnerability_settings = get_option( 'wpvulnerability-config' );

?>
?>
<div class="header-wrap">
<div class="wrapper">
<div class="header wpvulnerability-header">
Expand All @@ -69,19 +68,19 @@ function wpvulnerability_create_admin_page() {
?>
</form>
</div>
<?php
<?php
}

/**
* Adds a WP-Admin menu option for the WPVulnerability plugin
*
*
* @since 2.0.0
*
*
* @return void
*/
function wpvulnerability_admin_menu() {

// Adds a submenu page under the Settings menu
// Adds a submenu page under the Settings menu.
add_submenu_page(
'options-general.php',
__( 'WPVulnerability', 'wpvulnerability' ),
Expand All @@ -90,7 +89,6 @@ function wpvulnerability_admin_menu() {
'wpvulnerability-options',
'wpvulnerability_create_admin_page'
);

}
add_action( 'admin_menu', 'wpvulnerability_admin_menu' );

Expand All @@ -105,12 +103,8 @@ function wpvulnerability_admin_section_notifications() {

// Output the header information for the notifications section.
esc_html_e( 'Configure and save these settings to receive email notifications.', 'wpvulnerability' );

}




/**
* Callback function to display the email input field in the admin settings page.
* This function retrieves the current WPVulnerability plugin settings and displays the email input field
Expand All @@ -122,19 +116,19 @@ function wpvulnerability_admin_section_notifications() {
*/
function wpvulnerability_admin_emails_callback() {

// Retrieve the WPVulnerability plugin settings
// Retrieve the WPVulnerability plugin settings.
$wpvulnerability_settings = get_option( 'wpvulnerability-config' );

// Set a default value for the email input field if no email is saved in the settings
if ( !isset( $wpvulnerability_settings['emails'] ) ) {
// Set a default value for the email input field if no email is saved in the settings.
if ( ! isset( $wpvulnerability_settings['emails'] ) ) {
$wpvulnerability_settings['emails'] = '';
}

// Output the email input field and display the admin email as a hint
?>
<input class="regular-text" type="text" name="wpvulnerability-config[emails]" id="wpvulnerability_emails" placeholder="<?php echo get_bloginfo( 'admin_email' ); ?>" value="<?php echo esc_attr( $wpvulnerability_settings['emails'] ); ?>">
<br><small><?php echo get_bloginfo( 'admin_email' ); ?></small>
<?php
// Output the email input field and display the admin email as a hint.
?>
<input class="regular-text" type="text" name="wpvulnerability-config[emails]" id="wpvulnerability_emails" placeholder="<?php echo esc_attr( get_bloginfo( 'admin_email' ) ); ?>" value="<?php echo esc_attr( $wpvulnerability_settings['emails'] ); ?>">
<br><small><?php echo esc_attr( get_bloginfo( 'admin_email' ) ); ?></small>
<?php
}

/**
Expand All @@ -145,22 +139,22 @@ function wpvulnerability_admin_emails_callback() {
* @return void
*/
function wpvulnerability_admin_period_callback() {

// Get the saved plugin settings.
$wpvulnerability_settings = get_option( 'wpvulnerability-config' );

// Set the default period to 'weekly' if not set or empty.
if ( !isset( $wpvulnerability_settings['period'] ) || empty( $wpvulnerability_settings['period'] ) ) {
if ( ! isset( $wpvulnerability_settings['period'] ) || empty( $wpvulnerability_settings['period'] ) ) {
$wpvulnerability_settings['period'] = 'weekly';
}

// Output the period select box.
?>
?>
<select name="wpvulnerability-config[period]" id="wpvulnerability_period">
<option value="weekly" <?php selected( $wpvulnerability_settings['period'], 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'wpvulnerability' ); ?></option>
<option value="daily" <?php selected( $wpvulnerability_settings['period'], 'daily' ); ?>><?php esc_html_e( 'Daily', 'wpvulnerability' ); ?></option>
</select>
<?php
<?php
}

/**
Expand All @@ -175,27 +169,25 @@ function wpvulnerability_admin_period_callback() {
function wpvulnerability_admin_sanitize( $input ) {

$sanitized_values = array();
$input_emails = array();
$input_emails = array();

if ( isset( $input['emails'] ) ) {

$input_email_text = explode( ',', $input['emails'] );

// Loop through each email address in the input field.
foreach( $input_email_text as $input_email ) {
foreach ( $input_email_text as $input_email ) {

// Sanitize each email address.
$input_email = sanitize_email( trim( $input_email ) );

if( $input_email ) {
if ( $input_email ) {
$input_emails[] = $input_email;
}

}

}

if( count( $input_emails ) ) {
if ( count( $input_emails ) ) {
$sanitized_values['emails'] = implode( ',', $input_emails );
} else {
$sanitized_values['emails'] = null;
Expand All @@ -204,7 +196,7 @@ function wpvulnerability_admin_sanitize( $input ) {
if ( isset( $input['period'] ) ) {

// Check the value of the period field and sanitize it.
switch( $input['period'] ) {
switch ( $input['period'] ) {
case 'daily':
$sanitized_values['period'] = 'daily';
break;
Expand All @@ -213,7 +205,6 @@ function wpvulnerability_admin_sanitize( $input ) {
$sanitized_values['period'] = 'weekly';
break;
}

}

// Clear the scheduled hook for the notification event and set it to run at the sanitized interval.
Expand All @@ -232,22 +223,22 @@ function wpvulnerability_admin_sanitize( $input ) {
*/
function wpvulnerability_admin_init() {

// Register the plugin settings to be saved in the database
// Register the plugin settings to be saved in the database.
register_setting(
'admin_wpvulnerability_settings',
'wpvulnerability-config',
'wpvulnerability_admin_sanitize'
);

// Add a section to the settings page
// Add a section to the settings page.
add_settings_section(
'admin_wpvulnerability_settings',
__( 'Receive notifications in your email', 'wpvulnerability' ),
'wpvulnerability_admin_section_notifications',
'wpvulnerability-config'
);

// Add a field to the settings page for the email addresses
// Add a field to the settings page for the email addresses.
add_settings_field(
'wpvulnerability_emails',
__( 'eMail addresses to notify (separated by commas)', 'wpvulnerability' ),
Expand All @@ -256,14 +247,13 @@ function wpvulnerability_admin_init() {
'admin_wpvulnerability_settings'
);

// Add a field to the settings page for the notification period
// Add a field to the settings page for the notification period.
add_settings_field(
'wpvulnerability_period',
__( 'How often you want to receive notifications', 'wpvulnerability' ),
'wpvulnerability_admin_period_callback',
'wpvulnerability-config',
'admin_wpvulnerability_settings'
);

}
add_action( 'admin_init', 'wpvulnerability_admin_init' );
Loading

0 comments on commit 635719e

Please sign in to comment.