Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #5

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
=== WooCommerce Daily Error Log Emailer ===
=== Error Logs Emailer for WooCommerce ===
Contributors: mslepko
Tags: woocommerce, errors, error log, mailer
Tags: woocommerce, errors, error log, developers, debug
Requires at least: 6.0
Tested up to: 6.5
Requires PHP: 7.4
Stable tag: 1.2
Stable tag: 1.2.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Sends the previous day's WooCommerce fatal error log to specified email(s) using Action Scheduler.

== Description ==

[WooCommerce Daily Error Log Emailer](https://github.com/mslepko/wc-daily-logs-emailer) is a free plugin to send fatal error logged by WooCommerce
[Error Logs Emailer for WooCommerce](https://github.com/mslepko/wc-daily-logs-emailer) is a free plugin to send fatal error logged by WooCommerce

- Know what errors are happening on your site without constantly checking the logs
- Set the email where error logs should be sent
Expand All @@ -25,6 +25,11 @@ Sends the previous day's WooCommerce fatal error log to specified email(s) using

== Changelog ==

= 1.2.2 =
* Plugin Check fixes
* Updated date() to gmdate() to prevent runtime timezone changes
* Plugin name change to Error Logs Emailer for WooCommerce

= 1.2.1 =
* Making sure to register the action with Action Scheduler.
* Removed unnecessary file include
Expand Down
56 changes: 29 additions & 27 deletions wc-daily-logs-emailer.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
/**
* Woo Daily Error Log Emailer
* Error Logs Emailer for WooCommerce
*
* @package wc-daily-logs-emailer
* @link https://github.com/mslepko/wc-daily-logs-emailer
* @author WP Maintenance PRO <support@wp-maintenance.pro>
* @copyright Michal Slepko
* @license GPL v2 or later
*
* Plugin Name: WooCommerce Daily Error Log Emailer
* Plugin Name: Error Logs Emailer for WooCommerce
* Description: Sends the previous day's WooCommerce fatal error log to specified email(s) using Action Scheduler.
* Version: 1.2.0
* Version: 1.2.2
* Author: WP Maintenance PRO
* Plugin URI: https://github.com/mslepko/wc-daily-logs-emailer
* Author URI: https://wp-maintenance.pro
Expand All @@ -31,26 +31,33 @@
exit; // Exit if accessed directly.
}

// Activation hook.
register_activation_hook( __FILE__, 'wc_schedule_daily_error_log_email' );

// Deactivation hook.
register_deactivation_hook( __FILE__, 'wc_daily_error_log_emailer_deactivate_action' );


// Register admin menu and settings.
add_action( 'admin_menu', 'wc_daily_logs_emailer_add_admin_menu' );
add_action( 'admin_init', 'wc_daily_logs_emailer_settings_init' );

/**
* Add admin menu for WooCommerce Daily Logs Emailer.
* Add admin menu for Error Logs Emailer for WooCommerce.
*/
function wc_daily_logs_emailer_add_admin_menu() {
add_options_page(
'WooCommerce Daily Logs Emailer Settings',
'WooCommerce Logs Emailer',
'Error Logs Emailer for WooCommerce',
'Error Logs Emailer',
'manage_options',
'wc-daily-logs-emailer',
'wc_daily_logs_emailer_settings_page'
);
}

/**
* Initialize the settings for WooCommerce Daily Logs Emailer.
* */
* Initialize the settings for Error Logs Emailer for WooCommerce.
*/
function wc_daily_logs_emailer_settings_init() {
register_setting( 'wcDailyLogsEmailer', 'wc_log_email_settings' );

Expand Down Expand Up @@ -90,15 +97,15 @@ function wc_log_email_render() {
}

/**
* Callback function for the settings section in WooCommerce Daily Logs Emailer.
* Callback function for the settings section in Error Logs Emailer for WooCommerce.
*/
function wc_daily_logs_emailer_settings_section_callback() {
echo '<p>Adjust the settings for how and where you receive WooCommerce error logs.</p>';
}

/**
* Displays additional information about the email recipient settings.
*/
/**
* Displays additional information about the email recipient settings.
*/
function wc_daily_logs_emailer_settings_description() {
$admin_email = get_option( 'admin_email' );
// Check for RECOVERY_MODE_EMAIL.
Expand All @@ -114,14 +121,14 @@ function wc_daily_logs_emailer_settings_description() {
}

/**
* Function to display the settings page for WooCommerce Daily Logs Emailer.
* Displays the settings page for Error Logs Emailer for WooCommerce.
*
* This function displays the settings page for WooCommerce Daily Logs Emailer.
* This function displays the settings page for Error Logs Emailer for WooCommerce.
*/
function wc_daily_logs_emailer_settings_page() {
?>
<div class="wrap">
<h1>WooCommerce Daily Logs Emailer Settings</h1>
<h1>Error Logs Emailer for WooCommerce Settings</h1>
<form action='options.php' method='post'>
<?php
settings_fields( 'wcDailyLogsEmailer' );
Expand All @@ -133,10 +140,7 @@ function wc_daily_logs_emailer_settings_page() {
<?php
}

// }

// Schedule the action with either Action Scheduler.
register_activation_hook( __FILE__, 'wc_schedule_daily_error_log_email' );

/**
* Schedule the daily error log email.
Expand Down Expand Up @@ -169,7 +173,11 @@ function wc_schedule_daily_error_log_email() {
* @see wp_mail() For sending the email with the log content.
*/
function wc_daily_error_log_emailer_send_log() {
$yesterday = date( 'Y-m-d', strtotime( '-1 day' ) );
// Required files for WP_Filesystem_Direct.
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';

$yesterday = gmdate( 'Y-m-d', strtotime( '-1 day' ) );
$log_filename = 'fatal-errors-' . $yesterday . '*.log';
$log_files = glob( WC_LOG_DIR . '/' . $log_filename );
$options = get_option( 'wc_log_email_settings' );
Expand All @@ -185,22 +193,16 @@ function wc_daily_error_log_emailer_send_log() {
if ( is_email( $email ) && ! empty( $log_files ) ) {
foreach ( $log_files as $log_file ) {
if ( file_exists( $log_file ) ) {
$log_content = file_get_contents( $log_file );
$wp_filesystem = new WP_Filesystem_Direct( null );
$log_content = $wp_filesystem->get_contents( $log_file );
wp_mail( $email, "[$site_name] WooCommerce Fatal Errors Log for $yesterday", $log_content );
}
}
}
}
}

/**
* Deactivation hook to clear the scheduled action.
*
* @see as_unschedule_all_actions() For clearing all scheduled actions.
* @see delete_option() For deleting the 'wc_log_email' option.
*/

register_deactivation_hook( __FILE__, 'wc_daily_error_log_emailer_deactivate_action' );

/**
* Deactivate the plugin and clear the scheduled action.
Expand Down