This commit is contained in:
Javier Casares 2026-07-09 06:28:55 +00:00
commit db98c4438c

View file

@ -9,60 +9,6 @@
defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
/**
* Adds a custom schedule for a weekly cron job.
*
* This function adds a new schedule interval of one week (604800 seconds)
* to the system's available cron schedules. It allows tasks to be scheduled
* to run every week using the 'weekly' interval.
*
* @since 2.0.0
*
* @param array<string, array<string, int|string>> $schedules The existing system schedules.
*
* @return array<string, array<string, int|string>> The updated list of schedules with the added weekly interval.
*/
function wpvulnerability_add_every_week( $schedules ) {
// Add a weekly schedule interval of 604800 seconds (1 week).
// Use did_action('init') guard: cron_schedules fires before init (WP 6.7+ textdomain notice).
$schedules['weekly'] = array(
'interval' => 604800,
'display' => did_action( 'init' ) ? __( 'Every week', 'wpvulnerability' ) : 'Every week',
);
// Return the modified list of schedules.
return $schedules;
}
// Hook the function to the 'cron_schedules' filter to add the custom schedule.
add_filter( 'cron_schedules', 'wpvulnerability_add_every_week' );
/**
* Adds a custom schedule for daily events.
*
* This function adds a new schedule interval of one day (86400 seconds)
* to the system's available cron schedules. It allows tasks to be scheduled
* to run every day using the 'daily' interval.
*
* @since 2.0.0
*
* @param array<string, array<string, int|string>> $schedules List of available schedules.
*
* @return array<string, array<string, int|string>> Modified list of available schedules with the added daily interval.
*/
function wpvulnerability_add_every_day( $schedules ) {
// Define a new schedule with a 24 hour interval.
// Use did_action('init') guard: cron_schedules fires before init (WP 6.7+ textdomain notice).
$schedules['daily'] = array(
'interval' => 86400,
'display' => did_action( 'init' ) ? __( 'Every day', 'wpvulnerability' ) : 'Every day',
);
// Return the modified list of schedules.
return $schedules;
}
// Hook the function to the 'cron_schedules' filter to add the custom schedule.
add_filter( 'cron_schedules', 'wpvulnerability_add_every_day' );
/**
* Disables email notifications when requested via URL.
*
@ -715,7 +661,7 @@ function wpvulnerability_execute_notification( $forced = false ) {
$wpmail = false;
if ( $email_enabled ) {
if ( $email_enabled || $forced ) {
$mail_to = is_array( $wpvulnerability_settings['emails'] ) ? array_map(
static function ( $e ) {
return is_scalar( $e ) ? (string) $e : '';
@ -728,23 +674,27 @@ function wpvulnerability_execute_notification( $forced = false ) {
$text_message_body = wpvulnerability_html_to_plain_text( $email_content );
$text_message = trim( (string) ( $email_subject . "\n\n" . $text_message_body ) );
if ( $slack_enabled ) {
wpvulnerability_send_slack_notification( ( is_scalar( $wpvulnerability_settings['slack_webhook'] ) ? (string) $wpvulnerability_settings['slack_webhook'] : '' ), $text_message );
// Track whether any webhook channel delivered successfully, so a webhook-only
// notification (email disabled) is not reported as a failure.
$webhook_sent = false;
if ( $slack_enabled && wpvulnerability_send_slack_notification( ( is_scalar( $wpvulnerability_settings['slack_webhook'] ) ? (string) $wpvulnerability_settings['slack_webhook'] : '' ), $text_message ) ) {
$webhook_sent = true;
}
if ( $teams_enabled ) {
wpvulnerability_send_teams_notification( ( is_scalar( $wpvulnerability_settings['teams_webhook'] ) ? (string) $wpvulnerability_settings['teams_webhook'] : '' ), $text_message );
if ( $teams_enabled && wpvulnerability_send_teams_notification( ( is_scalar( $wpvulnerability_settings['teams_webhook'] ) ? (string) $wpvulnerability_settings['teams_webhook'] : '' ), $text_message ) ) {
$webhook_sent = true;
}
if ( $discord_enabled ) {
wpvulnerability_send_discord_notification( ( is_scalar( $wpvulnerability_settings['discord_webhook'] ) ? (string) $wpvulnerability_settings['discord_webhook'] : '' ), $text_message );
if ( $discord_enabled && wpvulnerability_send_discord_notification( ( is_scalar( $wpvulnerability_settings['discord_webhook'] ) ? (string) $wpvulnerability_settings['discord_webhook'] : '' ), $text_message ) ) {
$webhook_sent = true;
}
if ( $telegram_enabled ) {
wpvulnerability_send_telegram_notification( ( is_scalar( $wpvulnerability_settings['telegram_bot_token'] ) ? (string) $wpvulnerability_settings['telegram_bot_token'] : '' ), ( is_scalar( $wpvulnerability_settings['telegram_chat_id'] ) ? (string) $wpvulnerability_settings['telegram_chat_id'] : '' ), $text_message );
if ( $telegram_enabled && wpvulnerability_send_telegram_notification( ( is_scalar( $wpvulnerability_settings['telegram_bot_token'] ) ? (string) $wpvulnerability_settings['telegram_bot_token'] : '' ), ( is_scalar( $wpvulnerability_settings['telegram_chat_id'] ) ? (string) $wpvulnerability_settings['telegram_chat_id'] : '' ), $text_message ) ) {
$webhook_sent = true;
}
return $wpmail;
return $wpmail || $webhook_sent;
}
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM properties follow upstream naming.