rl-warmup-plugin/includes/rl-mailwarmer-domain-admin.php

925 lines
38 KiB
PHP

<?php
add_action('admin_enqueue_scripts', function ($hook) {
if ($hook === 'post.php' || $hook === 'post-new.php') {
global $post;
wp_enqueue_style(
'rl-mailwarmer-admin-css',
RL_MAILWARMER_URL . '/css/admin-style.css', // Path to your CSS file
[],
'1.0.3' // Version number
);
if ($post->post_type === 'domain') {
wp_enqueue_script('rl-mailwarmer-admin-script', RL_MAILWARMER_URL . '/js/admin-check-domain-health.js', ['jquery'], null, true);
wp_localize_script('rl-mailwarmer-admin-script', 'rlMailWarmer', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('check_domain_health_nonce'),
'post_id' => $post->ID
]);
wp_enqueue_script('rl-mailwarmer-spf-script', RL_MAILWARMER_URL . '/js/admin-update-spf.js', ['jquery'], null, true);
wp_localize_script('rl-mailwarmer-spf-script', 'rlMailWarmerSpf', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('update_spf_record_nonce'),
'post_id' => $post->ID
]);
wp_enqueue_script('rl-mailwarmer-mx-script', RL_MAILWARMER_URL . '/js/admin-update-mx.js', ['jquery'], null, true);
wp_localize_script('rl-mailwarmer-mx-script', 'rlMailWarmerMx', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('update_mx_record_nonce'),
'post_id' => $post->ID
]);
wp_enqueue_script('rl-mailwarmer-dmarc-script', RL_MAILWARMER_URL . '/js/admin-update-dmarc.js', ['jquery'], null, true);
wp_localize_script('rl-mailwarmer-dmarc-script', 'rlMailWarmerDmarc', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('update_dmarc_record_nonce'),
'post_id' => $post->ID
]);
wp_enqueue_script('rl-mailwarmer-dkim-script', RL_MAILWARMER_URL . '/js/admin-update-dkim.js', ['jquery'], null, true);
wp_localize_script('rl-mailwarmer-dkim-script', 'rlMailWarmerDkim', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('update_dkim_record_nonce'),
'post_id' => $post->ID
]);
wp_enqueue_script('rl-mailwarmer-dns-fix-script', RL_MAILWARMER_URL . '/js/admin-fix-dns.js', ['jquery'], null, true);
wp_localize_script('rl-mailwarmer-dns-fix-script', 'rlMailWarmerDnsFix', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('fix_deliverability_dns_issues_nonce'),
'post_id' => $post->ID
]);
wp_enqueue_script('rl-mailwarmer-dns-backup', RL_MAILWARMER_URL . '/js/admin-dns-backup.js' , ['jquery'], null, true);
wp_localize_script('rl-mailwarmer-dns-backup', 'rlMailWarmerDnsBackup', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('create_dns_backup_nonce'),
]);
} else if ($post->post_type === 'email-account') {
wp_enqueue_script(
'rl-mailwarmer-check-login-js',
RL_MAILWARMER_URL . 'js/check-mail-login.js', // Adjust path as needed
['jquery'],
null,
true
);
wp_localize_script('rl-mailwarmer-check-login-js', 'rlMailWarmerCheckMailLogin', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('check_mail_login_nonce'),
'post_id' => $post->ID
]);
} else if ($post->post_type === 'campaign') {
// log_to_file("On a campaign page. Enqueing admin scripts");
// // Enqueue D3.js
// wp_enqueue_script(
// 'd3-js',
// 'https://d3js.org/d3.v7.min.js',
// [],
// '7.0.0',
// true
// );
// // Enqueue Cal-Heatmap script and style
// wp_enqueue_script(
// 'cal-heatmap',
// 'https://unpkg.com/cal-heatmap/dist/cal-heatmap.min.js',
// [],
// '4.2.4',
// true
// );
// wp_enqueue_style(
// 'cal-heatmap',
// 'https://unpkg.com/cal-heatmap/dist/cal-heatmap.css',
// [],
// '4.2.4'
// );
// // Enqueue custom script for rendering the heatmap
// wp_enqueue_script(
// 'rl-mailwarmer-campaign-heatmap',
// RL_MAILWARMER_URL . 'js/campaign-timeline-heatmap.js', // Adjust the path as needed
// ['cal-heatmap', 'jquery'],
// null,
// true
// );
// // Pass data to the custom script
// wp_localize_script('rl-mailwarmer-campaign-heatmap', 'rlMailWarmerHeatmap', [
// 'ajax_url' => admin_url('admin-ajax.php'),
// 'nonce' => wp_create_nonce('campaign_timeline_nonce'),
// 'post_id' => $post->ID,
// ]);
}
}
});
/**
* Add "Check Domain Health" button to the sidebar of the domain edit screen.
*/
add_action('add_meta_boxes', function () {
add_meta_box(
'check_domain_health_box',
__('Check Domain Health', 'rl-mailwarmer'),
'rl_mailwarmer_check_domain_health_box_callback',
'domain',
'side',
'default'
);
add_meta_box(
'create_dns_backup_box',
__('Create DNS Backup', 'rl-mailwarmer'),
'rl_mailwarmer_render_create_dns_backup_box',
'domain',
'side',
'default'
);
add_meta_box(
'fix_deliverability_dns_issues_box', // Meta box ID
__('Fix Deliverability DNS Issues', 'rl-mailwarmer'), // Title
'rl_mailwarmer_render_fix_deliverability_dns_issues_box', // Callback function
'domain', // Post type
'side', // Context
'default' // Priority
);
add_meta_box(
'update_mx_record_box', // Meta box ID
__('Update MX Record', 'rl-mailwarmer'), // Title
'rl_mailwarmer_render_update_mx_record_box', // Callback function
'domain', // Post type
'side', // Context
'default' // Priority
);
add_meta_box(
'update_spf_record_box', // Meta box ID
__('Update SPF Record', 'rl-mailwarmer'), // Title
'rl_mailwarmer_render_update_spf_record_box', // Callback function
'domain', // Post type
'side', // Context
'default' // Priority
);
add_meta_box(
'update_dmarc_record_box', // Meta box ID
__('Update DMARC Record', 'rl-mailwarmer'), // Title
'rl_mailwarmer_render_update_dmarc_record_box', // Callback function
'domain', // Post type
'side', // Context
'default' // Priority
);
add_meta_box(
'update_dkim_record_box', // Meta box ID
__('Update DKIM Record', 'rl-mailwarmer'), // Title
'rl_mailwarmer_render_update_dkim_record_box', // Callback function
'domain', // Post type
'side', // Context
'default' // Priority
);
});
/**
* Callback for the "Check Domain Health" meta box.
*/
function rl_mailwarmer_check_domain_health_box_callback($post)
{
// Add nonce for security
wp_nonce_field('check_domain_health_nonce', 'check_domain_health_nonce_field');
// Render the button
echo '<p>';
echo '<button id="check-domain-health-button" class="button button-primary">';
echo __('Check Domain Health', 'rl-mailwarmer');
echo '</button>';
echo '</p>';
// Output a placeholder for results
echo '<div id="domain-health-result"></div>';
}
/**
* Render the meta box for DNS backup.
*
* @param WP_Post $post The current post object.
*/
function rl_mailwarmer_render_create_dns_backup_box($post)
{
// Add a nonce field for security
wp_nonce_field('create_dns_backup_nonce', 'create_dns_backup_nonce_field');
// Render the button
?>
<p>
<button type="button" id="create-dns-backup-button" class="button button-primary">
<?php esc_html_e('Create DNS Backup', 'rl-mailwarmer'); ?>
</button>
</p>
<div id="dns-backup-result"></div>
<?php
}
/**
* Render the fields for the "Fix Deliverability DNS Issues" meta box.
*
* @param WP_Post $post The current post object.
*/
function rl_mailwarmer_render_fix_deliverability_dns_issues_box($post)
{
// Add a nonce field for security
wp_nonce_field('fix_deliverability_dns_issues_nonce', 'fix_deliverability_dns_issues_nonce_field');
// Render the button
?>
<p>
<button type="button" id="fix-dns-issues-button" class="button button-primary">
<?php esc_html_e('Fix DNS Issues', 'rl-mailwarmer'); ?>
</button>
</p>
<div id="dns-issues-fix-result"></div>
<?php
}
/**
* Render the fields for the "Update MX Record" meta box.
*
* @param WP_Post $post The current post object.
*/
function rl_mailwarmer_render_update_mx_record_box($post)
{
// Add a nonce field for security
wp_nonce_field('update_mx_record_nonce', 'update_mx_record_nonce_field');
// Render the fields
?>
<p>
<label for="mx_action"><?php esc_html_e('Action', 'rl-mailwarmer'); ?></label><br>
<select id="mx_action" name="mx_action">
<!-- <option value=""><?php esc_html_e('Select', 'rl-mailwarmer'); ?></option> -->
<option value="add"><?php esc_html_e('Add', 'rl-mailwarmer'); ?></option>
<option value="delete"><?php esc_html_e('Delete', 'rl-mailwarmer'); ?></option>
</select>
</p>
<!-- <p>
<label for="mx_host"><?php //esc_html_e('Host', 'rl-mailwarmer'); ?></label><br>
<input type="text" id="mx_host" name="mx_host" class="regular-text">
</p> -->
<p>
<label for="mx_content"><?php esc_html_e('Content', 'rl-mailwarmer'); ?></label><br>
<input type="text" id="mx_content" name="mx_content" class="regular-text" value="onyx.bldsecurity.com">
</p>
<p>
<label for="mx_priority"><?php esc_html_e('Priority', 'rl-mailwarmer'); ?></label><br>
<input type="number" id="mx_priority" name="mx_priority" class="small-text" value="0" min="0">
</p>
<p>
<label for="mx_ttl"><?php esc_html_e('TTL', 'rl-mailwarmer'); ?></label><br>
<input type="number" id="mx_ttl" name="mx_ttl" class="small-text" value="3600" min="1">
</p>
<p>
<button type="button" id="update-mx-record-button" class="button button-primary">
<?php esc_html_e('Update MX Record', 'rl-mailwarmer'); ?>
</button>
</p>
<div id="mx-update-result"></div>
<?php
}
/**
* Render the fields for the "Update SPF Record" meta box.
*
* @param WP_Post $post The current post object.
*/
function rl_mailwarmer_render_update_spf_record_box($post)
{
// Add a nonce field for security
wp_nonce_field('update_spf_record_nonce', 'update_spf_record_nonce_field');
// Render the fields
?>
<p>
<label for="spf_host"><?php esc_html_e('Host', 'rl-mailwarmer'); ?></label><br>
<input type="text" id="spf_host" name="spf_host" class="regular-text">
</p>
<p>
<label for="spf_action"><?php esc_html_e('Action', 'rl-mailwarmer'); ?></label><br>
<select id="spf_action" name="spf_action">
<option value=""><?php esc_html_e('Select', 'rl-mailwarmer'); ?></option>
<option value="add"><?php esc_html_e('Add', 'rl-mailwarmer'); ?></option>
<option value="delete"><?php esc_html_e('Delete', 'rl-mailwarmer'); ?></option>
</select>
</p>
<p>
<label for="spf_all_policy"><?php esc_html_e('All Policy', 'rl-mailwarmer'); ?></label><br>
<select id="spf_all_policy" name="spf_all_policy">
<option value="-all"><?php esc_html_e('Fail (-all)', 'rl-mailwarmer'); ?></option>
<option value="~all"><?php esc_html_e('SoftFail (~all)', 'rl-mailwarmer'); ?></option>
</select>
</p>
<p>
<label for="spf_ttl"><?php esc_html_e('TTL', 'rl-mailwarmer'); ?></label><br>
<input type="number" id="spf_ttl" name="spf_ttl" class="small-text" value="3600" min="1">
</p>
<p>
<button type="button" id="update-spf-record-button" class="button button-primary">
<?php esc_html_e('Update SPF Record', 'rl-mailwarmer'); ?>
</button>
</p>
<div id="spf-update-result"></div>
<?php
}
/**
* Render the fields for the "Update DMARC Record" meta box.
*
* @param WP_Post $post The current post object.
*/
function rl_mailwarmer_render_update_dmarc_record_box($post)
{
// Add a nonce field for security
wp_nonce_field('update_dmarc_record_nonce', 'update_dmarc_record_nonce_field');
// Render the form fields
?>
<p>
<label for="dmarc_policy"><?php esc_html_e('Policy (p)', 'rl-mailwarmer'); ?></label><br>
<select id="dmarc_policy" name="dmarc_policy">
<option value=""><?php esc_html_e('Select...', 'rl-mailwarmer'); ?></option>
<option value="reject"><?php esc_html_e('Reject', 'rl-mailwarmer'); ?></option>
<option value="quarantine"><?php esc_html_e('Quarantine', 'rl-mailwarmer'); ?></option>
<option value="none"><?php esc_html_e('None', 'rl-mailwarmer'); ?></option>
</select>
</p>
<p>
<label for="dmarc_sp"><?php esc_html_e('Subdomain Policy (sp)', 'rl-mailwarmer'); ?></label><br>
<select id="dmarc_sp" name="dmarc_sp">
<option value=""><?php esc_html_e('Select...', 'rl-mailwarmer'); ?></option>
<option value="reject"><?php esc_html_e('Reject', 'rl-mailwarmer'); ?></option>
<option value="quarantine"><?php esc_html_e('Quarantine', 'rl-mailwarmer'); ?></option>
<option value="none"><?php esc_html_e('None', 'rl-mailwarmer'); ?></option>
</select>
</p>
<p>
<label for="dmarc_pct"><?php esc_html_e('Percentage (pct)', 'rl-mailwarmer'); ?></label><br>
<input type="number" id="dmarc_pct" name="dmarc_pct" class="small-text" min="0" max="100" value="100">
</p>
<p>
<label for="dmarc_aspf"><?php esc_html_e('SPF Alignment (aspf)', 'rl-mailwarmer'); ?></label><br>
<select id="dmarc_aspf" name="dmarc_aspf">
<option value=""><?php esc_html_e('Select...', 'rl-mailwarmer'); ?></option>
<option value="s"><?php esc_html_e('Strict', 'rl-mailwarmer'); ?></option>
<option value="r"><?php esc_html_e('Relaxed', 'rl-mailwarmer'); ?></option>
</select>
</p>
<p>
<label for="dmarc_adkim"><?php esc_html_e('DKIM Alignment (adkim)', 'rl-mailwarmer'); ?></label><br>
<select id="dmarc_adkim" name="dmarc_adkim">
<option value=""><?php esc_html_e('Select...', 'rl-mailwarmer'); ?></option>
<option value="s"><?php esc_html_e('Strict', 'rl-mailwarmer'); ?></option>
<option value="r"><?php esc_html_e('Relaxed', 'rl-mailwarmer'); ?></option>
</select>
</p>
<p>
<label for="dmarc_rua"><?php esc_html_e('Aggregate Report Address (rua)', 'rl-mailwarmer'); ?></label><br>
<input type="email" id="dmarc_rua" name="dmarc_rua" class="regular-text">
</p>
<p>
<label for="dmarc_ruf"><?php esc_html_e('Forensic Report Address (ruf)', 'rl-mailwarmer'); ?></label><br>
<input type="email" id="dmarc_ruf" name="dmarc_ruf" class="regular-text">
</p>
<p>
<label for="dmarc_fo"><?php esc_html_e('Failure Reporting Options (fo)', 'rl-mailwarmer'); ?></label><br>
<input type="text" id="dmarc_fo" name="dmarc_fo" class="regular-text" placeholder="e.g., 1, 0, d, or s">
</p>
<p>
<label for="dmarc_rf"><?php esc_html_e('Report Format (rf)', 'rl-mailwarmer'); ?></label><br>
<input type="text" id="dmarc_rf" name="dmarc_rf" class="regular-text" placeholder="e.g., afrf">
</p>
<p>
<label for="dmarc_ri"><?php esc_html_e('Report Interval (ri)', 'rl-mailwarmer'); ?></label><br>
<input type="number" id="dmarc_ri" name="dmarc_ri" class="regular-text" value="86400" min="1">
</p>
<p>
<button type="button" id="update-dmarc-record-button" class="button button-primary">
<?php esc_html_e('Update DMARC Record', 'rl-mailwarmer'); ?>
</button>
</p>
<div id="dmarc-update-result"></div>
<?php
}
/**
* Render the fields for the "Update DKIM Record" meta box.
*
* @param WP_Post $post The current post object.
*/
function rl_mailwarmer_render_update_dkim_record_box($post)
{
// Add a nonce field for security
wp_nonce_field('update_dkim_record_nonce', 'update_dkim_record_nonce_field');
// Render the form fields
?>
<p>
<label for="dkim_selector"><?php esc_html_e('Selector', 'rl-mailwarmer'); ?></label><br>
<input type="text" id="dkim_selector" name="dkim_selector" class="regular-text">
</p>
<p>
<label for="dkim_action"><?php esc_html_e('Action', 'rl-mailwarmer'); ?></label><br>
<select id="dkim_action" name="dkim_action">
<option value="add"><?php esc_html_e('Add', 'rl-mailwarmer'); ?></option>
<option value="delete"><?php esc_html_e('Delete', 'rl-mailwarmer'); ?></option>
</select>
</p>
<p>
<label for="dkim_value"><?php esc_html_e('Value (Public Key)', 'rl-mailwarmer'); ?></label><br>
<textarea id="dkim_value" name="dkim_value" rows="3" class="regular-text"></textarea>
</p>
<p>
<label for="dkim_ttl"><?php esc_html_e('TTL', 'rl-mailwarmer'); ?></label><br>
<input type="number" id="dkim_ttl" name="dkim_ttl" class="small-text" value="3600" min="1">
</p>
<p>
<button type="button" id="update-dkim-record-button" class="button button-primary">
<?php esc_html_e('Update DKIM Record', 'rl-mailwarmer'); ?>
</button>
</p>
<div id="dkim-update-result"></div>
<?php
}
/**
* Add custom columns to the "All Domain Health Reports" admin page.
*
* @param array $columns Default columns.
* @return array Modified columns.
*/
add_filter('manage_domain-health-report_posts_columns', function ($columns) {
// Remove default columns if necessary
// unset($columns['date']);
// Add custom columns
$custom_columns = [
'domain_name' => __('Domain Name', 'rl-mailwarmer'),
'domain_valid' => __('Valid', 'rl-mailwarmer'),
'domain_age' => __('Age', 'rl-mailwarmer'),
'domain_days_to_expiration' => __('Days to Expiration', 'rl-mailwarmer'),
'a_record_valid' => __('A Record Valid', 'rl-mailwarmer'),
// 'a_record_resolves' => __('A Record Resolves To', 'rl-mailwarmer'),
'http_status' => __('HTTP Status', 'rl-mailwarmer'),
'https_enabled' => __('HTTPS Enabled', 'rl-mailwarmer'),
'mx_record_valid' => __('Valid MX Record', 'rl-mailwarmer'),
// 'mx_record_ptr_valid' => __('PTR Valid', 'rl-mailwarmer'),
// 'mx_record_ptr_match' => __('PTR Matches', 'rl-mailwarmer'),
// 'spf_record_exists' => __('SPF Exists', 'rl-mailwarmer'),
'spf_record_content' => __('SPF Record', 'rl-mailwarmer'),
// 'spf_record_ttl' => __('SPF TTL', 'rl-mailwarmer'),
// 'spf_record_all_mechanism' => __('SPF All Mechanism', 'rl-mailwarmer'),
'dmarc_record_exists' => __('DMARC Exists', 'rl-mailwarmer'),
'dmarc_policy' => __('DMARC Policy', 'rl-mailwarmer'),
// 'dmarc_sp_policy' => __('DMARC SP Policy', 'rl-mailwarmer'),
// 'dmarc_percentage' => __('DMARC Percentage', 'rl-mailwarmer'),
// 'dmarc_aspf' => __('DMARC ASPF', 'rl-mailwarmer'),
// 'dmarc_adkim' => __('DMARC ADKIM', 'rl-mailwarmer'),
// 'dmarc_aggregate_rpt' => __('DMARC Aggregate RPT', 'rl-mailwarmer'),
// 'dmarc_forensic_rpt' => __('DMARC Forensic RPT', 'rl-mailwarmer'),
// 'dmarc_report_format' => __('DMARC Report Format', 'rl-mailwarmer'),
// 'dmarc_report_interval' => __('DMARC Report Interval', 'rl-mailwarmer'),
'dkim_records' => __('DKIM Records', 'rl-mailwarmer'),
];
return array_merge($columns, $custom_columns);
});
/**
* Populate custom column data for the "All Domain Health Reports" admin page.
*
* @param string $column The column name.
* @param int $post_id The post ID.
*/
add_action('manage_domain-health-report_posts_custom_column', function ($column, $post_id) {
$meta = get_post_meta($post_id);
switch ($column) {
case 'domain_name':
echo esc_html($meta['domain_name'][0] ?? '');
break;
case 'domain_valid':
echo !empty($meta['domain_valid'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'domain_age':
echo esc_html($meta['domain_age'][0] ?? '');
break;
case 'domain_days_to_expiration':
echo esc_html($meta['domain_days_to_expiration'][0] ?? '');
break;
case 'a_record_valid':
echo !empty($meta['a_record_valid'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'a_record_resolves':
echo esc_html($meta['a_record_resolves'][0] ?? '');
break;
case 'http_status':
echo esc_html($meta['http_status'][0] ?? '');
break;
case 'https_enabled':
echo !empty($meta['https_enabled'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'mx_record_valid':
echo !empty($meta['mx_record_valid'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'mx_record_ptr_valid':
echo !empty($meta['mx_record_ptr_valid'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'mx_record_ptr_match':
echo !empty($meta['mx_record_ptr_match'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'spf_record_exists':
echo !empty($meta['spf_record_exists'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'spf_record_content':
echo !empty($meta['spf_record_content'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'spf_record_ttl':
echo esc_html($meta['spf_record_ttl'][0] ?? '');
break;
case 'spf_record_all_mechanism':
echo esc_html($meta['spf_record_all_mechanism'][0] ?? '');
break;
case 'dmarc_record_exists':
echo !empty($meta['dmarc_record_exists'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'dmarc_policy':
echo esc_html($meta['dmarc_policy'][0] ?? '');
break;
case 'dmarc_sp_policy':
echo esc_html($meta['dmarc_sp_policy'][0] ?? '');
break;
case 'dmarc_percentage':
echo esc_html($meta['dmarc_percentage'][0] ?? '');
break;
case 'dmarc_aspf':
echo esc_html($meta['dmarc_aspf'][0] ?? '');
break;
case 'dmarc_adkim':
echo esc_html($meta['dmarc_adkim'][0] ?? '');
break;
case 'dmarc_aggregate_rpt':
echo esc_html($meta['dmarc_aggregate_rpt'][0] ?? '');
break;
case 'dmarc_forensic_rpt':
echo esc_html($meta['dmarc_forensic_rpt'][0] ?? '');
break;
case 'dmarc_report_format':
echo esc_html($meta['dmarc_report_format'][0] ?? '');
break;
case 'dmarc_report_interval':
echo esc_html($meta['dmarc_report_interval'][0] ?? '');
break;
case 'dkim_records':
echo esc_html($meta['dkim_records'][0] ?? '');
break;
default:
echo '';
}
}, 10, 2);
// Make Columns Sortable
add_filter('manage_edit-domain-health-report_sortable_columns', function ($columns) {
$columns['domain_name'] = 'domain_name';
$columns['domain_valid'] = 'domain_valid';
$columns['domain_age'] = 'domain_age';
$columns['mx_record_valid'] = 'mx_record_valid';
// Add more sortable columns as needed
return $columns;
});
/**
* Add custom columns to the "All Domains" admin page.
*
* @param array $columns Default columns.
* @return array Modified columns.
*/
add_filter('manage_domain_posts_columns', function ($columns) {
// Remove default columns if necessary
// unset($columns['date']);
// Add custom columns
$custom_columns = [
// 'domain_name' => __('Domain Name', 'rl-mailwarmer'),
'domain_valid' => __('Valid', 'rl-mailwarmer'),
'domain_age' => __('Age', 'rl-mailwarmer'),
'domain_days_to_expiration' => __('Days to Expiration', 'rl-mailwarmer'),
'a_record_valid' => __('A Record Valid', 'rl-mailwarmer'),
// 'a_record_resolves' => __('A Record Resolves To', 'rl-mailwarmer'),
'http_status' => __('HTTP Status', 'rl-mailwarmer'),
'https_enabled' => __('HTTPS Enabled', 'rl-mailwarmer'),
'mx_record' => __('MX Record', 'rl-mailwarmer'),
// 'mx_record_ptr_valid' => __('PTR Valid', 'rl-mailwarmer'),
// 'mx_record_ptr_match' => __('PTR Matches', 'rl-mailwarmer'),
// 'spf_record_exists' => __('SPF Exists', 'rl-mailwarmer'),
'spf_record_content' => __('SPF Record', 'rl-mailwarmer'),
// 'spf_record_ttl' => __('SPF TTL', 'rl-mailwarmer'),
// 'spf_record_all_mechanism' => __('SPF All Mechanism', 'rl-mailwarmer'),
'dmarc_record_exists' => __('DMARC Exists', 'rl-mailwarmer'),
'dmarc_policy' => __('DMARC Policy', 'rl-mailwarmer'),
// 'dmarc_sp_policy' => __('DMARC SP Policy', 'rl-mailwarmer'),
// 'dmarc_percentage' => __('DMARC Percentage', 'rl-mailwarmer'),
// 'dmarc_aspf' => __('DMARC ASPF', 'rl-mailwarmer'),
// 'dmarc_adkim' => __('DMARC ADKIM', 'rl-mailwarmer'),
// 'dmarc_aggregate_rpt' => __('DMARC Aggregate RPT', 'rl-mailwarmer'),
// 'dmarc_forensic_rpt' => __('DMARC Forensic RPT', 'rl-mailwarmer'),
// 'dmarc_report_format' => __('DMARC Report Format', 'rl-mailwarmer'),
// 'dmarc_report_interval' => __('DMARC Report Interval', 'rl-mailwarmer'),
'dkim_records' => __('DKIM Records', 'rl-mailwarmer'),
];
return array_merge($columns, $custom_columns);
});
/**
* Populate custom column data for the "All Domains" admin page.
*
* @param string $column The column name.
* @param int $post_id The post ID.
*/
add_action('manage_domain_posts_custom_column', function ($column, $post_id) {
$meta = get_post_meta($post_id);
$json_report = $meta['domain_health_report'][0];
// Decode the JSON into an associative array
$report = json_decode($json_report, true);
// var_dump($report);
// // Check for JSON decoding errors
// if (json_last_error() !== JSON_ERROR_NONE) {
// log_to_file("rl_mailwarmer_render_domain_metadata_table - JSON decode error for post {$post->ID}: " . json_last_error_msg());
// // return null;
// }
// log_to_file("manage_domain_posts_custom_column - Report array: ", $report["domain_health"]);
// Assign metadata to the array using $post_meta
$metadata = [
'domain_valid' => $report["domain_health"]['registration_valid'] ?? '',
'domain_age' => $report["domain_health"]['domain_age'] ?? '',
'domain_days_to_expiration' => $report["domain_health"]['days_to_expiration'] ?? '',
'a_record_ip' => $report["a_record"]['ip'] ?? '',
'http_status' => $report["a_record"]['http_status'] ?? '',
'https_enabled' => $report["a_record"]['https_enabled'] ?? '',
'mx_record_host' => $report["mx_record"]['host'] ?? '',
'mx_record_ptr_valid' => $report["mx_record"]['ptr_valid'] ?? '',
'mx_record_ptr_match' => $report["mx_record"]['ptr_matches'] ?? '',
'spf_record' => $report["spf_record"]['content'] ?? '',
'spf_record_ttl' => $report["spf_record"]['ttl'] ?? '',
'spf_record_all_mechanism' => $report["spf_record"]['all_mechanism'] ?? '',
'dmarc_record_exists' => $report["dmarc_record"]['exists'] ?? '',
'dmarc_record_content' => $report["dmarc_record"]['content'] ?? '',
'dmarc_record_ttl' => $report["dmarc_record"]['ttl'] ?? '',
'dmarc_policy' => $report["dmarc_record"]['policy'] ?? '',
'dmarc_sp_policy' => $report["dmarc_record"]['sp_policy'] ?? '',
'dmarc_percentage' => $report["dmarc_record"]['percentage'] ?? '',
'dmarc_aspf' => $report["dmarc_record"]['aspf'] ?? '',
'dmarc_adkim' => $report["dmarc_record"]['adkim'] ?? '',
'dmarc_aggregate_rpt' => $report["dmarc_record"]['aggregate_rpt'] ?? '',
'dmarc_forensic_rpt' => $report["dmarc_record"]['forensic_rpt'] ?? '',
'dmarc_report_format' => $report["dmarc_record"]['report_format'] ?? '',
'dmarc_report_interval' => $report["dmarc_record"]['report_interval'] ?? '',
'dkim_records' => $report['dkim_records'] ?? '',
];
// log_to_file("manage_domain_posts_custom_column - Health report: ", $domain_report);
switch ($column) {
case 'domain_valid':
echo !empty($report["domain_health"]['registration_valid']) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
break;
case 'domain_age':
echo !empty($report["domain_health"]['domain_age']) ? $report["domain_health"]['domain_age'] : __('0', 'rl-mailwarmer');
break;
case 'mx_record':
echo !empty($report["mx_record"]['host']) ? $report["mx_record"]['host'] : 'Unset';
break;
// case 'domain_days_to_expiration':
// echo esc_html($meta['domain_days_to_expiration'][0] ?? '');
// break;
// case 'a_record_valid':
// echo !empty($meta['a_record_valid'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
// break;
// case 'a_record_resolves':
// echo esc_html($meta['a_record_resolves'][0] ?? '');
// break;
// case 'http_status':
// echo esc_html($meta['http_status'][0] ?? '');
// break;
// case 'https_enabled':
// echo !empty($meta['https_enabled'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
// break;
// case 'mx_record_ptr_valid':
// echo !empty($meta['mx_record_ptr_valid'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
// break;
// case 'mx_record_ptr_match':
// echo !empty($meta['mx_record_ptr_match'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
// break;
// case 'spf_record_exists':
// echo !empty($meta['spf_record_exists'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
// break;
// case 'spf_record_is_valid':
// echo !empty($meta['spf_record_is_valid'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
// break;
// case 'spf_record_ttl':
// echo esc_html($meta['spf_record_ttl'][0] ?? '');
// break;
// case 'spf_record_all_mechanism':
// echo esc_html($meta['spf_record_all_mechanism'][0] ?? '');
// break;
// case 'dmarc_record_exists':
// echo !empty($meta['dmarc_record_exists'][0]) ? __('Yes', 'rl-mailwarmer') : __('No', 'rl-mailwarmer');
// break;
// case 'dmarc_policy':
// echo esc_html($meta['dmarc_policy'][0] ?? '');
// break;
// case 'dmarc_sp_policy':
// echo esc_html($meta['dmarc_sp_policy'][0] ?? '');
// break;
// case 'dmarc_percentage':
// echo esc_html($meta['dmarc_percentage'][0] ?? '');
// break;
// case 'dmarc_aspf':
// echo esc_html($meta['dmarc_aspf'][0] ?? '');
// break;
// case 'dmarc_adkim':
// echo esc_html($meta['dmarc_adkim'][0] ?? '');
// break;
// case 'dmarc_aggregate_rpt':
// echo esc_html($meta['dmarc_aggregate_rpt'][0] ?? '');
// break;
// case 'dmarc_forensic_rpt':
// echo esc_html($meta['dmarc_forensic_rpt'][0] ?? '');
// break;
// case 'dmarc_report_format':
// echo esc_html($meta['dmarc_report_format'][0] ?? '');
// break;
// case 'dmarc_report_interval':
// echo esc_html($meta['dmarc_report_interval'][0] ?? '');
// break;
// case 'dkim_records':
// echo esc_html($meta['dkim_records'][0] ?? '');
// break;
default:
echo '';
}
}, 10, 2);
// Make Columns Sortable
add_filter('manage_edit-domain_sortable_columns', function ($columns) {
// $columns['domain_name'] = 'domain_name';
$columns['domain_valid'] = 'domain_valid';
$columns['domain_age'] = 'domain_age';
$columns['mx_record'] = 'mx_record';
// Add more sortable columns as needed
return $columns;
});
/**
* Add a custom meta box to display domain metadata.
*/
add_action('add_meta_boxes', function () {
add_meta_box(
'domain_metadata_table', // Meta box ID
__('Domain Health', 'rl-mailwarmer'), // Title
'rl_mailwarmer_render_domain_metadata_table', // Callback function
'domain', // Post type
'normal', // Context
'low' // Priority
);
});
/**
* Render the metadata table for the "Domain Metadata" meta box.
*
* @param WP_Post $post The current post object.
*/
function rl_mailwarmer_render_domain_metadata_table($post)
{
// Fetch the domain health report from post meta
$json_report = get_post_meta($post->ID, 'domain_health_report', true);
// Check if the meta field exists and is not empty
if (empty($json_report)) {
return null; // or throw an exception, depending on your error handling preference
}
// Decode the JSON into an associative array
$report = json_decode($json_report, true);
// Check for JSON decoding errors
if (json_last_error() !== JSON_ERROR_NONE) {
log_to_file("rl_mailwarmer_render_domain_metadata_table - JSON decode error for post {$post->ID}: " . json_last_error_msg());
// return null;
}
// log_to_file("rl_mailwarmer_render_domain_metadata_table - Report array: ", $report);
// Assign metadata to the array using $post_meta
$metadata = [
'domain_valid' => $report["domain_health"]['registration_valid'] ?? '',
'domain_age' => $report["domain_health"]['domain_age'] ?? '',
'domain_days_to_expiration' => $report["domain_health"]['days_to_expiration'] ?? '',
'a_record_ip' => $report["a_record"]['ip'] ?? '',
'http_status' => $report["a_record"]['http_status'] ?? '',
'https_enabled' => $report["a_record"]['https_enabled'] ?? '',
'mx_record_host' => $report["mx_record"]['host'] ?? '',
'mx_record_ptr_valid' => $report["mx_record"]['ptr_valid'] ?? '',
'mx_record_ptr_match' => $report["mx_record"]['ptr_matches'] ?? '',
'spf_record' => $report["spf_record"]['content'] ?? '',
'spf_record_ttl' => $report["spf_record"]['ttl'] ?? '',
'spf_record_all_mechanism' => $report["spf_record"]['all_mechanism'] ?? '',
'dmarc_record_exists' => $report["dmarc_record"]['exists'] ?? '',
'dmarc_record_content' => $report["dmarc_record"]['content'] ?? '',
'dmarc_record_ttl' => $report["dmarc_record"]['ttl'] ?? '',
'dmarc_policy' => $report["dmarc_record"]['policy'] ?? '',
'dmarc_sp_policy' => $report["dmarc_record"]['sp_policy'] ?? '',
'dmarc_percentage' => $report["dmarc_record"]['percentage'] ?? '',
'dmarc_aspf' => $report["dmarc_record"]['aspf'] ?? '',
'dmarc_adkim' => $report["dmarc_record"]['adkim'] ?? '',
'dmarc_aggregate_rpt' => $report["dmarc_record"]['aggregate_rpt'] ?? '',
'dmarc_forensic_rpt' => $report["dmarc_record"]['forensic_rpt'] ?? '',
'dmarc_report_format' => $report["dmarc_record"]['report_format'] ?? '',
'dmarc_report_interval' => $report["dmarc_record"]['report_interval'] ?? '',
'dkim_records' => $report['dkim_records'] ?? '',
];
// Render the table
echo '<table class="widefat striped rl_admin_meta_table">';
echo '<thead>';
echo '<tr>';
echo '<th>' . __('Title', 'rl-mailwarmer') . '</th>';
echo '<th>' . __('Value', 'rl-mailwarmer') . '</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach ($metadata as $key => $value) {
echo '<tr>';
echo '<td>' . esc_html(ucwords(str_replace('_', ' ', $key))) . '</td>';
echo '<td>' . esc_html(is_array($value) ? json_encode($value) : $value) . '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
}