芝麻web文件管理V1.00
编辑当前文件:/var/www/cognitio.in/wp-content/plugins/wp-mail-smtp/src/Admin/DashboardWidget.php
get( 'general', 'dashboard_widget_hidden' ) ) { return; } add_action( 'admin_init', [ $this, 'init' ] ); } /** * Init class. * * @since 2.9.0 */ public function init() { // This widget should be displayed for certain high-level users only. if ( ! current_user_can( '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-moment', wp_mail_smtp()->assets_url . '/js/vendor/moment.min.js', [], '2.22.2', true ); wp_enqueue_script( 'wp-mail-smtp-chart', wp_mail_smtp()->assets_url . '/js/vendor/chart.min.js', [ 'wp-mail-smtp-moment' ], '2.9.4.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' ], 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']; $widget_instance = [ $widget_key => $normal_dashboard[ $widget_key ] ]; unset( $normal_dashboard[ $widget_key ] ); $sorted_dashboard = array_merge( $widget_instance, $normal_dashboard ); $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } /** * 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( '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( 'manage_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' ); $hide_summary_report_email_block = (bool) $this->widget_meta( 'get', 'hide_summary_report_email_block' ); ?>
email_types_select_html(); ?>
timespan_select_html(); $this->widget_settings_html(); ?>
email_stats_block(); ?>
NEW! Enable Weekly Email Summaries', 'wp-mail-smtp' ), [ 'b' => [], ] ); ?>
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(); ?>
'; } $count++; ?>
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; } $defaults = [ 'hide_graph' => 0, 'hide_summary_report_email_block' => 0, ]; if ( ! array_key_exists( $meta, $defaults ) ) { return false; } $meta_key = 'wp_mail_smtp_' . static::SLUG . '_' . $meta; if ( 'get' === $action ) { $meta_value = get_user_meta( get_current_user_id(), $meta_key, true ); return empty( $meta_value ) ? $defaults[ $meta ] : $meta_value; } $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; } }