'POST', 'callback' => [ $this, 'send_test_email' ], 'permission_callback' => [ $sureforms_helper, 'get_items_permissions_check' ], ] ); } /** * Send test email. * * @param WP_REST_Request $request Request object. * @return WP_REST_Response * @since 0.0.2 */ public function send_test_email( $request ) { $data = $request->get_body(); $data = json_decode( $data, true ); $email_send_to = ''; if ( is_array( $data ) && isset( $data['srfm_email_sent_to'] ) && is_string( $data['srfm_email_sent_to'] ) ) { $email_send_to = sanitize_email( $data['srfm_email_sent_to'] ); if ( ! is_email( $email_send_to ) ) { return new \WP_REST_Response( [ 'data' => __( 'Invalid email address.', 'sureforms' ) ], 400 ); } } $get_email_summary_options = [ 'srfm_email_sent_to' => $email_send_to, ]; self::send_entries_to_admin( $get_email_summary_options ); return new WP_REST_Response( [ 'data' => __( 'Test Email Sent Successfully.', 'sureforms' ), ] ); } /** * Get or copy image to uploads folder. * * @param string $filename The image filename. * @param string $source_path The source path relative to plugin directory. * @return string The public URL of the image. * * @since 1.10.1 */ public static function get_public_image_url( $filename, $source_path ) { // Sanitize filename. $filename = basename( $filename ); // Validate allowed extensions. $allowed_ext = [ 'png', 'jpg', 'jpeg', 'gif', 'svg' ]; $ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ); if ( ! in_array( $ext, $allowed_ext, true ) ) { return ''; } // Whitelist or sanitize source_path if possible. $source_path = trailingslashit( ltrim( $source_path, '/' ) ); // Upload directory info. $upload_dir = wp_upload_dir(); $sureforms_upload_dir = trailingslashit( $upload_dir['basedir'] ) . 'sureforms/images/'; $sureforms_upload_url = trailingslashit( $upload_dir['baseurl'] ) . 'sureforms/images/'; // Create directory if it doesn't exist. if ( ! file_exists( $sureforms_upload_dir ) && ! wp_mkdir_p( $sureforms_upload_dir ) ) { // Fallback URL. return esc_url( SRFM_URL . $source_path . $filename ); } $target_file = $sureforms_upload_dir . $filename; $target_url = $sureforms_upload_url . $filename; // Copy if doesn't exist. if ( ! file_exists( $target_file ) ) { $source_file = SRFM_DIR . $source_path . $filename; if ( ! file_exists( $source_file ) || ! copy( $source_file, $target_file ) ) { // Fallback URL. return esc_url( SRFM_URL . $source_path . $filename ); } } return esc_url( $target_url ); } /** * Function to get the total number of entries for the last week. * * @param array|null $forms_data Optional. Forms data with entry counts. If null, fetches from database. * * @since 0.0.2 * @return string HTML table with entries count. */ public static function get_total_entries_for_week( $forms_data = null ) { // Calculate timestamp for 7 days ago (last week). $week_ago_timestamp = strtotime( '-7 days' ); if ( null === $forms_data ) { // Use the helper function to get forms with entry counts. $forms_data = Helper::get_forms_with_entry_counts( $week_ago_timestamp ); } $logs_url = admin_url( 'admin.php?page=sureforms_entries' ); ob_start(); ?> <?php esc_html_e( 'Weekly Summary', 'sureforms' ); ?> '; ?>
<?php esc_attr_e( 'SureForms Logo', 'sureforms' ); ?>

%2$s', esc_url( $site_url ), esc_html( $site_name ) ) ); ?>


', '' ); ?>


<?php esc_attr_e( 'SureForms Logo', 'sureforms' ); ?>
[ 'logo' => 'ottokit.png', 'title' => __( 'Automate Workflows with OttoKit', 'sureforms' ), 'description' => __( 'Connect your apps and automate repetitive tasks with ease. Build workflows that save time, reduce errors, and keep your business running smoothly around the clock.', 'sureforms' ), 'link' => 'https://ottokit.com?utm_medium=sureforms-email-summary', 'link_text' => __( 'Explore OttoKit', 'sureforms' ), 'plugin_path' => 'suretriggers/suretriggers.php', ], 'surerank' => [ 'logo' => 'surerank.png', 'title' => __( 'Optimize Your Site with SureRank', 'sureforms' ), 'description' => __( 'Fix common SEO issues and make your site search-friendly without the clutter. Check pages, add titles, meta, and schema — all in one simple plugin.', 'sureforms' ), 'link' => 'https://surerank.com?utm_medium=sureforms-email-summary', 'link_text' => __( 'Explore SureRank', 'sureforms' ), 'plugin_path' => 'surerank/surerank.php', ], 'suremail' => [ 'logo' => 'suremail.png', 'title' => __( 'Send Emails Reliably with SureMail', 'sureforms' ), 'description' => __( 'Make sure every WordPress email gets delivered. View logs, debug errors, and send with confidence using a lightweight SMTP solution.', 'sureforms' ), 'link' => 'https://suremails.com?utm_medium=sureforms-email-summary', 'link_text' => __( 'Explore SureMail', 'sureforms' ), 'plugin_path' => 'suremails/suremails.php', ], 'surecart' => [ 'logo' => 'surecart.png', 'title' => __( 'Sell with Ease using SureCart', 'sureforms' ), 'description' => __( 'Run your online store on WordPress with a modern checkout, subscriptions, and payments. Fast, flexible, and built for growth.', 'sureforms' ), 'link' => 'https://surecart.com?utm_medium=sureforms-email-summary', 'link_text' => __( 'Explore SureCart', 'sureforms' ), 'plugin_path' => 'surecart/surecart.php', ], 'suredash' => [ 'logo' => 'suredash.png', 'title' => __( 'Build Your Community with SureDash', 'sureforms' ), 'description' => __( 'Create a central hub where members can connect, share, and grow together. Manage discussions, courses, and events — all from your own WordPress site.', 'sureforms' ), 'link' => 'https://suredash.com?utm_medium=sureforms-email-summary', 'link_text' => __( 'Explore SureDash', 'sureforms' ), 'plugin_path' => 'suredash/suredash.php', ], ]; } /** * Check if a plugin is installed. * * @param string $plugin_path The plugin path (e.g., 'plugin-folder/plugin-file.php'). * @return bool True if plugin is installed, false otherwise. * @since 2.3.0 */ public static function is_plugin_installed( $plugin_path ) { return '' !== Helper::get_plugin_if_installed( [ $plugin_path ] ); } /** * Render a promo banner for a given plugin. * * Outputs the banner HTML for the specified plugin key. * If the key is invalid, nothing is rendered. * * @since 1.12.1 * * @param string $plugin_key The key of the promo plugin to render. * * @return void */ public static function render_promo_banner( $plugin_key ) { $banners = self::get_promo_banners(); if ( ! isset( $banners[ $plugin_key ] ) ) { return; } $args = $banners[ $plugin_key ]; if ( isset( $args['plugin_path'] ) && self::is_plugin_installed( $args['plugin_path'] ) ) { return; } ?>
<?php echo esc_attr( $args['title'] ); ?> Logo

→
|bool $email_summary_options Email Summary Options. * @since 0.0.2 * @return void */ public static function send_entries_to_admin( $email_summary_options ) { // Calculate timestamp for 7 days ago (last week). $week_ago_timestamp = strtotime( '-7 days' ); $forms_data = Helper::get_forms_with_entry_counts( $week_ago_timestamp ); // Calculate total entries. $total_entries = array_sum( wp_list_pluck( $forms_data, 'count' ) ); // If no entries at all, don't send the email. if ( $total_entries <= 0 ) { return; } $entries_count_table = self::get_total_entries_for_week( $forms_data ); $recipients_string = ''; if ( is_array( $email_summary_options ) && isset( $email_summary_options['srfm_email_sent_to'] ) && is_string( $email_summary_options['srfm_email_sent_to'] ) ) { $recipients_string = $email_summary_options['srfm_email_sent_to']; } $recipients = $recipients_string ? explode( ',', $recipients_string ) : []; $from_date = date_i18n( 'F j, Y', $week_ago_timestamp ); $to_date = date_i18n( 'F j, Y' ); // Translators: %1$s: From Date, %2$s: To Date. $subject = sprintf( __( 'Email Summary of your last week - %1$s to %2$s', 'sureforms' ), $from_date, $to_date ); $message = $entries_count_table; $headers = [ 'Content-Type: text/html; charset=UTF-8', 'From: ' . get_option( 'admin_email' ), ]; wp_mail( $recipients, $subject, $message, $headers ); } /** * Schedule the event action to run weekly. * * @return void * @since 0.0.2 */ public static function schedule_weekly_entries_email() { $email_summary_options = get_option( 'srfm_email_summary_settings_options' ); $time = apply_filters( 'srfm_weekly_email_summary_time', '09:00:00' ); if ( wp_next_scheduled( 'srfm_weekly_scheduled_events' ) ) { wp_clear_scheduled_hook( 'srfm_weekly_scheduled_events' ); } $day = __( 'Monday', 'sureforms' ); if ( is_array( $email_summary_options ) && isset( $email_summary_options['srfm_schedule_report'] ) && is_string( $email_summary_options['srfm_schedule_report'] ) ) { $day = Helper::get_string_value( $email_summary_options['srfm_schedule_report'] ); } $current_time = time(); $current_time_user_timezone = Helper::get_integer_value( strtotime( gmdate( 'Y-m-d H:i:s', $current_time ) ) ); if ( ! preg_match( '/^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/', $time ) ) { $time = '09:00:00'; } $next_day_user_timezone = Helper::get_integer_value( strtotime( "next {$day} {$time}", $current_time_user_timezone ) ); $scheduled_time = Helper::get_integer_value( strtotime( gmdate( 'Y-m-d H:i:s', $next_day_user_timezone ) ) ); if ( false === as_has_scheduled_action( 'srfm_weekly_scheduled_events' ) ) { as_schedule_recurring_action( $scheduled_time, WEEK_IN_SECONDS, 'srfm_weekly_scheduled_events', [ 'email_summary_options' => $email_summary_options, ], 'sureforms', true ); } } }