/home/vianto5/hidalgoresidences.mx/wp-content/plugins/wp-mail-smtp/src/Admin
Edit: /home/vianto5/hidalgoresidences.mx/wp-content/plugins/wp-mail-smtp/src/Admin/DashboardWidget.php (22405B)
get( 'general', 'dashboard_widget_hidden' ) ) {
return;
}
add_action(
'admin_init',
function() {
// This widget should be displayed for certain high-level users only.
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
return;
}
/**
* Filters whether the initialization of the dashboard widget should be allowed.
*
* @since 2.9.0
*
* @param bool $var If the dashboard widget should be initialized.
*/
if ( ! apply_filters( 'wp_mail_smtp_admin_dashboard_widget', '__return_true' ) ) {
return;
}
$this->hooks();
}
);
}
/**
* Widget hooks.
*
* @since 2.9.0
*/
public function hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'widget_scripts' ] );
add_action( 'wp_dashboard_setup', [ $this, 'widget_register' ] );
add_action( 'wp_ajax_wp_mail_smtp_' . static::SLUG . '_save_widget_meta', [ $this, 'save_widget_meta_ajax' ] );
add_action(
'wp_ajax_wp_mail_smtp_' . static::SLUG . '_enable_summary_report_email',
[
$this,
'enable_summary_report_email_ajax',
]
);
}
/**
* Load widget-specific scripts.
* Load them only on the admin dashboard page.
*
* @since 2.9.0
*/
public function widget_scripts() {
$screen = get_current_screen();
if ( ! isset( $screen->id ) || 'dashboard' !== $screen->id ) {
return;
}
$min = WP::asset_min();
wp_enqueue_style(
'wp-mail-smtp-dashboard-widget',
wp_mail_smtp()->assets_url . '/css/dashboard-widget.min.css',
[],
WPMS_PLUGIN_VER
);
wp_enqueue_script(
'wp-mail-smtp-chart',
wp_mail_smtp()->assets_url . '/js/vendor/chart.min.js',
[ 'moment' ],
'4.4.9',
true
);
wp_enqueue_script(
'wp-mail-smtp-chart-adapter',
wp_mail_smtp()->assets_url . '/js/vendor/chartjs-adapter-moment.min.js',
[ 'moment', 'wp-mail-smtp-chart' ],
'1.0.1',
true
);
wp_enqueue_script(
'wp-mail-smtp-dashboard-widget',
wp_mail_smtp()->assets_url . "/js/smtp-dashboard-widget{$min}.js",
[ 'jquery', 'wp-mail-smtp-chart', 'wp-mail-smtp-chart-adapter' ],
WPMS_PLUGIN_VER,
true
);
wp_localize_script(
'wp-mail-smtp-dashboard-widget',
'wp_mail_smtp_dashboard_widget',
[
'slug' => static::SLUG,
'nonce' => wp_create_nonce( 'wp_mail_smtp_' . static::SLUG . '_nonce' ),
]
);
}
/**
* Register the widget.
*
* @since 2.9.0
*/
public function widget_register() {
global $wp_meta_boxes;
$widget_key = 'wp_mail_smtp_reports_widget_lite';
wp_add_dashboard_widget(
$widget_key,
esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ),
[ $this, 'widget_content' ]
);
// Attempt to place the widget at the top.
$normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
if ( isset( $normal_dashboard[ $widget_key ] ) ) {
$widget_instance = [ $widget_key => $normal_dashboard[ $widget_key ] ];
unset( $normal_dashboard[ $widget_key ] );
$sorted_dashboard = array_merge( $widget_instance, $normal_dashboard );
//phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
}
}
/**
* Save a widget meta for a current user using AJAX.
*
* @since 2.9.0
*/
public function save_widget_meta_ajax() {
check_admin_referer( 'wp_mail_smtp_' . static::SLUG . '_nonce' );
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
wp_send_json_error();
}
$meta = ! empty( $_POST['meta'] ) ? sanitize_key( $_POST['meta'] ) : '';
$value = ! empty( $_POST['value'] ) ? sanitize_key( $_POST['value'] ) : 0;
$this->widget_meta( 'set', $meta, $value );
wp_send_json_success();
}
/**
* Enable summary report email using AJAX.
*
* @since 3.0.0
*/
public function enable_summary_report_email_ajax() {
check_admin_referer( 'wp_mail_smtp_' . static::SLUG . '_nonce' );
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_global_options() ) ) {
wp_send_json_error();
}
$options = Options::init();
$data = [
'general' => [
SummaryReportEmail::SETTINGS_SLUG => false,
],
];
$options->set( $data, false, false );
wp_send_json_success();
}
/**
* Load widget content.
*
* @since 2.9.0
*/
public function widget_content() {
echo '
';
$this->widget_content_html();
echo '
';
}
/**
* Increment the number of total emails sent by 1.
*
* @deprecated 3.0.0
*
* @since 2.9.0
*/
public function increment_sent_email_counter() {
_deprecated_function( __METHOD__, '3.0.0' );
}
/**
* Widget content HTML.
*
* @since 2.9.0
*/
private function widget_content_html() {
$hide_graph = (bool) $this->widget_meta( 'get', 'hide_graph' );
?>
email_stats_block(); ?>
display_after_email_stats_block_content();
}
/**
* Display the content after the email stats block.
*
* @since 3.9.0
*
* @return void
*/
private function display_after_email_stats_block_content() {
if ( empty( $this->widget_meta( 'get', 'hide_email_alerts_banner' ) ) ) {
// Check if we have error debug events.
$error_debug_events_count = DebugEvents::get_error_debug_events_count();
if ( ! is_wp_error( $error_debug_events_count ) && ! empty( $error_debug_events_count ) ) {
$this->show_email_alerts_banner( $error_debug_events_count );
return;
}
}
$hide_summary_report_email_block = (bool) $this->widget_meta( 'get', 'hide_summary_report_email_block' );
if (
SummaryReportEmail::is_disabled() &&
! $hide_summary_report_email_block &&
current_user_can( wp_mail_smtp()->get_capability_manage_global_options() )
) {
$this->show_summary_report_email_block();
}
$this->show_upgrade_footer();
}
/**
* Display the email alerts banner.
*
* @since 3.9.0
*
* @param int $error_count The number of debug events error.
*
* @return void
*/
private function show_email_alerts_banner( $error_count ) {
?>
widget_meta( 'get', 'hide_graph' );
?>
esc_html__( 'Confirmed Emails', 'wp-mail-smtp' ),
'sent' => esc_html__( 'Unconfirmed Emails', 'wp-mail-smtp' ),
'unsent' => esc_html__( 'Failed Emails', 'wp-mail-smtp' ),
];
if ( Helpers::mailer_without_send_confirmation() ) {
unset( $options['sent'] );
$options['delivered'] = esc_html__( 'Sent Emails', 'wp-mail-smtp' );
}
?>
$title ) : ?>
get_email_stats_data();
?>
get_total_emails_sent();
$output_data = [
'all' => [
'type' => 'all',
'icon' => wp_mail_smtp()->assets_url . '/images/dash-widget/wp/total.svg',
/* translators: %d number of total emails sent. */
'title' => esc_html( sprintf( esc_html__( '%d total', 'wp-mail-smtp' ), $total_sent ) ),
],
'delivered' => [
'type' => 'delivered',
'icon' => wp_mail_smtp()->assets_url . '/images/dash-widget/wp/delivered.svg',
/* translators: %s fixed string of 'N/A'. */
'title' => esc_html( sprintf( esc_html__( 'Confirmed %s', 'wp-mail-smtp' ), 'N/A' ) ),
],
'sent' => [
'type' => 'sent',
'icon' => wp_mail_smtp()->assets_url . '/images/dash-widget/wp/sent.svg',
/* translators: %s fixed string of 'N/A'. */
'title' => esc_html( sprintf( esc_html__( 'Unconfirmed %s', 'wp-mail-smtp' ), 'N/A' ) ),
],
'unsent' => [
'type' => 'unsent',
'icon' => wp_mail_smtp()->assets_url . '/images/dash-widget/wp/unsent.svg',
/* translators: %s fixed string of 'N/A'. */
'title' => esc_html( sprintf( esc_html__( 'Failed %s', 'wp-mail-smtp' ), 'N/A' ) ),
],
];
if ( Helpers::mailer_without_send_confirmation() ) {
// Skip the 'unconfirmed sent' section.
unset( $output_data['sent'] );
// Change the 'confirmed sent' section into a general 'sent' section.
$output_data['delivered']['title'] = esc_html( /* translators: %s fixed string of 'N/A'. */
sprintf( esc_html__( 'Sent %s', 'wp-mail-smtp' ), 'N/A' )
);
}
return $output_data;
}
/**
* Get/set a widget meta.
*
* @since 2.9.0
*
* @param string $action Possible value: 'get' or 'set'.
* @param string $meta Meta name.
* @param int $value Value to set.
*
* @return mixed
*/
protected function widget_meta( $action, $meta, $value = 0 ) {
$allowed_actions = [ 'get', 'set' ];
if ( ! in_array( $action, $allowed_actions, true ) ) {
return false;
}
if ( $action === 'get' ) {
return $this->get_widget_meta( $meta );
}
$meta_key = $this->get_widget_meta_key( $meta );
$value = sanitize_key( $value );
if ( 'set' === $action && ! empty( $value ) ) {
return update_user_meta( get_current_user_id(), $meta_key, $value );
}
if ( 'set' === $action && empty( $value ) ) {
return delete_user_meta( get_current_user_id(), $meta_key );
}
return false;
}
/**
* Get the widget meta value.
*
* @since 3.9.0
*
* @param string $meta Meta name.
*
* @return mixed
*/
private function get_widget_meta( $meta ) {
$defaults = [
'hide_graph' => 0,
'hide_summary_report_email_block' => 0,
'hide_email_alerts_banner' => 0,
];
$meta_value = get_user_meta( get_current_user_id(), $this->get_widget_meta_key( $meta ), true );
if ( ! empty( $meta_value ) ) {
return $meta_value;
}
if ( isset( $defaults[ $meta ] ) ) {
return $defaults[ $meta ];
}
return null;
}
/**
* Retrieve the meta key.
*
* @since 3.9.0
*
* @param string $meta Meta name.
*
* @return string
*/
private function get_widget_meta_key( $meta ) {
return 'wp_mail_smtp_' . static::SLUG . '_' . $meta;
}
}