rebase code on oct-10-2023
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace WPMailSMTP\Admin\DebugEvents;
|
||||
|
||||
use WP_Error;
|
||||
use WPMailSMTP\Admin\Area;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\Tasks\DebugEventsCleanupTask;
|
||||
@@ -15,15 +14,6 @@ use WPMailSMTP\WP;
|
||||
*/
|
||||
class DebugEvents {
|
||||
|
||||
/**
|
||||
* Transient name for the error debug events.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ERROR_DEBUG_EVENTS_TRANSIENT = 'wp_mail_smtp_error_debug_events_transient';
|
||||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
@@ -258,51 +248,6 @@ class DebugEvents {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of error debug events in a given time span.
|
||||
*
|
||||
* By default it returns the number of error debug events in the last 30 days.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param string $span_of_time The time span to count the events for. Default '-30 days'.
|
||||
*
|
||||
* @return int|WP_Error The number of error debug events or WP_Error on failure.
|
||||
*/
|
||||
public static function get_error_debug_events_count( $span_of_time = '-30 days' ) {
|
||||
|
||||
$timestamp = strtotime( $span_of_time );
|
||||
|
||||
if ( ! $timestamp || $timestamp > time() ) {
|
||||
return new WP_Error( 'wp_mail_smtp_admin_debug_events_get_error_debug_events_count_invalid_time', 'Invalid time span.' );
|
||||
}
|
||||
|
||||
$transient_key = self::ERROR_DEBUG_EVENTS_TRANSIENT . '_' . sanitize_title_with_dashes( $span_of_time );
|
||||
$cached_error_events_count = get_transient( $transient_key );
|
||||
|
||||
if ( $cached_error_events_count !== false ) {
|
||||
return (int) $cached_error_events_count;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
|
||||
$sql = $wpdb->prepare(
|
||||
'SELECT COUNT(*) FROM `%1$s` WHERE event_type = %2$d AND created_at >= "%3$s"',
|
||||
self::get_table_name(),
|
||||
Event::TYPE_ERROR,
|
||||
gmdate( WP::datetime_mysql_format(), $timestamp )
|
||||
);
|
||||
// phpcs:enable WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
|
||||
$error_events_count = (int) $wpdb->get_var( $sql );
|
||||
|
||||
set_transient( $transient_key, $error_events_count, HOUR_IN_SECONDS );
|
||||
|
||||
return $error_events_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the screen options for the debug events page.
|
||||
*
|
||||
@@ -414,8 +359,7 @@ class DebugEvents {
|
||||
|
||||
$table = self::get_table_name();
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
$is_valid = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s;', $table ) );
|
||||
$is_valid = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s;', $table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
|
||||
return $is_valid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user