This commit is contained in:
2026-07-02 15:54:39 -06:00
commit 9883323161
17470 changed files with 4470592 additions and 0 deletions
@@ -0,0 +1,185 @@
<?php
namespace Gravity_Forms\Gravity_SMTP\Apps\Config;
use Gravity_Forms\Gravity_SMTP\Alerts\Endpoints\Save_Alerts_Settings_Endpoint;
use Gravity_Forms\Gravity_SMTP\Connectors\Connector_Service_Provider;
use Gravity_Forms\Gravity_SMTP\Connectors\Endpoints\Save_Plugin_Settings_Endpoint;
use Gravity_Forms\Gravity_SMTP\Experimental_Features\Experiment_Features_Handler;
use Gravity_Forms\Gravity_SMTP\Gravity_SMTP;
use Gravity_Forms\Gravity_SMTP\Users\Roles;
use Gravity_Forms\Gravity_SMTP\Utils\Booliesh;
use Gravity_Forms\Gravity_Tools\Config;
class Apps_Config extends Config {
protected $script_to_localize = 'gravitysmtp_scripts_admin';
protected $name = 'gravitysmtp_admin_config';
public function data() {
$container = Gravity_SMTP::container();
$plugin_data_store = $container->get( Connector_Service_Provider::DATA_STORE_ROUTER );
$debug_log_enabled = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_DEBUG_LOG_ENABLED, 'false' );
$debug_log_enabled = ! empty( $debug_log_enabled ) ? $debug_log_enabled !== 'false' : false;
$test_mode = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_TEST_MODE );
$test_mode = ! empty( $test_mode ) ? $test_mode !== 'false' : false;
$usage_analytics_enabled = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_USAGE_ANALYTICS, 'true' );
$usage_analytics_enabled = ! empty( $usage_analytics_enabled ) ? $usage_analytics_enabled !== 'false' : false;
// todo: @aaron from here to line 42, please refactor as you see fit. We need deep defaults maybe, or a pattern, and i need deep Booliesh hahaha unless what i did there is cool
$experimental_features = $plugin_data_store->get_plugin_setting( Experiment_Features_Handler::ENABLED_EXPERIMENTS_PARAM, array() );
if ( ! isset( $experimental_features[ 'alerts_management' ] ) ) {
$experimental_features[ 'alerts_management' ] = false;
}
foreach( $experimental_features as $feature => $enabled ) {
$experimental_features[ $feature ] = Booliesh::get( $enabled );
}
return array(
'common' => array(
'i18n' => array(
'aria_label_collapsed_metabox' => esc_html__( 'Expand', 'gravitysmtp' ),
'aria_label_expanded_metabox' => esc_html__( 'Collapse', 'gravitysmtp' ),
'confirm_change_cancel' => esc_html__( 'Cancel', 'gravitysmtp' ),
'confirm_change_confirm' => esc_html__( 'Confirm', 'gravitysmtp' ),
'debug_log_enabled' => esc_html__( 'Debug Log Enabled', 'gravitysmtp' ),
'test_mode_enabled' => esc_html__( 'Test Mode Enabled', 'gravitysmtp' ),
'setting_locked' => esc_html__( 'This setting is locked due to a defined constant and cannot be modified.', 'gravitysmtp' ),
'debug_messages' => array(
/* translators: %1$s is the body of the ajax request. */
'deleting_activity_log_rows' => esc_html__( 'Deleting activity log rows: %1$s', 'gravitysmtp' ),
/* translators: %1$s is the error. */
'deleting_activity_log_rows_error' => esc_html__( 'Error deleting activity log rows: %1$s', 'gravitysmtp' ),
/* translators: %1$s is the body of the ajax request. */
'deleting_all_debug_logs' => esc_html__( 'Deleting all debug logs: %1$s', 'gravitysmtp' ),
/* translators: %1$s is the error. */
'deleting_all_debug_logs_error' => esc_html__( 'Error deleting all debug logs: %1$s', 'gravitysmtp' ),
/* translators: %1$s is the active connector they are saving settings for, %2$s is the body of the ajax request. */
'saving_integration_settings' => esc_html__( 'Saving integration settings for the %1$s connector: %2$s', 'gravitysmtp' ),
/* translators: %1$s is the active connector they are saving settings for, %2$s is the error. */
'saving_integration_settings_error' => esc_html__( 'Error saving integration settings for the %1$s connector: %2$s', 'gravitysmtp' ),
/* translators: %1$s is the body of the ajax request. */
'saving_plugin_settings' => esc_html__( 'Saving plugin settings: %1$s', 'gravitysmtp' ),
/* translators: %1$s is the error. */
'saving_plugin_settings_error' => esc_html__( 'Error saving plugin settings: %1$s', 'gravitysmtp' ),
),
'general_settings_usage_analytics_label' => esc_html__( 'Share Gravity SMTP Analytics', 'gravitysmtp' ),
/* translators: {{learn_link}} tags are replaced by opening and closing tags for a link to our learn more page for usage */
'general_settings_usage_analytics_help_text' => esc_html__( 'We love improving the email sending experience for everyone in our community. By enabling analytics you can help us learn more about how our customers use Gravity SMTP. {{learn_link}}Learn more{{learn_link}}', 'gravitysmtp' ),
'snackbar_api_save_success' => esc_html__( 'API settings saved', 'gravitysmtp' ),
'snackbar_api_save_integration_enabled' => esc_html__( 'API settings saved and %1$s integration enabled', 'gravitysmtp' ),
'snackbar_generic_update_error' => esc_html__( 'Error saving setting', 'gravitysmtp' ),
'snackbar_generic_update_success' => esc_html__( 'Setting successfully updated', 'gravitysmtp' ),
'snackbar_send_test_mail_error' => esc_html__( 'Could not send test email; please check your logs', 'gravitysmtp' ),
'snackbar_send_test_mail_success' => esc_html__( 'Email successfully sent', 'gravitysmtp' ),
'snackbar_activity_log_delete_error' => esc_html__( 'Error deleting log entries', 'gravitysmtp' ),
'snackbar_email_log_error' => esc_html__( 'Error getting email log for requested page', 'gravitysmtp' ),
'snackbar_email_log_detail_generic_error' => esc_html__( 'Error getting email log details', 'gravitysmtp' ),
'snackbar_email_log_detail_empty_error' => esc_html__( 'Error getting email log details, the log data was empty', 'gravitysmtp' ),
'snackbar_email_log_delete_error' => esc_html__( 'Error deleting email log', 'gravitysmtp' ),
'snackbar_activity_log_delete_success' => esc_html__( 'Email log successfully deleted', 'gravitysmtp' ),
'snackbar_debug_log_delete_error' => esc_html__( 'Error deleting debug log', 'gravitysmtp' ),
'snackbar_debug_log_delete_success' => esc_html__( 'Debug log successfully deleted', 'gravitysmtp' ),
'snackbar_url_copied' => esc_html__( 'URL copied to clipboard', 'gravitysmtp' ),
'test_mode_warning_notice' => esc_html__( 'Test mode is enabled, emails will not be sent.', 'gravitysmtp' ),
),
'data' => array(
'constants' => array(
'CAPS_DELETE_DEBUG_LOG' => Roles::DELETE_DEBUG_LOG,
'CAPS_DELETE_EMAIL_LOG' => Roles::DELETE_EMAIL_LOG,
'CAPS_DELETE_EMAIL_LOG_DETAILS' => Roles::DELETE_EMAIL_LOG_DETAILS,
'CAPS_EDIT_ALERTS' => Roles::EDIT_ALERTS,
'CAPS_EDIT_ALERTS_SLACK_SETTINGS' => Roles::EDIT_ALERTS_SLACK_SETTINGS,
'CAPS_EDIT_ALERTS_TWILIO_SETTINGS' => Roles::EDIT_ALERTS_TWILIO_SETTINGS,
'CAPS_EDIT_DEBUG_LOG' => Roles::EDIT_DEBUG_LOG,
'CAPS_EDIT_EMAIL_LOG' => Roles::EDIT_EMAIL_LOG,
'CAPS_EDIT_EMAIL_LOG_DETAILS' => Roles::EDIT_EMAIL_LOG_DETAILS,
'CAPS_EDIT_EMAIL_LOG_SETTINGS' => Roles::EDIT_EMAIL_LOG_SETTINGS,
'CAPS_EDIT_DEBUG_LOG_SETTINGS' => Roles::EDIT_DEBUG_LOG_SETTINGS,
'CAPS_EDIT_EMAIL_MANAGEMENT_SETTINGS' => Roles::EDIT_EMAIL_MANAGEMENT_SETTINGS,
'CAPS_EDIT_GENERAL_SETTINGS' => Roles::EDIT_GENERAL_SETTINGS,
'CAPS_EDIT_INTEGRATIONS' => Roles::EDIT_INTEGRATIONS,
'CAPS_EDIT_LICENSE_KEY' => Roles::EDIT_LICENSE_KEY,
'CAPS_EDIT_EXPERIMENTAL_FEATURES' => Roles::EDIT_EXPERIMENTAL_FEATURES,
'CAPS_EDIT_NOTIFICATIONS_SETTINGS' => Roles::EDIT_NOTIFICATIONS_SETTINGS,
'CAPS_EDIT_TEST_MODE' => Roles::EDIT_TEST_MODE,
'CAPS_EDIT_UNINSTALL' => Roles::EDIT_UNINSTALL,
'CAPS_EDIT_USAGE_ANALYTICS' => Roles::EDIT_USAGE_ANALYTICS,
'CAPS_VIEW_ALERTS' => Roles::VIEW_ALERTS,
'CAPS_VIEW_ALERTS_SLACK_SETTINGS' => Roles::VIEW_ALERTS_SLACK_SETTINGS,
'CAPS_VIEW_ALERTS_TWILIO_SETTINGS' => Roles::VIEW_ALERTS_TWILIO_SETTINGS,
'CAPS_VIEW_DEBUG_LOG' => Roles::VIEW_DEBUG_LOG,
'CAPS_VIEW_EMAIL_LOG' => Roles::VIEW_EMAIL_LOG,
'CAPS_VIEW_EMAIL_LOG_DETAILS' => Roles::VIEW_EMAIL_LOG_DETAILS,
'CAPS_VIEW_EMAIL_LOG_PREVIEW' => Roles::VIEW_EMAIL_LOG_PREVIEW,
'CAPS_VIEW_EMAIL_LOG_SETTINGS' => Roles::VIEW_EMAIL_LOG_SETTINGS,
'CAPS_VIEW_DEBUG_LOG_SETTINGS' => Roles::VIEW_DEBUG_LOG_SETTINGS,
'CAPS_VIEW_EMAIL_MANAGEMENT_SETTINGS' => Roles::VIEW_EMAIL_MANAGEMENT_SETTINGS,
'CAPS_VIEW_GENERAL_SETTINGS' => Roles::VIEW_GENERAL_SETTINGS,
'CAPS_VIEW_INTEGRATIONS' => Roles::VIEW_INTEGRATIONS,
'CAPS_VIEW_LICENSE_KEY' => Roles::VIEW_LICENSE_KEY,
'CAPS_VIEW_EXPERIMENTAL_FEATURES' => Roles::VIEW_EXPERIMENTAL_FEATURES,
'CAPS_VIEW_NOTIFICATIONS_SETTINGS' => Roles::VIEW_NOTIFICATIONS_SETTINGS,
'CAPS_VIEW_TEST_MODE' => Roles::VIEW_TEST_MODE,
'CAPS_VIEW_TOOLS' => Roles::VIEW_TOOLS,
'CAPS_VIEW_TOOLS_SENDATEST' => Roles::VIEW_TOOLS_SENDATEST,
'CAPS_VIEW_TOOLS_SYSTEMREPORT' => Roles::VIEW_TOOLS_SYSTEMREPORT,
'CAPS_VIEW_UNINSTALL' => Roles::VIEW_UNINSTALL,
'CAPS_VIEW_USAGE_ANALYTICS' => Roles::VIEW_USAGE_ANALYTICS,
'CAPS_VIEW_DASHBOARD' => Roles::VIEW_DASHBOARD,
),
'debug_log_enabled' => $debug_log_enabled,
'experimental_features' => $experimental_features,
'param_keys' => array(
'alert_threshold_count' => Save_Alerts_Settings_Endpoint::PARAM_ALERT_THRESHOLD_COUNT,
'alert_threshold_interval' => Save_Alerts_Settings_Endpoint::PARAM_ALERT_THRESHOLD_INTERVAL,
'debug_log_enabled' => Save_Plugin_Settings_Endpoint::PARAM_DEBUG_LOG_ENABLED,
'debug_log_retention' => Save_Plugin_Settings_Endpoint::PARAM_DEBUG_LOG_RETENTION,
'enabled_experimental_features' => Experiment_Features_Handler::ENABLED_EXPERIMENTS_PARAM,
'event_log_enabled' => Save_Plugin_Settings_Endpoint::PARAM_EVENT_LOG_ENABLED,
'event_log_retention' => Save_Plugin_Settings_Endpoint::PARAM_EVENT_LOG_RETENTION,
'license_key' => Save_Plugin_Settings_Endpoint::PARAM_LICENSE_KEY,
'notifications_email_digest_enabled' => Save_Plugin_Settings_Endpoint::PARAM_NOTIFICATIONS_EMAIL_DIGEST_ENABLED,
'notifications_email_digest_frequency' => Save_Plugin_Settings_Endpoint::PARAM_NOTIFICATIONS_EMAIL_DIGEST_FREQUENCY,
'notify_when_email_sending_fails_enabled' => Save_Plugin_Settings_Endpoint::PARAM_NOTIFY_WHEN_EMAIL_SENDING_FAILS_ENABLED,
'save_attachments_enabled' => Save_Plugin_Settings_Endpoint::PARAM_SAVE_ATTACHMENTS_ENABLED,
'save_email_body_enabled' => Save_Plugin_Settings_Endpoint::PARAM_SAVE_EMAIL_BODY_ENABLED,
'slack_alerts' => Save_Alerts_Settings_Endpoint::PARAM_SLACK_ALERTS,
'slack_alerts_enabled' => Save_Plugin_Settings_Endpoint::PARAM_SLACK_ALERTS_ENABLED,
'test_mode' => Save_Plugin_Settings_Endpoint::PARAM_TEST_MODE,
'twilio_alerts' => Save_Alerts_Settings_Endpoint::PARAM_TWILIO_ALERTS,
'twilio_alerts_enabled' => Save_Plugin_Settings_Endpoint::PARAM_TWILIO_ALERTS_ENABLED,
'usage_analytics' => Save_Plugin_Settings_Endpoint::PARAM_USAGE_ANALYTICS,
),
'locked_settings' => $this->get_locked_settings(),
'test_mode_enabled' => $test_mode,
'usage_analytics_enabled' => $usage_analytics_enabled,
'usage_analytics_link' => 'https://docs.gravitysmtp.com/about-additional-data-collection/',
),
),
'hmr_dev' => defined( 'GRAVITYSMTP_ENABLE_HMR' ) && GRAVITYSMTP_ENABLE_HMR,
'public_path' => trailingslashit( Gravity_SMTP::get_base_url() ) . 'assets/js/dist/',
);
}
private function get_locked_settings() {
$return = array();
$defined_constants = array_filter( get_defined_constants(), function( $constant ) {
return strpos( $constant, 'GRAVITYSMTP_' ) !== false;
}, ARRAY_FILTER_USE_KEY );
foreach( $defined_constants as $constant => $constant_value ) {
$setting_name = strtolower( str_replace( 'GRAVITYSMTP_', '', $constant ) );
$return[] = $setting_name;
}
return $return;
}
}
@@ -0,0 +1,572 @@
<?php
namespace Gravity_Forms\Gravity_SMTP\Apps\Config;
use Gravity_Forms\Gravity_SMTP\Apps\App_Service_Provider;
use Gravity_Forms\Gravity_SMTP\Apps\Endpoints\Get_Dashboard_Data_Endpoint;
use Gravity_Forms\Gravity_SMTP\Connectors\Connector_Service_Provider;
use Gravity_Forms\Gravity_SMTP\Data_Store\Data_Store_Router;
use Gravity_Forms\Gravity_SMTP\Feature_Flags\Feature_Flag_Manager;
use Gravity_Forms\Gravity_SMTP\Gravity_SMTP;
use Gravity_Forms\Gravity_SMTP\Models\Event_Model;
use Gravity_Forms\Gravity_SMTP\Utils\Booliesh;
use Gravity_Forms\Gravity_Tools\Config;
use Gravity_Forms\Gravity_Tools\Config_Data_Parser;
class Dashboard_Config extends Config {
const DEFAULT_DATE_RANGE_INTERVAL = 90;
protected $script_to_localize = 'gravitysmtp_scripts_admin';
protected $name = 'gravitysmtp_admin_config';
protected $overwrite = false;
private $start;
private $end;
private $period;
/**
* @var Event_Model
*/
private $model;
public function __construct( Config_Data_Parser $parser ) {
parent::__construct( $parser );
/**
* @var Data_Store_Router $settings
*/
$settings = Gravity_SMTP::$container->get( Connector_Service_Provider::DATA_STORE_ROUTER );
$this->model = Gravity_SMTP::$container->get( Connector_Service_Provider::EVENT_MODEL );
}
public function should_enqueue() {
$enabled = Feature_Flag_Manager::is_enabled( App_Service_Provider::FEATURE_FLAG_DASHBOARD );
if ( ! $enabled ) {
return false;
}
$page = filter_input( INPUT_GET, 'page' );
if ( ! is_string( $page ) ) {
return false;
}
$page = htmlspecialchars( $page );
return $page === 'gravitysmtp-dashboard';
}
public function data() {
$mod_string = sprintf( '-%d days', self::DEFAULT_DATE_RANGE_INTERVAL );
// Default to Last 3 Months
$this->start = gmdate( 'Y-m-d 00:00:00', strtotime( $mod_string ) );
// Get minimum start date based on data.
$this->start = $this->get_min_start_date( true );
$this->end = gmdate( 'Y-m-d 23:59:59', strtotime( "+1 day") );
// Determine proper period to use.
$this->period = $this->get_period_from_ranges();
return array(
'common' => array(
'endpoints' => array(
Get_Dashboard_Data_Endpoint::ACTION_NAME => array(
'action' => array(
'value' => Get_Dashboard_Data_Endpoint::ACTION_NAME,
'default' => 'mock_endpoint',
),
'nonce' => array(
'value' => wp_create_nonce( Get_Dashboard_Data_Endpoint::ACTION_NAME ),
'default' => 'nonce',
),
),
)
),
'components' => array(
'dashboard' => array(
'i18n' => $this->i18n_values(),
'data' => $this->data_values(),
),
)
);
}
public function ajax_data( $start, $end, $period ) {
$this->start = $start;
$this->end = $end;
if ( is_numeric( $period ) ) {
switch( $period ) {
case 0:
default:
$period = $this->get_period_from_ranges();
break;
case 1:
$period = 'hour';
break;
case 7:
$period = 'day';
break;
case 30:
case 90:
case 180:
$period = 'day';
break;
case 365:
$period = 'month';
break;
}
}
$this->period = $period;
return $this->data_values();
}
protected function get_period_from_ranges() {
$start = date_create( $this->start );
$end = date_create( $this->end );
$interval = date_diff( $start, $end );
$diff = $interval->format( '%a' );
if ( $diff <= 1 ) {
return 'hour';
}
if ( $diff < 180 ) {
return 'day';
}
return 'month';
}
protected function i18n_values() {
return array(
'totals' => array(
'headings' => array(
'emails' => __( 'Processed', 'gravitysmtp' ),
'sent' => __( 'Sent', 'gravitysmtp' ),
'failed' => __( 'Failed', 'gravitysmtp' ),
),
),
'stats' => array(
'heading' => __( 'Email Overview', 'gravitystmp' ),
'no_data_heading' => __( 'This is where your email statistics will appear.', 'gravitysmtp' ),
'no_data_message' => __( 'No data for the selected date range.', 'gravitysmtp' ),
'checkboxes' => array(
'sent' => __( 'Sent', 'gravitysmtp' ),
'failed' => __( 'Failed', 'gravitysmtp' ),
),
'date_range_label' => __( 'Date Range', 'gravitysmtp' ),
'calendar_label' => __( 'Custom Date', 'gravitysmtp' ),
),
'rankings' => array(
'headings' => array(
'your_integrations' => __( 'Your Integrations', 'gravitysmtp' ),
'sources' => __( 'Top Sending Sources', 'gravitysmtp' ),
'recipients' => __( 'Top Email Recipients', 'gravitysmtp' ),
'quick_links' => __( 'Quick Links', 'gravitysmtp' ),
),
'email' => __( '%1$s Email', 'gravitysmtp' ),
'emails' => __( '%1$s Emails', 'gravitysmtp' ),
'tags' => array(
'primary' => __( 'Primary', 'gravitysmtp' ),
'backup' => __( 'Backup', 'gravitysmtp' ),
'connected' => __( 'Connected', 'gravitysmtp' ),
'configured' => __( 'Configured', 'gravitysmtp' ),
'not_configured' => __( 'Not Configured', 'gravitysmtp' ),
),
),
);
}
protected function data_values() {
$totals = $this->get_email_totals();
return array(
'totals' => $totals,
'chart' => $this->get_chart_data(),
'date_ranges' => array(
'options' => $this->get_date_options(),
'initial_value' => $this->get_initial_range_value_from_data( true ),
'min_start' => $this->model->get_earliest_event_date(),
'max_end' => get_date_from_gmt( $this->end ),
),
'integrations_url' => admin_url( 'admin.php?page=gravitysmtp-settings&tab=integrations&integration=%1$s' ),
'source_icons_url' => trailingslashit( GF_GRAVITY_SMTP_PLUGIN_URL ) . 'assets/images/plugin-icons/',
'rankings' => array(
'your_integrations' => $this->get_your_integrations_info(),
'sources' => $this->get_top_sending_sources(),
'recipients' => $this->get_top_email_recipients(),
'quick_links' => $this->get_quick_links(),
),
);
}
protected function get_initial_range_value_from_data( $respect_default = false ) {
$diff = $this->get_max_interval_diff();
$options = array( 1, 7, 30, 90, 180, 365 );
$value = 365;
foreach ( $options as $option ) {
if ( $diff <= $option ) {
$value = $option;
break;
}
}
if ( $respect_default && $value > self::DEFAULT_DATE_RANGE_INTERVAL ) {
return self::DEFAULT_DATE_RANGE_INTERVAL;
}
return $value;
}
protected function get_date_options() {
$diff = $this->get_max_interval_diff();
$options = array(
array(
'label' => __( 'Last Day', 'gravitysmtp' ),
'value' => 1,
),
array(
'label' => __( 'Last 7 Days', 'gravitysmtp' ),
'value' => 7,
),
array(
'label' => __( 'Last 30 Days', 'gravitysmtp' ),
'value' => 30,
),
array(
'label' => __( 'Last 90 Days', 'gravitysmtp' ),
'value' => 90,
),
array(
'label' => __( 'Last 180 Days', 'gravitysmtp' ),
'value' => 180,
),
array(
'label' => __( 'Last 365 Days', 'gravitysmtp' ),
'value' => 365,
),
);
if ( $diff <= 1 ) {
$options = array(
reset( $options ),
);
return $options;
}
$parsed_options = array();
foreach ( $options as $key => $option ) {
$value = $option['value'];
$next = isset( $options[ $key + 1 ] ) ? $options[ $key + 1 ]['value'] : - 1;
if ( $diff >= $value ) {
$parsed_options[] = $option;
} else {
continue;
}
if ( $diff < $next ) {
$parsed_options[] = $options[ $key + 1 ];
}
}
return array_values( $parsed_options );
}
private function get_max_interval_diff() {
$earliest_date = date_create( $this->model->get_earliest_event_date() );
$today = date_create( date( 'Y:m:d 23:59:59' ) );
$interval = date_diff( $earliest_date, $today );
return (int) $interval->format( '%a' );
}
protected function get_chart_data() {
$data = $this->model->get_chart_data( $this->start, $this->end );
list( $format ) = $this->get_date_format_and_interval();
$sorted = array_reduce(
$data,
function( $carry, $item ) use ( $format ) {
$key = get_date_from_gmt( $item['date_created'], $format );
if ( ! array_key_exists( $key , $carry ) ) {
$carry[ $key ] = array(
'sent' => 0,
'failed' => 0,
);
}
if ( $item['status'] === 'sent' ) {
$carry[ $key ]['sent'] += 1;
} elseif ( $item['status'] === 'failed' ) {
$carry[ $key ]['failed'] += 1;
}
return $carry;
},
array()
);
// $sorted = array();
//
// foreach( $data as $datum ) {
// if ( ! array_key_exists( $datum['date_created'], $sorted ) ) {
// $sorted[ $datum['date_created'] ] = array(
// 'sent' => 0,
// 'failed' => 0,
// );
// }
//
// if ( $datum['status'] !== 'sent' && $datum['status'] !== 'failed' ) {
// continue;
// }
//
// $sorted[ $datum['date_created'] ][ $datum['status'] ] += $datum['total'];
// }
$sorted = $this->pad_with_empty_values( $sorted );
$chart_data = array();
foreach ( $sorted as $date => $values ) {
$chart_data[] = array(
'xAxisKey' => $date,
'sent' => $values['sent'],
'failed' => $values['failed'],
);
}
return array(
'config' => array(
'start' => $this->get_min_start_date(),
'end' => get_date_from_gmt( $this->end ),
'period' => $this->period
),
'values' => $chart_data,
'datasets' => array(
array(
'label' => __( 'Sent', 'gravitysmtp' ),
'dataKey' => 'sent',
'color' => '#82ca9d',
'defaultChecked' => true
),
array(
'label' => __( 'Failed', 'gravitysmtp' ),
'dataKey' => 'failed',
'color' => '#ff6b6b',
'defaultChecked' => true
),
),
);
}
protected function pad_with_empty_values( $data ) {
// Don't pad empty results.
if ( empty( $data ) ) {
return $data;
}
list( $format, $interval ) = $this->get_date_format_and_interval();
$period = new \DatePeriod(
new \DateTime( get_date_from_gmt( $this->start ) ),
new \DateInterval( $interval ),
new \DateTime( get_date_from_gmt( $this->end ) )
);
$sorted_values = array();
foreach( $period as $key => $value ) {
$date = $value->format( $format );
if ( ! array_key_exists( $date, $data ) ) {
$sorted_values[ $date ] = array(
'sent' => 0,
'failed' => 0,
);
} else {
$sorted_values[ $date ] = $data[ $date ];
}
}
return $sorted_values;
}
protected function get_date_format_and_interval() {
switch( $this->period ) {
case 'day':
default:
$format = 'M d';
$interval = 'P1D';
break;
case 'month':
$format = 'M Y';
$interval = 'P1M';
break;
case 'hour':
$format = 'H:00 M d';
$interval = 'PT1H';
break;
}
return array( $format, $interval );
}
protected function get_email_totals() {
$stats = $this->model->get_event_stats( $this->start, $this->end );
$total = array_sum( $stats );
return array(
'emails' => $total,
'sent' => isset( $stats['sent'] ) ? $stats['sent'] : 0,
'failed' => isset( $stats['failed'] ) ? $stats['failed'] : 0,
);
}
protected function get_top_sending_sources() {
$sources = $this->model->get_top_sending_sources( $this->start, $this->end );
// Some old entries are missing the source param and return the `headers` instead.
$sources = array_filter( $sources, function ( $data ) {
return $data['source'] !== 'headers' && $data['source'] !== 'message_omitted';
} );
return array_values( $sources );
}
protected function get_top_email_recipients() {
$recipients = $this->model->get_top_recipients( $this->start, $this->end );
array_walk( $recipients, function ( &$item ) {
$item['hash'] = hash( 'sha256', $item['recipients'] );
} );
$recipients = array_filter( $recipients, function ( $data ) {
return $data['recipients'] !== 'headers' && $data['recipients'] !== 'message_omitted' && ! empty( $data['recipients'] );
} );
return array_values( $recipients );
}
protected function get_your_integrations_info() {
$connector_data = Gravity_SMTP::$container->get( Connector_Service_Provider::CONNECTOR_DATA_MAP );
$return = array();
$connector_data = array_filter( $connector_data, function ( $info ) {
return $info['data']['enabled'] && $info['data']['activated'];
} );
foreach ( $connector_data as $connector => $info ) {
$data = $info['data'];
$return[] = array(
'is_primary' => $data['is_primary'],
'is_backup' => $data['is_backup'],
'configured' => $data['configured'],
'name' => $connector,
'label' => $info['title'],
'logo' => $info['logo'],
);
}
usort( $return, function ( $a, $b ) {
if ( $a['is_primary'] && $b['is_primary'] ) {
return 0;
}
if ( $a['is_backup'] && $b['is_backup'] ) {
return 0;
}
if ( $a['is_primary'] && $b['is_backup'] ) {
return - 1;
}
if ( $a['is_backup'] && $b['is_primary'] ) {
return 1;
}
if ( $a['is_primary'] ) {
return - 1;
}
if ( $a['is_backup'] ) {
return - 1;
}
return 1;
} );
return $return;
}
protected function get_quick_links() {
// @todo - get actual values.
return array(
array(
'label' => __( 'Getting Started', 'gravitysmtp' ),
'href' => 'https://docs.gravitysmtp.com/category/getting-started/',
),
array(
'label' => __( 'Troubleshooting Gravity SMTP', 'gravitysmtp' ),
'href' => 'https://docs.gravitysmtp.com/troubleshooting-gravity-smtp/',
),
array(
'label' => __( 'Email Delivery Best Practices', 'gravitysmtp' ),
'href' => 'https://docs.gravitysmtp.com/email-delivery-best-practices/',
),
array(
'label' => __( 'An Overview of Gravity SMTP', 'gravitysmtp' ),
'href' => 'https://docs.gravitysmtp.com/using-gravity-smtp/',
),
array(
'label' => __( 'Integrations', 'gravitysmtp' ),
'href' => 'https://docs.gravitysmtp.com/category/integrations/',
),
array(
'label' => __( 'Frequently Asked Questions', 'gravitysmtp' ),
'href' => 'https://docs.gravitysmtp.com/frequently-asked-questions/',
),
array(
'label' => __( 'Gravity SMTP Changelog', 'gravitysmtp' ),
'href' => 'https://docs.gravitysmtp.com/gravity-smtp-changelog/',
),
array(
'label' => __( 'Open Support Ticket', 'gravitysmtp' ),
'href' => 'https://www.gravityforms.com/open-support-ticket/',
),
);
}
private function get_min_start_date( $restrict_to_range = false ) {
$earliest_date = $this->model->get_earliest_event_date();
$passed_start = strtotime( $this->start );
$calculated_start = strtotime( $earliest_date );
// Passed start is after the minimum retention period start, return it.
if ( $calculated_start <= $passed_start ) {
return get_date_from_gmt( $this->start );
}
if ( ! $restrict_to_range ) {
return $earliest_date;
}
// Passed start is *before* minimum retention period start, return retention period start.
$range_diff = $this->get_initial_range_value_from_data();
$mod_string = sprintf( '-%d days', ( $range_diff - 1 ) );
return gmdate( 'Y-m-d 00:00:00', strtotime( $mod_string ) );
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,196 @@
<?php
namespace Gravity_Forms\Gravity_SMTP\Apps\Config;
use Gravity_Forms\Gravity_SMTP\Apps\App_Service_Provider;
use Gravity_Forms\Gravity_SMTP\Connectors\Connector_Service_Provider;
use Gravity_Forms\Gravity_SMTP\Gravity_SMTP;
use Gravity_Forms\Gravity_Tools\Config;
class Email_Log_Single_Config extends Config {
protected $script_to_localize = 'gravitysmtp_scripts_admin';
protected $name = 'gravitysmtp_admin_config';
protected $overwrite = false;
public function should_enqueue() {
if ( ! is_admin() ) {
return false;
}
$page = filter_input( INPUT_GET, 'page' );
if ( ! is_string( $page ) ) {
return false;
}
$page = htmlspecialchars( $page );
$event_id = filter_input( INPUT_GET, 'event_id', FILTER_SANITIZE_NUMBER_INT );
if ( $page !== 'gravitysmtp-activity-log' || empty( $event_id ) ) {
return false;
}
return true;
}
public function get_i18n() {
return array(
'error_alert_title' => esc_html__( 'Error Saving', 'gravitysmtp' ),
'error_alert_generic_message' => esc_html__( 'Could not save; please check your logs.', 'gravitysmtp' ),
'error_alert_close_text' => esc_html__( 'Close', 'gravitysmtp' ),
'log_detail' => array(
'top_heading' => esc_html__( 'Email Log Details', 'gravitysmtp' ),
// 'top_content' => esc_html__( '', 'gravitysmtp' ),
'top_error' => esc_html__( 'The email could not be found, go back and try again.', 'gravitysmtp' ),
'action_button_view_email_label' => esc_html__( 'View Email', 'gravitysmtp' ),
'action_button_resend_label' => esc_html__( 'Resend', 'gravitysmtp' ),
'action_button_print_label' => esc_html__( 'Print', 'gravitysmtp' ),
'action_button_export_label' => esc_html__( 'Export', 'gravitysmtp' ),
'action_button_delete_label' => esc_html__( 'Delete Log Entry', 'gravitysmtp' ),
'back_button_label' => esc_html__( 'Back to Email Log', 'gravitysmtp' ),
'main_box_heading' => esc_html__( 'Email Details', 'gravitysmtp' ),
'main_box_bcc_label' => esc_html__( 'BCC', 'gravitysmtp' ),
'main_box_cc_label' => esc_html__( 'CC', 'gravitysmtp' ),
'main_box_date_label' => esc_html__( 'Date Sent', 'gravitysmtp' ),
'main_box_from_label' => esc_html__( 'From', 'gravitysmtp' ),
'main_box_to_label' => esc_html__( 'To', 'gravitysmtp' ),
'main_box_subject_label' => esc_html__( 'Subject', 'gravitysmtp' ),
'nav_button_next_title' => esc_html__( 'Navigate to the next log detail', 'gravitysmtp' ),
'nav_button_prev_title' => esc_html__( 'Navigate to the previous log detail', 'gravitysmtp' ),
'secondary_box_heading' => esc_html__( 'Technical Information', 'gravitysmtp' ),
'secondary_box_log_heading' => esc_html__( 'Log', 'gravitysmtp' ),
'secondary_box_headers_heading' => esc_html__( 'Headers', 'gravitysmtp' ),
'sidebar_status_heading' => esc_html__( 'Log Details', 'gravitysmtp' ),
'sidebar_status_label' => esc_html__( 'Status:', 'gravitysmtp' ),
'sidebar_service_label' => esc_html__( 'Service:', 'gravitysmtp' ),
'sidebar_has_attachment_label' => esc_html__( 'Has attachment:', 'gravitysmtp' ),
'sidebar_log_id_label' => esc_html__( 'Log ID:', 'gravitysmtp' ),
'sidebar_source_label' => esc_html__( 'Source:', 'gravitysmtp' ),
'sidebar_attachments_heading' => esc_html__( 'Attachments', 'gravitysmtp' ),
'view_email_desktop_mode' => esc_html__( 'Preview email in desktop mode', 'gravitysmtp' ),
'view_email_mobile_mode' => esc_html__( 'Preview email in mobile mode', 'gravitysmtp' ),
),
/* translators: %1$s is the body of the ajax request. */
'resending_email' => esc_html__( 'Resending email: %1$s', 'gravitysmtp' ),
/* translators: %1$s is the error message. */
'resending_error' => esc_html__( 'Error resending email: %1$s', 'gravitysmtp' ),
'snackbar_resend_error' => esc_html__( 'Error resending email', 'gravitysmtp' ),
'snackbar_resend_success' => esc_html__( 'Email successfully resent', 'gravitysmtp' ),
);
}
public function get_log_single_data() {
return array(
'log_detail' => array(
'default' => $this->get_default_log_details(),
'value' => $this->get_log_details(),
),
);
}
private function get_default_log_data() {
$headers = array(
'body' => array(
'to' => 'someuser@its.rochester.edu',
'subject' => 'My mail message is about.',
),
'headers' => array(
'from: somesender@mail.rochester.edu',
'content-type: text/html',
),
);
$text = 'Received: from antivirus1.its.rochester.edu (antivirus.its.rochester.edu [128.151.57.50])
by mail.rochester.edu (8.12.8/8.12.4) with ESMTP id h20GQs90002563;
Mon, 24 Mar 2003 11:26:54 -0500 (EST)
Received: from antivirus.its.rochester.edu (localhost [127.0.0.1])
by antivirus1.its.rochester.edu (8.12.8/8.12.4) with ESMTP id h20GOr0x003450;
Mon, 24 Mar 2003 11:26:54 -0500 (EST)
Received: from galileo.cc.rochester.edu (galileo.cc.rochester.edu [128.151.224.6])
by antivirus1.its.rochester.edu (8.12.8/8.12.4) with SMTP id h20GOrDC003447;
Mon, 24 Mar 2003 11:26:53 -0500 (EST)
Received: (from majord@localhost)
by galileo.cc.rochester.edu (8.12.8/8.12.4) id h20GQg91029757;
Mon, 24 Mar 2003 11:26:52 -0500 (EST)
Date: Mon, 24 Mar 2003 11:26:50 -0500 (EST)
From: somesender@mail.rochester.edu
Message-Id: <200303241626.h20GQoit002507@mail.rochester.edu>
To: someuser@its.rochester.edu
Subject: My mail message is about.';
$lines = explode( "\n", $text );
$temp_log_detail_techincal_data = array();
foreach ( $lines as $index => $line ) {
$temp_log_detail_techincal_data[ $index ] = $line;
}
return array(
'log' => $temp_log_detail_techincal_data,
'headers' => $headers,
);
}
private function get_default_log_details() {
return array(
'date' => 'March 7, 2023 at 8:07 pm',
'from' => 'carl@gmail.com',
'to' => 'carl@hancock.io',
'subject' => 'New WordPress User Registration',
'technical_information' => $this->get_default_log_data(),
'status' => array(
'label' => 'Sent',
'status' => 'active',
),
'service' => 'Amazon SES',
'has_attachment' => 3,
'attachments' => array(
array(
'file_name' => 'test.pdf',
'file_path' => 'http://example.com/wp-content/uploads/gravity_forms/2023/08/test.pdf',
'file_extension' => 'pdf',
),
array(
'file_name' => 'test2.pdf',
'file_path' => 'http://example.com/wp-content/uploads/gravity_forms/2023/08/test2.pdf',
'file_extension' => 'pdf',
),
array(
'file_name' => 'test3.pdf',
'file_path' => 'http://example.com/wp-content/uploads/gravity_forms/2023/08/test3.pdf',
'file_extension' => 'pdf',
),
),
'log_id' => '12',
'source' => 'Gravity Forms',
);
}
private function get_log_details() {
$id = filter_input( INPUT_GET, 'event_id', FILTER_SANITIZE_NUMBER_INT );
if ( empty( $id ) ) {
return array();
}
$container = Gravity_SMTP::container();
$logs = $container->get( Connector_Service_Provider::LOG_DETAILS_MODEL );
return $logs->full_details( $id );
}
public function data() {
$log_config = Gravity_SMTP::container()->get( App_Service_Provider::EMAIL_LOG_CONFIG );
return array(
'components' => array(
'activity_log' => array(
'data' => array_merge( $this->get_log_single_data(), $log_config->get_log_data() ),
'i18n' => array_merge( $this->get_i18n(), $log_config->get_i18n() ),
'endpoints' => array(),
),
),
);
}
}
@@ -0,0 +1,629 @@
<?php
namespace Gravity_Forms\Gravity_SMTP\Apps\Config;
use Gravity_Forms\Gravity_SMTP\Gravity_SMTP;
use Gravity_Forms\Gravity_SMTP\Connectors\Connector_Service_Provider;
use Gravity_Forms\Gravity_SMTP\Connectors\Endpoints\Save_Plugin_Settings_Endpoint;
use Gravity_Forms\Gravity_SMTP\Users\Roles;
use Gravity_Forms\Gravity_SMTP\Utils\Booliesh;
use Gravity_Forms\Gravity_Tools\Config;
use Gravity_Forms\Gravity_Tools\License\License_Statuses;
use Gravity_Forms\Gravity_Tools\Updates\Updates_Service_Provider;
class Settings_Config extends Config {
protected $script_to_localize = 'gravitysmtp_scripts_admin';
protected $name = 'gravitysmtp_admin_config';
protected $overwrite = false;
public function should_enqueue() {
if ( ! is_admin() ) {
return false;
}
$page = filter_input( INPUT_GET, 'page' );
if ( ! is_string( $page ) ) {
return false;
}
$page = htmlspecialchars( $page );
if ( $page !== 'gravitysmtp-settings' ) {
return false;
}
return true;
}
public function data() {
$container = Gravity_SMTP::container();
$plugin_data_store = $container->get( Connector_Service_Provider::DATA_STORE_ROUTER );
$license_key = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_LICENSE_KEY, '' );
$key_is_empty = empty( $license_key );
$is_valid = null;
if ( ! $key_is_empty ) {
$license_info = $container->get( Updates_Service_Provider::LICENSE_API_CONNECTOR )->check_license( $license_key );
$is_valid = License_Statuses::VALID_KEY === $license_info->get_status();
}
$email_log_enabled = Booliesh::get( $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_EVENT_LOG_ENABLED, 'true' ) );
$save_email_body_enabled = Booliesh::get( $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_SAVE_EMAIL_BODY_ENABLED, 'true' ) );
$save_attachments_enabled = Booliesh::get( $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_SAVE_ATTACHMENTS_ENABLED, 'false' ) );
$email_log_retention = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_EVENT_LOG_RETENTION, 7 );
$max_records_value = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_MAX_EVENT_RECORDS, 0 );
$debug_log_enabled = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_DEBUG_LOG_ENABLED, 'false' );
$debug_log_enabled = ! empty( $debug_log_enabled ) ? $debug_log_enabled !== 'false' : false;
$debug_log_retention = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_DEBUG_LOG_RETENTION, 7 );
$notifications_email_digest_enabled = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_NOTIFICATIONS_EMAIL_DIGEST_ENABLED, 'false' );
$notifications_email_digest_enabled = ! empty( $notifications_email_digest_enabled ) ? $notifications_email_digest_enabled !== 'false' : false;
$notifications_email_digest_frequency = $plugin_data_store->get_plugin_setting( Save_Plugin_Settings_Endpoint::PARAM_NOTIFICATIONS_EMAIL_DIGEST_FREQUENCY, 7 );
$primary_locked = defined( 'GRAVITYSMTP_INTEGRATION_PRIMARY' );
$backup_locked = defined( 'GRAVITYSMTP_INTEGRATION_BACKUP' );
// @translators: %d is an integer representing the maximum number of records to store in the log.
$max_records_message = esc_html__( 'The Email Log is set to store a maximum of %d records. Any records over that limit will be deleted, starting with oldest records first.', 'gravitysmtp' );
return array(
'components' => array(
'settings' => array(
'i18n' => array(
'error_alert_title' => esc_html__( 'Error Saving', 'gravitysmtp' ),
'error_alert_generic_message' => esc_html__( 'Could not save, please check your logs.', 'gravitysmtp' ),
'error_alert_close_text' => esc_html__( 'Close', 'gravitysmtp' ),
'debug_messages' => array(
/* translators: %1$s is the body of the ajax request. */
'uninstalling_plugin' => esc_html__( 'Uninstalling plugin: %1$s', 'gravitysmtp' ),
/* translators: %1$s is the error. */
'uninstalling_plugin_error' => esc_html__( 'Error uninstalling plugin: %1$s', 'gravitysmtp' ),
),
'unsaved_changes_title' => esc_html__( 'Unsaved Changes', 'gravitysmtp' ),
'unsaved_changes_message' => esc_html__( 'You have unsaved changes. Are you sure you want to leave this page?', 'gravitysmtp' ),
'settings' =>
array(
'top_heading' => esc_html__( 'Settings', 'gravitysmtp' ),
'top_content' => '',
'license_box_heading' => esc_html__( 'License', 'gravitysmtp' ),
'license_box_content' => esc_html__( 'A valid license key is required for access to automatic plugin upgrades and product support.', 'gravitysmtp' ),
'license_box_input_label' => esc_html__( 'License Key', 'gravitysmtp' ),
'license_box_input_help_text' => esc_html__( 'Enter your license key to gain access to plugin updates.', 'gravitysmtp' ),
'license_box_input_link_text' => esc_html__( 'Already purchased?', 'gravitysmtp' ),
'license_box_button_text' => esc_html__( 'Save License', 'gravitysmtp' ),
'license_valid' => esc_html__( 'License key successfully validated!', 'gravitysmtp' ),
'license_invalid' => esc_html__( 'Invalid license key entered. Please check your license key and try again.', 'gravitysmtp' ),
'experiments_box_heading' => esc_html__( 'Experimental Features', 'gravitysmtp' ),
'experiments_box_content' => esc_html__( 'These features are works-in-progress, so you may find some bugs along the way.', 'gravitysmtp' ),
'experiments_box_toggle_label' => esc_html__( 'Alerts', 'gravitysmtp' ),
'experiments_box_toggle_help_text' => esc_html__( 'Get notified via webhook or SMS (Twilio) when emails fail to send.', 'gravitysmtp' ),
'test_mode_box_heading' => esc_html__( 'Test Mode', 'gravitysmtp' ),
/* translators: %s: opening and closing anchor tags */
'test_mode_box_content_1' => esc_html__( 'When test mode is on, your site will not send out any emails. If you turn on %semail logging%s, all emails will be stored in the Email Logs.', 'gravitysmtp' ),
'test_mode_box_toggle_help_text' => esc_html__( 'Note: Some WordPress plugins use their own email delivery system instead of the standard wp_mail() function. Test mode might not block emails sent by these plugins. Consult their documentation to learn how to enable test emails.', 'gravitysmtp' ),
'test_mode_box_toggle_label' => esc_html__( 'Enable Test Mode', 'gravitysmtp' ),
'general_settings_box_heading' => esc_html__( 'General Settings', 'gravitysmtp' ),
'uninstall_box_heading' => esc_html__( 'Uninstall', 'gravitysmtp' ),
'uninstall_box_content' => esc_html__( 'This operation deletes ALL Gravity SMTP settings. If you continue, you will NOT be able to retrieve these settings.', 'gravitysmtp' ),
'uninstall_box_button_label' => esc_html__( 'Erase ALL Gravity SMTP Data', 'gravitysmtp' ),
'uninstall_dialog_confirm_change_heading' => esc_html__( 'Confirm Delete', 'gravitysmtp' ),
'uninstall_dialog_confirm_change_content' => esc_html__( 'This operation deletes ALL Gravity SMTP settings. If you continue, you will NOT be able to retrieve these settings.', 'gravitysmtp' ),
'uninstall_dialog_confirm_change_confirm' => esc_html__( 'Delete', 'gravitysmtp' ),
'error_uninstalling_message' => esc_html__( 'There was an error uninstalling Gravity SMTP', 'gravitysmtp' ),
),
'integrations' =>
array(
'top_heading' => esc_html__( 'Integrations', 'gravitysmtp' ),
'top_content' => esc_html__( 'Manage all your email connections. Click the + icon to add an integration; you can connect one or multiple services to handle your sites emails.', 'gravitysmtp' ),
'card_more_settings' => esc_html__( 'More Settings', 'gravitysmtp' ),
'card_settings' => esc_html__( 'Settings', 'gravitysmtp' ),
'card_primary' => esc_html__( 'Primary', 'gravitysmtp' ),
'card_backup' => esc_html__( 'Backup', 'gravitysmtp' ),
'integration_settings_error' => esc_html__( 'There was an error saving your settings', 'gravitysmtp' ),
/* translators: %1$s is the integration name */
'set_primary_integration' => esc_html__( '%1$s set as primary integration', 'gravitysmtp' ),
/* translators: %1$s is the integration name */
'set_backup_integration' => esc_html__( '%1$s set as backup integration', 'gravitysmtp' ),
'primary_disabled_heading' => esc_html__( 'Primary Integration Disabled', 'gravitysmtp' ),
'primary_disabled_content' => esc_html__( 'You have disabled your primary email integration. To continue sending emails via Gravity SMTP, please enable a backup integration or set and enable a new primary integration.', 'gravitysmtp' ),
/* translators: %1$s is the integration name */
'integration_disabled' => esc_html__( '%1$s integration has been disabled', 'gravitysmtp' ),
'flyout' => array(
'screen01' => array(
'heading' => esc_html__( 'New Connection', 'gravitysmtp' ),
/* translators: {{suggest_link}} tags are replaced by opening and closing tags for a link to our suggest integration page */
'description' => __( "Select and configure the integration you would like to use to send emails from this site. Don't see an integration you're looking for? {{suggest_link}}Suggest an integration.{{suggest_link}}", 'gravitysmtp' ),
'search_placeholder' => esc_html__( 'Search integration', 'gravitysmtp' ),
'search_label' => esc_html__( 'Search integration', 'gravitysmtp' ),
),
'screen02' => array(
'back_button_label' => esc_html__( 'Back', 'gravitysmtp' ),
'save_button_label' => esc_html__( 'Save Settings', 'gravitysmtp' ),
'save_enable_button_label' => __( 'Save & Enable', 'gravitysmtp' ),
),
),
),
'emails' =>
array(
'top_heading' => esc_html__( 'Email Management', 'gravitysmtp' ),
'top_content' => __( "WordPress, by default, will send out emails for many events on your site. Using the toggles below, you can decide exactly which emails you'd like enabled.", 'gravitysmtp' ),
'email_notifications_box_heading' => esc_html__( 'Manage Emails', 'gravitysmtp' ),
),
'logging' =>
array(
'top_heading' => esc_html__( 'Logging', 'gravitysmtp' ),
'top_content' => '',
'logging_box_heading' => esc_html__( 'Email Logging', 'gravitysmtp' ),
'logging_box_content' => esc_html__( 'Email logging keeps copies of all emails sent from your WordPress site, so you can review your sent emails and check their delivery status.', 'gravitysmtp' ),
'enable_log_label' => esc_html__( 'Enable Log', 'gravitysmtp' ),
'enable_log_helper_text' => esc_html__( 'Keep copies of all emails sent from your site.', 'gravitysmtp' ),
'save_email_body_label' => esc_html__( 'Save Email Body', 'gravitysmtp' ),
'save_email_body_helper_text' => esc_html__( 'Store the email body for all emails sent from your site.', 'gravitysmtp' ),
'save_attachments_label' => esc_html__( 'Save Attachments', 'gravitysmtp' ),
'save_attachments_helper_text' => esc_html__( 'Store attachments on the server in the uploads folder.', 'gravitysmtp' ),
'email_log_retention_label' => esc_html__( 'Log Retention Period', 'gravitysmtp' ),
'email_log_retention_helper_text' => esc_html__( 'Email logs older than the selected timeframe will be permanently deleted.', 'gravitysmtp' ),
'email_log_max_records_helper_text' => sprintf( $max_records_message, $max_records_value ),
/* translators: {{docs_link}} tags are replaced by opening and closing tags for a link to our log file retention periods documentation */
'email_log_resources_alert' => __( 'Large log files can quickly consume server resources and may impact site performance, especially on shared hosting. We recommend reviewing our {{docs_link}}log file retention periods article{{docs_link}} before enabling extended logging.', 'gravitysmtp' ),
'error_saving_snackbar_message' => esc_html__( 'There was an error saving the settings', 'gravitysmtp' ),
'debug_logging_box_heading' => esc_html__( 'Debug Logging', 'gravitysmtp' ),
'enable_debug_log_label' => esc_html__( 'Enable Debug Log', 'gravitysmtp' ),
'enable_debug_log_helper_text' => esc_html__( 'When enabled email sending errors debugging events will be logged, allowing you to detect email sending issues.', 'gravitysmtp' ),
'debug_log_retention_label' => esc_html__( 'Debug Log Retention Period', 'gravitysmtp' ),
'debug_log_retention_helper_text' => esc_html__( 'Debug events older than the selected period will be permanently deleted from the database.', 'gravitysmtp' ),
/* translators: {{docs_link}} tags are replaced by opening and closing tags for a link to our log file retention periods documentation */
'debug_log_resources_alert' => __( 'Debug logging should only be enabled temporarily when troubleshooting specific issues. Continuous logging can quickly consume server resources and may impact site performance, especially on shared hosting. We recommend reviewing our {{docs_link}}log file retention periods article{{docs_link}} before enabling debug logging.', 'gravitysmtp' ),
'view_activity_log_button_text' => esc_html__( 'View Email Log', 'gravitysmtp' ),
'delete_activity_log_button_text' => esc_html__( 'Delete Email Log', 'gravitysmtp' ),
'view_debug_log_button_text' => esc_html__( 'View Debug Log', 'gravitysmtp' ),
'copy_debug_log_button_text' => esc_html__( 'Copy Debug Log Link', 'gravitysmtp' ),
'delete_debug_log_button_text' => esc_html__( 'Delete Debug Log', 'gravitysmtp' ),
'delete_debug_log_dialog_confirm_change_heading' => esc_html__( 'Confirm Delete', 'gravitysmtp' ),
'delete_email_log_dialog_confirm_change_content' => esc_html__( 'This operation deletes ALL email logs. If you continue, you will NOT be able to retrieve these logs.', 'gravitysmtp' ),
'delete_debug_log_dialog_confirm_change_content' => esc_html__( 'This operation deletes ALL debug logs. If you continue, you will NOT be able to retrieve these logs.', 'gravitysmtp' ),
'delete_debug_log_dialog_confirm_change_confirm' => esc_html__( 'Delete', 'gravitysmtp' ),
),
'notifications' =>
array(
'email_digest_box_heading' => esc_html__( 'Email Activity Digest', 'gravitysmtp' ),
'email_digest_box_enabled_label' => esc_html__( 'Email Activity Digest', 'gravitysmtp' ),
'email_digest_box_enabled_helper_text' => __( 'Get a summary of your site\'s recent email activity delivered to your inbox. Includes key metrics like send volume, failures, and top emails.', 'gravitysmtp' ),
'email_digest_box_frequency_label' => esc_html__( 'Send Digest', 'gravitysmtp' ),
'email_digest_box_frequency_helper_text' => esc_html__( 'Select how often you want the email activity digest to be sent.', 'gravitysmtp' ),
'email_digest_box_send_preview_button_text' => esc_html__( 'Send Email Preview', 'gravitysmtp' ),
'error_sending_email_digest_preview_message' => esc_html__( 'Error sending email preview.', 'gravitysmtp' ),
'success_sending_email_digest_preview_message' => esc_html__( 'Email preview successfully sent!', 'gravitysmtp' ),
),
),
'data' => array(
'license_key' => $license_key,
'license_key_is_valid' => $is_valid,
'version' => GF_GRAVITY_SMTP_VERSION,
'email_log_settings' => array(
'email_log_enabled' => $email_log_enabled,
'email_log_retention' => $email_log_retention,
'email_log_url' => admin_url( 'admin.php?page=gravitysmtp-activity-log' ),
'log_retention_period_enabled' => ! Booliesh::get( $max_records_value ),
'max_records' => $max_records_value,
'max_records_set' => Booliesh::get( $max_records_value ),
'retention_options' => $this->get_email_log_retention_options( $email_log_retention ),
'save_attachments_enabled' => $save_attachments_enabled,
'save_email_body_enabled' => $save_email_body_enabled,
),
'debug_log_settings' => array(
'debug_log_enabled' => $debug_log_enabled,
'debug_log_retention' => $debug_log_retention,
'debug_log_url' => admin_url( 'admin.php?page=gravitysmtp-tools&tab=debug-log' ),
'retention_options' => $this->get_debug_log_retention_options( $debug_log_retention ),
),
'notifications_settings' => array(
'email_digest_enabled' => $notifications_email_digest_enabled,
'email_digest_frequency' => $notifications_email_digest_frequency,
'email_digest_frequency_options' => $this->get_notifications_email_digest_frequency_options(),
),
'caps' => array(
Roles::DELETE_DEBUG_LOG => current_user_can( Roles::DELETE_DEBUG_LOG ),
Roles::DELETE_EMAIL_LOG => current_user_can( Roles::DELETE_EMAIL_LOG ),
Roles::EDIT_ALERTS => current_user_can( Roles::EDIT_ALERTS ),
Roles::EDIT_ALERTS_SLACK_SETTINGS => current_user_can( Roles::EDIT_ALERTS_SLACK_SETTINGS ),
Roles::EDIT_ALERTS_TWILIO_SETTINGS => current_user_can( Roles::EDIT_ALERTS_TWILIO_SETTINGS ),
Roles::EDIT_DEBUG_LOG_SETTINGS => current_user_can( Roles::EDIT_DEBUG_LOG_SETTINGS ),
Roles::EDIT_EMAIL_LOG_SETTINGS => current_user_can( Roles::EDIT_EMAIL_LOG_SETTINGS ),
Roles::EDIT_EMAIL_MANAGEMENT_SETTINGS => current_user_can( Roles::EDIT_EMAIL_MANAGEMENT_SETTINGS ),
Roles::EDIT_INTEGRATIONS => current_user_can( Roles::EDIT_INTEGRATIONS ),
Roles::EDIT_LICENSE_KEY => current_user_can( Roles::EDIT_LICENSE_KEY ),
Roles::EDIT_EXPERIMENTAL_FEATURES => current_user_can( Roles::EDIT_EXPERIMENTAL_FEATURES ),
Roles::EDIT_NOTIFICATIONS_SETTINGS => current_user_can( Roles::EDIT_NOTIFICATIONS_SETTINGS ),
Roles::EDIT_TEST_MODE => current_user_can( Roles::EDIT_TEST_MODE ),
Roles::EDIT_UNINSTALL => current_user_can( Roles::EDIT_UNINSTALL ),
Roles::EDIT_USAGE_ANALYTICS => current_user_can( Roles::EDIT_USAGE_ANALYTICS ),
Roles::VIEW_ALERTS => current_user_can( Roles::VIEW_ALERTS ),
Roles::VIEW_ALERTS_SLACK_SETTINGS => current_user_can( Roles::VIEW_ALERTS_SLACK_SETTINGS ),
Roles::VIEW_ALERTS_TWILIO_SETTINGS => current_user_can( Roles::VIEW_ALERTS_TWILIO_SETTINGS ),
Roles::VIEW_DEBUG_LOG => current_user_can( Roles::VIEW_DEBUG_LOG ),
Roles::VIEW_DEBUG_LOG_SETTINGS => current_user_can( Roles::VIEW_DEBUG_LOG_SETTINGS ),
Roles::VIEW_EMAIL_LOG => current_user_can( Roles::VIEW_EMAIL_LOG ),
Roles::VIEW_EMAIL_LOG_SETTINGS => current_user_can( Roles::VIEW_EMAIL_LOG_SETTINGS ),
Roles::VIEW_EMAIL_MANAGEMENT_SETTINGS => current_user_can( Roles::VIEW_EMAIL_MANAGEMENT_SETTINGS ),
Roles::VIEW_INTEGRATIONS => current_user_can( Roles::VIEW_INTEGRATIONS ),
Roles::VIEW_LICENSE_KEY => current_user_can( Roles::VIEW_LICENSE_KEY ),
Roles::VIEW_EXPERIMENTAL_FEATURES => current_user_can( Roles::VIEW_EXPERIMENTAL_FEATURES ),
Roles::VIEW_NOTIFICATIONS_SETTINGS => current_user_can( Roles::VIEW_NOTIFICATIONS_SETTINGS ),
Roles::VIEW_TEST_MODE => current_user_can( Roles::VIEW_TEST_MODE ),
Roles::VIEW_UNINSTALL => current_user_can( Roles::VIEW_UNINSTALL ),
Roles::VIEW_USAGE_ANALYTICS => current_user_can( Roles::VIEW_USAGE_ANALYTICS ),
),
'email_digest_notifications' => array(
'email_digest_summary' => array(
'checked' => true,
'name' => 'email_digest_summary',
),
'notification_day' => array(
'options' => array(
array(
'label' => esc_html__( 'Every Day', 'gravitysmtp' ),
'value' => 'daily',
),
array(
'label' => esc_html__( 'Every Week', 'gravitysmtp' ),
'value' => 'weekly',
),
array(
'label' => esc_html__( 'Every Month', 'gravitysmtp' ),
'value' => 'monthly',
),
array(
'label' => esc_html__( 'Every Year', 'gravitysmtp' ),
'value' => 'yearly',
),
),
'name' => 'notification_day',
),
'notification_email_addresses' => array(
'value' => 'olivia@gravity.com, carl@hancock.io',
'name' => 'notification_email_addresses',
),
'enable_html_mode' => array(
'checked' => true,
'name' => 'enable_html_mode',
),
),
'route_path' => admin_url( 'admin.php' ),
'plugins_url' => admin_url( 'plugins.php' ),
'nav_item_param_key' => 'tab',
'nav_items' => array(
array(
'param' => 'settings',
'label' => esc_html__( 'Settings', 'gravitysmtp' ),
'icon' => 'settings',
),
array(
'param' => 'integrations',
'label' => esc_html__( 'Integrations', 'gravitysmtp' ),
'icon' => 'cloud1',
),
array(
'param' => 'alerts',
'label' => esc_html__( 'Alerts', 'gravitysmtp' ),
'icon' => 'exclamation-triangle',
),
array(
'param' => 'emails',
'label' => esc_html__( 'Emails', 'gravitysmtp' ),
'icon' => 'mail',
),
array(
'param' => 'logging',
'label' => esc_html__( 'Logging', 'gravitysmtp' ),
'icon' => 'circle-tool',
),
array(
'param' => 'routing',
'label' => esc_html__( 'Routing', 'gravitysmtp' ),
'icon' => 'routing',
),
),
'integrations_actions' => array(
0 =>
array(
'key' => 'edit',
'props' => array(
'element' => 'button',
'iconBefore' => 'api',
'iconPrefix' => 'gravity-admin-icon',
'label' => esc_html__( 'API Settings', 'gravitysmtp' ),
),
),
1 =>
array(
'key' => 'send-a-test',
'props' => array(
'customAttributes' => array(
'href' => admin_url( 'admin.php?page=gravitysmtp-tools&tab=send-a-test' ),
'data-test-id' => 'send-a-test-action'
),
'element' => 'link',
'iconBefore' => 'paper-plane',
'iconPrefix' => 'gravity-admin-icon',
'label' => esc_html__( 'Send A Test', 'gravitysmtp' ),
),
),
2 =>
array(
'key' => 'set-as-primary',
'props' => array(
'element' => 'button',
'iconBefore' => 'primary',
'iconPrefix' => 'gravity-admin-icon',
'label' => esc_html__( 'Set As Primary', 'gravitysmtp' ),
),
),
3 =>
array(
'key' => 'set-as-backup',
'props' => array(
'element' => 'button',
'iconBefore' => 'circle-lightning-bolt',
'iconPrefix' => 'gravity-admin-icon',
'label' => esc_html__( 'Set As Backup', 'gravitysmtp' ),
),
),
4 =>
array(
'key' => 'remove',
'props' => array(
'element' => 'button',
'iconBefore' => 'trash',
'iconPrefix' => 'gravity-admin-icon',
'label' => esc_html__( 'Remove Integration', 'gravitysmtp' ),
'style' => 'error',
),
),
),
'email_notifications' => array(
array(
'title' => esc_html__( 'Change of Admin Email', 'gravitysmtp' ),
'settings' => array(
array(
'label' => esc_html__( 'Site Admin Email Change Attempt', 'gravitysmtp' ),
'checked' => true,
'name' => 'site_admin_email_change_attempt',
),
array(
'label' => esc_html__( 'Site Admin Email Changed', 'gravitysmtp' ),
'checked' => false,
'name' => 'site_admin_email_changed',
),
),
),
array(
'title' => esc_html__( 'Change of User Email or Password', 'gravitysmtp' ),
'settings' => array(
array(
'label' => esc_html__( 'Reset Password Request', 'gravitysmtp' ),
'checked' => false,
'name' => 'reset_password_request',
),
array(
'label' => esc_html__( 'Password Reset Successfully', 'gravitysmtp' ),
'checked' => false,
'name' => 'password_reset_successfully',
),
array(
'label' => esc_html__( 'Password Changed', 'gravitysmtp' ),
'checked' => false,
'name' => 'password_changed',
),
array(
'label' => esc_html__( 'Email Change Attempt', 'gravitysmtp' ),
'checked' => false,
'name' => 'email_change_attempt',
),
array(
'label' => esc_html__( 'Email Changed', 'gravitysmtp' ),
'checked' => true,
'name' => 'email_changed',
),
),
),
array(
'title' => esc_html__( 'Personal Data Requests', 'gravitysmtp' ),
'settings' => array(
array(
'label' => esc_html__( 'User Confirmed Export / Erasure Request', 'gravitysmtp' ),
'checked' => true,
'name' => 'user_confirmed_export_erasure_request',
),
array(
'label' => esc_html__( 'Admin Erased Data', 'gravitysmtp' ),
'checked' => true,
'name' => 'admin_erased_data',
),
array(
'label' => esc_html__( 'Admin Sent Link to Export Data', 'gravitysmtp' ),
'checked' => false,
'name' => 'admin_sent_link_to_export_data',
),
),
),
array(
'title' => esc_html__( 'Automatic Updates', 'gravitysmtp' ),
'settings' => array(
array(
'label' => esc_html__( 'Plugin Status', 'gravitysmtp' ),
'checked' => true,
'name' => 'plugin_status',
),
array(
'label' => esc_html__( 'Theme Status', 'gravitysmtp' ),
'checked' => true,
'name' => 'theme_status',
),
array(
'label' => esc_html__( 'WP Core Status', 'gravitysmtp' ),
'checked' => true,
'name' => 'wp_core_status',
),
array(
'label' => esc_html__( 'Full Log', 'gravitysmtp' ),
'checked' => false,
'name' => 'full_log',
),
),
),
array(
'title' => esc_html__( 'New User', 'gravitysmtp' ),
'settings' => array(
array(
'label' => esc_html__( 'Created (Admin)', 'gravitysmtp' ),
'checked' => false,
'name' => 'created_admin',
),
array(
'label' => esc_html__( 'Created (User)', 'gravitysmtp' ),
'checked' => false,
'name' => 'created_user',
),
),
),
array(
'title' => esc_html__( 'Comments', 'gravitysmtp' ),
'settings' => array(
array(
'label' => esc_html__( 'Awaiting Moderation', 'gravitysmtp' ),
'checked' => false,
'name' => 'awaiting_moderation',
),
array(
'label' => esc_html__( 'Published', 'gravitysmtp' ),
'checked' => false,
'name' => 'published',
),
),
),
array(
'title' => esc_html__( 'WooCommerce', 'gravitysmtp' ),
'settings' => array(
array(
'label' => esc_html__( 'Purchase Receipt', 'gravitysmtp' ),
'checked' => true,
'name' => 'purchase_receipt',
),
array(
'label' => esc_html__( 'Password Change', 'gravitysmtp' ),
'checked' => true,
'name' => 'password_change',
),
),
),
),
'primary_locked' => $primary_locked,
'backup_locked' => $backup_locked,
),
'endpoints' => array(),
),
)
);
}
public function get_email_log_retention_options( $retention ) {
$options = array(
array(
'label' => esc_html__( '1 Day', 'gravitysmtp' ),
'value' => 1,
),
array(
'label' => esc_html__( '1 Week', 'gravitysmtp' ),
'value' => 7,
),
array(
'label' => esc_html__( '1 Month', 'gravitysmtp' ),
'value' => 30,
),
array(
'label' => esc_html__( '3 Months', 'gravitysmtp' ),
'value' => 90,
),
array(
'label' => esc_html__( '6 Months', 'gravitysmtp' ),
'value' => 180,
),
array(
'label' => esc_html__( '1 Year', 'gravitysmtp' ),
'value' => 365,
),
array(
'label' => esc_html__( 'Never Delete', 'gravitysmtp' ),
'value' => 0,
),
);
$values = array_column( $options, 'value' );
if ( in_array( $retention, $values ) ) {
return apply_filters( 'gravitysmtp_email_log_retention_options', $options );
}
return apply_filters(
'gravitysmtp_email_log_retention_options',
array(
array(
'label' => esc_html( sprintf( _n( '%s Day', '%s Days', $retention, 'gravitysmtp' ), $retention ) ),
'value' => $retention,
),
)
);
}
public function get_debug_log_retention_options( $retention ) {
$options = array(
array(
'label' => esc_html__( '1 Week', 'gravitysmtp' ),
'value' => 7,
),
array(
'label' => esc_html__( '1 Month', 'gravitysmtp' ),
'value' => 30,
),
);
$values = array_column( $options, 'value' );
if ( in_array( $retention, $values ) ) {
return apply_filters( 'gravitysmtp_debug_log_retention_options', $options );
}
return apply_filters(
'gravitysmtp_debug_log_retention_options',
array(
array(
'label' => esc_html( sprintf( _n( '%s Day', '%s Days', $retention, 'gravitysmtp' ), $retention ) ),
'value' => $retention,
),
)
);
}
public function get_notifications_email_digest_frequency_options() {
$options = array(
array(
'label' => esc_html__( 'Daily', 'gravitysmtp' ),
'value' => 1,
),
array(
'label' => esc_html__( 'Weekly (recommended)', 'gravitysmtp' ),
'value' => 7,
),
array(
'label' => esc_html__( 'Monthly', 'gravitysmtp' ),
'value' => 30,
),
);
return apply_filters( 'gravitysmtp_notifications_email_digest_frequency_options', $options );
}
}
File diff suppressed because it is too large Load Diff