rl-warmup-plugin/includes/rl-mailwarmer-functions.php

76 lines
2.4 KiB
PHP

<?php
/**
* Basic logging function for debugging. Allows passing of an object or array for the $data paramater
*
* Set the CUSTOM_DEBUG_LOG file in wp-config.php
*
*/
function log_to_file($message = false, $data = false){
if ($message) {
$log_File = CUSTOM_DEBUG_LOG;
$date = new DateTime();
$date = $date->format("Y/m/d h:i:s");
// Convert arrays and objects to JSON format
if (is_array($data) || is_object($data)) {
$data = json_encode($data);
$message = $message . " " . $data;
} else if ($data) {
$message = $message . " " . $data;
}
error_log("[$date] " . $message ."\r\n",3,$log_File);
}
}
/**
* Save a domain health report when a domain is first published.
*
* @param string $new_status The new post status.
* @param string $old_status The old post status.
* @param WP_Post $post The post object.
*/
// add_action('transition_post_status', function ($new_status, $old_status, $post) {
// // Ensure we're working with the 'domain' post type
// if ($post->post_type !== 'domain') {
// return;
// }
// // Only run when the status changes to 'publish' from a non-published status
// if ($new_status === 'publish' && $old_status !== 'publish') {
// try {
// RL_MailWarmer_Domain_Helper::saveDomainHealthReport($post->ID);
// } catch (Exception $e) {
// error_log('Failed to save domain health report: ' . $e->getMessage());
// }
// }
// }, 10, 3);
/**
* Save a domain health report when a new domain is created.
*
* @param int $post_id The ID of the post being saved.
* @param WP_Post $post The post object.
* @param bool $update Whether this is an update.
*/
// add_action('save_post_domain', function ($post_id, $post, $update) {
// // Exclude autosaves, revisions, drafts, and updates
// if (wp_is_post_autosave($post_id) || wp_is_post_revision($post_id) || $post->post_status === 'draft' || $update) {
// return;
// }
// // Call saveDomainHealthReport
// try {
// log_to_file("save_post_domain - Running health report for newly added domain: " . $post->post_title);
// RL_MailWarmer_Domain_Helper::saveDomainHealthReport($post_id);
// } catch (Exception $e) {
// error_log('Failed to save domain health report: ' . $e->getMessage());
// }
// log_to_file("save_post_domain - Finished! " . $post->post_title);
// }, 10, 3);