rootPluginFilenameAndPath = $rootPluginFilenameAndPath; $this->options = $options; $this->authorizationToken = $authorizationToken; $this->wpMailBinder = $binder; add_action( 'wp_ajax_post_smtp_dash_widget_lite_save_widget_meta', array( $this, 'post_smtp_save_widget_meta_ajax' ) ); add_action ( 'admin_enqueue_scripts', array ( $this, 'dasboardWidgetsScripts' ) ); add_action ( 'wp_dashboard_setup', array ( $this, 'addDashboardWidget' ) ); add_action ( 'wp_network_dashboard_setup', array ( $this, 'addNetworkDashboardWidget' ) ); // dashboard glance mod if ($this->options->isMailLoggingEnabled ()) { add_filter ( 'dashboard_glance_items', array ( $this, 'customizeAtAGlanceDashboardWidget' ), 10, 1 ); } // Postman API: register the human-readable plugin state add_filter ( 'print_postman_status', array ( $this, 'print_postman_status' ) ); } /** * Save a widget meta for a current user using AJAX. * * @since 1.4.0 */ public function post_smtp_save_widget_meta_ajax() { check_admin_referer( 'post_smtp_dash_widget_lite_nonce' ); // if ( ! current_user_can( post_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->post_smtp_widget_meta( 'set', $meta, $value ); wp_send_json_success(); } /** * Get/set a widget meta. * * @since 1.4.0 * * @param string $action Possible value: 'get' or 'set'. * @param string $meta Meta name. * @param int $value Value to set. * * @return mixed */ protected function post_smtp_widget_meta( $action, $meta, $value = 0 ) { $allowed_actions = [ 'get', 'set' ]; if ( ! in_array( $action, $allowed_actions, true ) ) { return false; } if ( $action === 'get' ) { return $this->post_smtp_get_widget_meta( $meta ); } $meta_key = $this->post_smtp_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 1.4.0 * * @param string $meta Meta name. * * @return mixed */ private function post_smtp_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->post_smtp_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 1.4.0 * * @param string $meta Meta name. * * @return string */ private function post_smtp_get_widget_meta_key( $meta ) { return 'post_smtp_dash_widget_' . $meta; } /** * Add a widget to the dashboard. * * This function is hooked into the 'wp_dashboard_setup' action below. * * @since 1.4.0 */ public function dasboardWidgetsScripts( $hook ) { if ( 'index.php' === $hook ) { // Enqueue Chart.js (with the built-in Luxon adapter). wp_enqueue_script( 'chart-js', POST_SMTP_URL . '/Postman/Postman-Controller/assets/js/chart.min.js', array(), '', true ); // Enqueue Moment.js Adapter (chartjs-adapter-moment). wp_enqueue_script( 'moment-js', POST_SMTP_URL . '/Postman/Postman-Controller/assets/js/moment.min.js', array( 'chart-js' ), '1.0.0', true ); // Enqueue your custom script that depends on both Chart.js and Luxon. wp_enqueue_script( 'post-smtp-wp-dashboard-widget', POST_SMTP_URL . '/Postman/Postman-Controller/assets/js/post-smtp-wp-dashboard.js', array( 'jquery', 'chart-js', 'moment-js' ), POST_SMTP_VER, true ); wp_localize_script( 'post-smtp-wp-dashboard-widget', 'post_smtp_dashboard_widget', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'slug' => 'dash_widget_lite', 'nonce' => wp_create_nonce( 'post_smtp_dash_widget_lite_nonce' ), ) ); wp_enqueue_script( 'post-smtp-wp-dashboard-widget' ); wp_enqueue_style( 'post-smtp-wp-dashboard-widget-style', POST_SMTP_URL . '/Postman/Postman-Controller/assets/css/post-smtp-wp-dashboard-style.css', array(), POST_SMTP_VER, 'all' ); } } /** * Add a widget to the dashboard. * * This function is hooked into the 'wp_dashboard_setup' action below. */ public function addDashboardWidget() { // only display to the widget to administrator if (PostmanUtils::isAdmin ()) { wp_add_dashboard_widget ( 'example_dashboard_widget', __ ( 'Postman SMTP', 'post-smtp' ), array ( $this, 'printDashboardWidget' ) ); // Display function. if ( ! post_smtp_has_pro() ) { $widget_key = 'post_smtp_reports_widget_lite'; } else { $widget_key = 'post_smtp_reports_widget'; } wp_add_dashboard_widget ( $widget_key, __ ( 'Postman SMTP Stats', 'post-smtp' ), array ( $this, 'printStatsDashboardWidget' ), 'high' ); // Display function. } } /** * Add a widget to the network dashboard */ public function addNetworkDashboardWidget() { // only display to the widget to administrator if (PostmanUtils::isAdmin ()) { wp_add_dashboard_widget ( 'example_dashboard_widget', __ ( 'Postman SMTP', 'post-smtp' ), array ( $this, 'printNetworkDashboardWidget' ) ); // Display function. } } /** * Create the function to output the contents of our Dashboard Widget. */ public function printDashboardWidget() { $goToSettings = sprintf ( '%s', PostmanUtils::getSettingsPageUrl (), __ ( 'Settings', 'post-smtp' ) ); $goToEmailLog = sprintf ( '%s', _x ( 'Email Log', 'The log of Emails that have been delivered', 'post-smtp' ) ); if ($this->options->isMailLoggingEnabled ()) { $goToEmailLog = sprintf ( '%s', PostmanUtils::getEmailLogPageUrl (), $goToEmailLog ); } apply_filters ( 'print_postman_status', null ); printf ( '

