options = Options::init();
parent::__construct( $parent_page );
// Remove unnecessary $_GET parameters and prevent url duplications in _wp_http_referer input.
$this->remove_get_parameters();
}
/**
* Link label of a tab.
*
* @since 3.0.0
*
* @return string
*/
public function get_label() {
return esc_html__( 'Debug Events', 'wp-mail-smtp' );
}
/**
* Title of a tab.
*
* @since 3.0.0
*
* @return string
*/
public function get_title() {
return $this->get_label();
}
/**
* Register hooks.
*
* @since 3.0.0
*/
public function hooks() {
add_action( 'wp_mail_smtp_admin_area_enqueue_assets', [ $this, 'enqueue_assets' ] );
}
/**
* Enqueue required JS and CSS.
*
* @since 3.0.0
*/
public function enqueue_assets() {
$min = WP::asset_min();
wp_enqueue_style(
'wp-mail-smtp-flatpickr',
wp_mail_smtp()->assets_url . '/css/vendor/flatpickr.min.css',
[],
'4.6.9'
);
wp_enqueue_script(
'wp-mail-smtp-flatpickr',
wp_mail_smtp()->assets_url . '/js/vendor/flatpickr.min.js',
[ 'jquery' ],
'4.6.9',
true
);
wp_enqueue_script(
'wp-mail-smtp-tools-debug-events',
wp_mail_smtp()->assets_url . "/js/smtp-tools-debug-events{$min}.js",
[ 'jquery', 'wp-mail-smtp-flatpickr' ],
WPMS_PLUGIN_VER,
true
);
wp_localize_script(
'wp-mail-smtp-tools-debug-events',
'wp_mail_smtp_tools_debug_events',
[
'lang_code' => sanitize_key( WP::get_language_code() ),
'plugin_url' => wp_mail_smtp()->plugin_url,
'loader' => wp_mail_smtp()->prepare_loader( 'blue' ),
'texts' => [
'delete_all_notice' => esc_html__( 'Are you sure you want to permanently delete all debug events?', 'wp-mail-smtp' ),
'cancel' => esc_html__( 'Cancel', 'wp-mail-smtp' ),
'close' => esc_html__( 'Close', 'wp-mail-smtp' ),
'yes' => esc_html__( 'Yes', 'wp-mail-smtp' ),
'ok' => esc_html__( 'OK', 'wp-mail-smtp' ),
'notice_title' => esc_html__( 'Heads up!', 'wp-mail-smtp' ),
'error_occurred' => esc_html__( 'An error occurred!', 'wp-mail-smtp' ),
],
]
);
}
/**
* Get email logs list table.
*
* @since 3.0.0
*
* @return Table
*/
public function get_table() {
if ( $this->table === null ) {
$this->table = new Table();
}
return $this->table;
}
/**
* Display scheduled actions table.
*
* @since 3.0.0
*/
public function display() {
?>
display_debug_events_not_installed();
} else {
$table = $this->get_table();
$table->prepare_items();
?>
check_admin_referer();
if ( WP::use_global_plugin_settings() && ! current_user_can( 'manage_network_options' ) ) {
wp_die( esc_html__( 'You don\'t have the capability to perform this action.', 'wp-mail-smtp' ) );
}
// Unchecked checkboxes doesn't exist in $_POST, so we need to ensure we actually have them in data to save.
if ( empty( $data['debug_events']['email_debug'] ) ) {
$data['debug_events']['email_debug'] = false;
}
// All the sanitization is done there.
$this->options->set( $data, false, false );
WP::add_admin_notice(
esc_html__( 'Settings were successfully saved.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_SUCCESS
);
}
/**
* Return an array with information (HTML and id) for each filter for this current view.
*
* @since 3.0.0
*
* @return array
*/
private function get_filters_html() {
$filters = [
'.search-box' => $this->get_filter_search_html(),
'.wp-mail-smtp-filter-date' => $this->get_filter_date_html(),
];
return array_filter( $filters );
}
/**
* Return HTML with information about the search filter.
*
* @since 3.0.0
*
* @return string
*/
private function get_filter_search_html() {
$table = $this->get_table();
$term = $table->get_filtered_search();
if ( $term === false ) {
return '';
}
return sprintf( /* translators: %s The searched term. */
__( 'where event contains "%s"', 'wp-mail-smtp' ),
'' . esc_html( $term ) . ''
);
}
/**
* Return HTML with information about the date filter.
*
* @since 3.0.0
*
* @return string
*/
private function get_filter_date_html() {
$table = $this->get_table();
$dates = $table->get_filtered_dates();
if ( $dates === false ) {
return '';
}
$dates = array_map(
function ( $date ) {
return date_i18n( 'M j, Y', strtotime( $date ) );
},
$dates
);
$html = '';
switch ( count( $dates ) ) {
case 1:
$html = sprintf( /* translators: %s - Date. */
esc_html__( 'on %s', 'wp-mail-smtp' ),
'' . $dates[0] . ''
);
break;
case 2:
$html = sprintf( /* translators: %1$s - Date. %2$s - Date. */
esc_html__( 'between %1$s and %2$s', 'wp-mail-smtp' ),
'' . $dates[0] . '',
'' . $dates[1] . ''
);
break;
}
return $html;
}
/**
* Display a message when debug events DB table is missing.
*
* @since 3.0.0
*/
private function display_debug_events_not_installed() {
$error_message = get_option( Migration::ERROR_OPTION_NAME );
?>
';
echo '' . esc_html( $error_message ) . '
';
} else {
esc_html_e( 'For some reason the database table was not installed correctly. Please contact plugin support team to diagnose and fix the issue.', 'wp-mail-smtp' );
}
?>
esc_html__( '1 Week', 'wp-mail-smtp' ),
2628000 => esc_html__( '1 Month', 'wp-mail-smtp' ),
7885000 => esc_html__( '3 Months', 'wp-mail-smtp' ),
15770000 => esc_html__( '6 Months', 'wp-mail-smtp' ),
31540000 => esc_html__( '1 Year', 'wp-mail-smtp' ),
];
$debug_event_retention_period = $this->options->get( 'debug_events', 'retention_period' );
// Check if defined value already in list and add it if not.
if (
! empty( $debug_event_retention_period ) &&
! isset( $options[ $debug_event_retention_period ] )
) {
$debug_event_retention_period_days = floor( $debug_event_retention_period / DAY_IN_SECONDS );
$options[ $debug_event_retention_period ] = sprintf(
/* translators: %d - days count. */
_n( '%d Day', '%d Days', $debug_event_retention_period_days, 'wp-mail-smtp' ),
$debug_event_retention_period_days
);
ksort( $options );
}
/**
* Filter debug events retention period options.
*
* @since 3.6.0
*
* @param array $options Debug Events retention period options.
* Option key in seconds.
*/
return apply_filters(
'wp_mail_smtp_admin_pages_debug_events_tab_get_debug_events_retention_period_options',
$options
);
}
}