%s | %s

', $goToEmailLog, $goToSettings ); } /** * Create the function to output the contents of our Dashboard Widget. * * @since 1.4.0 */ public function printStatsDashboardWidget() { ?>

Reporting and Tracking' ?>

emailTypesSelectHtml(); ?> viewFullEmailLogs(); ?>
TimespanSelectHtml(); $this->widgetSettingsHtml(); ?>
emailStatsBlock(); ?>

Download now', 'post-smtp' ), [ 'a' => [ 'href' => [], 'rel' => [], 'target' => [], ], ] ), // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound esc_url( "https://postmansmtp.com/post-smtp-mobile-app/" ) ); ?>

esc_html__( 'Sent Emails', 'post-smtp' ), 'failed_emails' => esc_html__( 'Failed Emails', 'post-smtp' ), ); if ( ! post_smtp_has_pro() ) { $disabled = 'disabled'; } else { $disabled = ''; } ?> options->isMailLoggingEnabled ()) { $goToEmailLog = sprintf ( '%s', PostmanUtils::getEmailLogPageUrl (), $goToEmailLog ); } printf ( '

%s

', $goToEmailLog ); } /** * Timespan select HTML. * * @since 1.4.0 */ private function TimespanSelectHtml() { // Check if Post SMTP Pro is available, disable options if not $disabled = post_smtp_has_pro() ? '' : 'disabled'; ?> post_smtp_get_widget_meta( 'chart_style' ); if ( ! post_smtp_has_pro() ) { $disabled = 'disabled'; } else { $disabled = ''; } ?>

>
>
get_logs(); $total = count( $logs ); $output_data = array(); // Initialize the categories $output_data['all_emails'] = array( 'type' => 'all', 'icon' => esc_url( POST_SMTP_URL . "/Postman/Postman-Controller/assets/images/email.svg" ), 'title' => $total . ' total', // Set the actual total count ); // Initialize counters for sent and failed emails $sent_count = 0; $failed_count = 0; if ( post_smtp_has_pro() ){ $opened_count = 0; // $opened_email = new Post_SMTP_New_Dashboard; $current_time = current_time( 'timestamp' ); $period = 'day'; $filter = strtotime( 'today', $current_time ); $opened_count = apply_filters( 'post_smtp_dashboard_opened_emails_count', 0, array( 'period' => $period, 'current_time' => $current_time, 'filter' => $filter, ) ); } // Loop through logs to count sent and failed emails, including fallback sent. foreach ( $logs as $log ) { if ( isset( $log->success ) ) { // Treat normal success and successful fallback ("Sent ( ** Fallback ** )") as sent. $success_value = $log->success; $is_normal_success = ( 1 === $success_value || '1' === $success_value ); $is_fallback_sent = is_string( $success_value ) && 0 === strpos( $success_value, 'Sent ( ** Fallback ** )' ); if ( $is_normal_success || $is_fallback_sent ) { $sent_count++; } else { // Any other value (including fallback failures) is considered failed. $failed_count++; } } } // Set sent and failed emails data $output_data['sent_emails'] = array( 'type' => 'sent', 'icon' => esc_url( POST_SMTP_URL . "/Postman/Postman-Controller/assets/images/sent.svg" ), 'title' => 'Sent '. $sent_count, // Show the actual count of sent emails. ); $output_data['failed_emails'] = array( 'type' => 'failed', 'icon' => esc_url( POST_SMTP_URL . "/Postman/Postman-Controller/assets/images/failed.svg" ), 'title' => 'Failed '. $failed_count, // Show the actual count of failed emails. ); if ( post_smtp_has_pro() ){ $output_data['opened_emails'] = array( 'type' => 'opened', 'icon' => esc_url( POST_SMTP_URL . "/Postman/Postman-Controller/assets/images/opend.svg" ), 'title' => 'Opened '. $opened_count, // Show the actual count of failed emails. ); } ?> '; } $count++; ?>
<?php esc_attr_e( 'Table cell icon', 'post-smtp' ); ?>
%s

', __ ( 'Error: Postman is missing a required PHP library.', 'post-smtp' ) ); } else if ($this->wpMailBinder->isUnboundDueToException ()) { printf ( '

%s

', __ ( 'Postman: wp_mail has been declared by another plugin or theme, so you won\'t be able to use Postman until the conflict is resolved.', 'post-smtp' ) ); } else { if ($this->options->getRunMode () != PostmanOptions::RUN_MODE_PRODUCTION) { printf ( '

%s

', __ ( 'Postman is in non-Production mode and is dumping all emails.', 'post-smtp' ) ); } else if (PostmanTransportRegistry::getInstance ()->getSelectedTransport ()->isConfiguredAndReady ()) { printf ( '', sprintf ( _n ( 'Postman is configured and has delivered %d email.', 'Postman is configured and has delivered %d emails.', PostmanState::getInstance ()->getSuccessfulDeliveries (), 'post-smtp' ), PostmanState::getInstance ()->getSuccessfulDeliveries () ) ); } else { printf ( '

%s

', __ ( 'Postman is not configured and is mimicking out-of-the-box WordPress email delivery.', 'post-smtp' ) ); } $currentTransport = PostmanTransportRegistry::getInstance ()->getActiveTransport (); $deliveryDetails = $currentTransport->getDeliveryDetails ( $this->options ); printf ( '

%s

', $deliveryDetails ); } } /** * Create the function to output the contents of our Dashboard Widget. */ public function printNetworkDashboardWidget() { printf ( '', __ ( 'Postman is operating in per-site mode.', 'post-smtp' ) ); } /** * From http://www.hughlashbrooke.com/2014/02/wordpress-add-items-glance-widget/ * http://coffeecupweb.com/how-to-add-custom-post-types-to-at-a-glance-dashboard-widget-in-wordpress/ * * @param mixed $items * @return string */ function customizeAtAGlanceDashboardWidget($items = array()) { // only modify the At-a-Glance for administrators if (PostmanUtils::isAdmin ()) { $post_types = array ( PostmanEmailLogPostType::POSTMAN_CUSTOM_POST_TYPE_SLUG ); foreach ( $post_types as $type ) { if (! post_type_exists ( $type )) continue; $num_posts = wp_count_posts ( $type ); if ($num_posts) { $published = intval ( $num_posts->publish ); $privated = intval ( $num_posts->private ); $post_type = get_post_type_object ( $type ); $text = _n ( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $privated, 'post-smtp' ); $text = sprintf ( $text, number_format_i18n ( $privated ) ); $items [] = sprintf ( '%2$s', $type, $text, PostmanUtils::getEmailLogPageUrl () ) . "\n"; } } return $items; } } } }