| 1 |
<?php |
| 2 |
defined('ABSPATH') or die('Unauthorized Access'); |
| 3 |
|
| 4 |
if (!Phpinfo_WP_License::is_valid()) { |
| 5 |
phpinfowp_render_feature_lock([ |
| 6 |
'feature' => 'Email Alerts & Webhooks', |
| 7 |
'icon' => 'dashicons-bell', |
| 8 |
'tagline' => 'Get notified on PHP EOL, config drift, OPcache drops, and SSL expiry via email, Slack, or Discord.', |
| 9 |
'previews' => [ |
| 10 |
'Email alerts: <strong>Disabled</strong>', |
| 11 |
'Slack webhook: <strong>—</strong>', |
| 12 |
'Last alert sent: <strong>—</strong>', |
| 13 |
], |
| 14 |
]); |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
$message = ''; |
| 19 |
$msg_type = 'success'; |
| 20 |
|
| 21 |
if (isset($_POST['phpinfowp_save_alerts']) && check_admin_referer('phpinfowp_alerts_nonce')) { |
| 22 |
Phpinfo_WP_Alerts::save_settings($_POST); |
| 23 |
$message = 'Alert settings saved.'; |
| 24 |
} |
| 25 |
|
| 26 |
if (isset($_POST['phpinfowp_test_alert']) && check_admin_referer('phpinfowp_alerts_nonce')) { |
| 27 |
$to = [get_option('admin_email')]; |
| 28 |
$site = get_bloginfo('name') . ' (' . get_site_url() . ')'; |
| 29 |
$sent = wp_mail($to, '[phpinfo() WP] Test alert', "This is a test alert from phpinfo() WP Pro.\nSite: {$site}"); |
| 30 |
$message = $sent ? 'Test email sent to ' . get_option('admin_email') : 'wp_mail() failed — check your mail configuration.'; |
| 31 |
$msg_type = $sent ? 'success' : 'error'; |
| 32 |
} |
| 33 |
|
| 34 |
if (isset($_POST['phpinfowp_test_webhook']) && check_admin_referer('phpinfowp_alerts_nonce')) { |
| 35 |
$ok = Phpinfo_WP_Alerts::send_webhook('Webhook test', 'This is a webhook test from phpinfo() WP Pro.'); |
| 36 |
$message = $ok ? 'Webhook payload delivered successfully.' : 'Webhook delivery failed — check the URL and provider settings.'; |
| 37 |
$msg_type = $ok ? 'success' : 'error'; |
| 38 |
} |
| 39 |
|
| 40 |
$s = Phpinfo_WP_Alerts::get_settings(); |
| 41 |
$next_cron = wp_next_scheduled('phpinfowp_weekly_maintenance'); |
| 42 |
?> |
| 43 |
|
| 44 |
<div class="phpinfowp-pro-page"> |
| 45 |
|
| 46 |
<div class="phpinfowp-page-header"> |
| 47 |
<div> |
| 48 |
<h1>Alerts <span class="phpinfowp-pro-badge"><?php _e('PRO', 'phpinfo-wp'); ?></span></h1> |
| 49 |
<p class="phpinfowp-page-subtitle"><?php _e('Email + Slack/Discord notifications for EOL, config changes, OPcache, and SSL events', 'phpinfo-wp'); ?></p> |
| 50 |
</div> |
| 51 |
</div> |
| 52 |
|
| 53 |
<?php if ($message): ?> |
| 54 |
<div class="notice notice-<?php echo $msg_type; ?> inline is-dismissible" style="margin:0 0 20px"><p><?php echo esc_html($message); ?></p></div> |
| 55 |
<?php endif; ?> |
| 56 |
|
| 57 |
<form method="post" style="max-width:720px"> |
| 58 |
<?php wp_nonce_field('phpinfowp_alerts_nonce'); ?> |
| 59 |
|
| 60 |
<table class="form-table" role="presentation"> |
| 61 |
<tr> |
| 62 |
<th scope="row"><?php _e('Enable Alerts', 'phpinfo-wp'); ?></th> |
| 63 |
<td> |
| 64 |
<label> |
| 65 |
<input type="checkbox" name="enabled" value="1" <?php checked($s['enabled']); ?>> |
| 66 |
Send alerts when issues are detected |
| 67 |
</label> |
| 68 |
</td> |
| 69 |
</tr> |
| 70 |
<tr> |
| 71 |
<th scope="row"><label for="alert_emails"><?php _e('Email recipients', 'phpinfo-wp'); ?></label></th> |
| 72 |
<td> |
| 73 |
<textarea name="emails" id="alert_emails" rows="3" class="large-text"><?php echo esc_textarea($s['emails']); ?></textarea> |
| 74 |
<p class="description"><?php _e('One email address per line (or comma-separated). Leave blank to disable email and use webhook only.', 'phpinfo-wp'); ?></p> |
| 75 |
</td> |
| 76 |
</tr> |
| 77 |
<tr> |
| 78 |
<th scope="row"><label for="webhook_url"><?php _e('Webhook URL', 'phpinfo-wp'); ?></label></th> |
| 79 |
<td> |
| 80 |
<?php if (!Phpinfo_WP_License::is_unlimited()): ?> |
| 81 |
<input type="url" disabled class="large-text" placeholder="<?php echo esc_attr__('https://hooks.slack.com/services/... (Requires Unlimited/Lifetime plan)', 'phpinfo-wp'); ?>"> |
| 82 |
<p class="description" style="color:#ba1a1a;font-weight:600;margin-top:6px"> |
| 83 |
Slack / Discord / Webhook integration requires the Unlimited or Lifetime plan. <a href="https://exeebit.com/phpinfo-wp#pricing" target="_blank" style="color:#7c3aed;text-decoration:none"><?php _e('Upgrade your plan →', 'phpinfo-wp'); ?></a> |
| 84 |
</p> |
| 85 |
<?php else: ?> |
| 86 |
<input type="url" name="webhook_url" id="webhook_url" value="<?php echo esc_attr($s['webhook_url']); ?>" |
| 87 |
class="large-text" placeholder="<?php echo esc_attr__('https://hooks.slack.com/services/... or https://discord.com/api/webhooks/...', 'phpinfo-wp'); ?>"> |
| 88 |
<p class="description" style="margin-top:6px"> |
| 89 |
<label style="margin-right:14px"> |
| 90 |
<input type="radio" name="webhook_type" value="slack" <?php checked($s['webhook_type'], 'slack'); ?>> |
| 91 |
Slack |
| 92 |
</label> |
| 93 |
<label style="margin-right:14px"> |
| 94 |
<input type="radio" name="webhook_type" value="discord" <?php checked($s['webhook_type'], 'discord'); ?>> |
| 95 |
Discord |
| 96 |
</label> |
| 97 |
<label> |
| 98 |
<input type="radio" name="webhook_type" value="generic" <?php checked($s['webhook_type'], 'generic'); ?>> |
| 99 |
Generic JSON (for Zapier, Make, etc.) |
| 100 |
</label> |
| 101 |
</p> |
| 102 |
<p class="description"><?php _e('HTTPS only. Same alerts as email — delivered to your chat or automation.', 'phpinfo-wp'); ?></p> |
| 103 |
<?php endif; ?> |
| 104 |
</td> |
| 105 |
</tr> |
| 106 |
<tr> |
| 107 |
<th scope="row"><?php _e('Alert Conditions', 'phpinfo-wp'); ?></th> |
| 108 |
<td> |
| 109 |
<label style="display:block;margin-bottom:8px"> |
| 110 |
<input type="checkbox" name="eol_warning" value="1" <?php checked($s['eol_warning']); ?>> |
| 111 |
<strong><?php _e('PHP EOL approaching', 'phpinfo-wp'); ?></strong> — alert when PHP is < 90 days from EOL, or already past it |
| 112 |
</label> |
| 113 |
<label style="display:block;margin-bottom:8px"> |
| 114 |
<input type="checkbox" name="config_change" value="1" <?php checked($s['config_change']); ?>> |
| 115 |
<strong><?php _e('Config changes detected', 'phpinfo-wp'); ?></strong> — alert when the weekly auto-snapshot detects php.ini changes |
| 116 |
</label> |
| 117 |
<label style="display:block;margin-bottom:8px"> |
| 118 |
<input type="checkbox" name="opcache_low" value="1" <?php checked($s['opcache_low']); ?>> |
| 119 |
<strong><?php _e('OPcache hit rate below', 'phpinfo-wp'); ?></strong> |
| 120 |
<input type="number" name="opcache_thresh" value="<?php echo esc_attr($s['opcache_thresh']); ?>" |
| 121 |
min="0" max="100" style="width:60px;margin:0 4px"> % |
| 122 |
</label> |
| 123 |
<label style="display:block;margin-bottom:8px"> |
| 124 |
<input type="checkbox" name="ssl_expiry" value="1" <?php checked($s['ssl_expiry']); ?>> |
| 125 |
<strong><?php _e('SSL certificate expiring within', 'phpinfo-wp'); ?></strong> |
| 126 |
<input type="number" name="ssl_thresh" value="<?php echo esc_attr($s['ssl_thresh']); ?>" |
| 127 |
min="1" max="365" style="width:65px;margin:0 4px"> days |
| 128 |
— <a href="<?php echo esc_url(admin_url('admin.php?page=phpinfowp-ssl')); ?>">Manage monitored domains</a> |
| 129 |
</label> |
| 130 |
<label style="display:block;margin-bottom:8px"> |
| 131 |
<?php if (!Phpinfo_WP_License::is_unlimited()): ?> |
| 132 |
<input type="checkbox" disabled> |
| 133 |
<span style="color:#646970"><strong><?php _e('Weekly digest', 'phpinfo-wp'); ?></strong> — summary every week: PHP, memory, config grade, OPcache, SSL, config changes <span style="color:#7c3aed;font-weight:600">(Requires Unlimited/Lifetime plan)</span></span> |
| 134 |
<?php else: ?> |
| 135 |
<input type="checkbox" name="weekly_digest" value="1" <?php checked($s['weekly_digest']); ?>> |
| 136 |
<strong><?php _e('Weekly digest', 'phpinfo-wp'); ?></strong> — summary every week: PHP, memory, config grade, OPcache, SSL, config changes |
| 137 |
<?php endif; ?> |
| 138 |
</label> |
| 139 |
</td> |
| 140 |
</tr> |
| 141 |
</table> |
| 142 |
|
| 143 |
<p class="submit" style="display:flex;gap:10px;align-items:center;flex-wrap:wrap"> |
| 144 |
<input type="submit" name="phpinfowp_save_alerts" class="button button-primary" value="<?php echo esc_attr__('Save Settings', 'phpinfo-wp'); ?>"> |
| 145 |
<input type="submit" name="phpinfowp_test_alert" class="button button-secondary" value="<?php echo esc_attr__('Send Test Email', 'phpinfo-wp'); ?>"> |
| 146 |
<?php if ($s['webhook_url']): ?> |
| 147 |
<input type="submit" name="phpinfowp_test_webhook" class="button button-secondary" value="<?php echo esc_attr__('Test Webhook', 'phpinfo-wp'); ?>"> |
| 148 |
<?php endif; ?> |
| 149 |
</p> |
| 150 |
</form> |
| 151 |
|
| 152 |
<div style="margin-top:24px;padding:16px 20px;background:#f9f9f9;border:1px solid #e0e0e0;border-radius:6px;max-width:720px"> |
| 153 |
<strong><?php _e('Alert schedule:', 'phpinfo-wp'); ?></strong> |
| 154 |
Alerts are checked weekly via WP Cron (alongside the auto-snapshot). |
| 155 |
<?php if ($next_cron): ?> |
| 156 |
Next run: <strong><?php echo esc_html(gmdate('Y-m-d H:i', $next_cron)); ?> UTC</strong> |
| 157 |
(<?php echo esc_html(human_time_diff($next_cron)); ?> from now). |
| 158 |
<?php else: ?> |
| 159 |
<span style="color:#d63638"><?php _e('WP Cron event not scheduled — deactivate and reactivate the plugin to fix this.', 'phpinfo-wp'); ?></span> |
| 160 |
<?php endif; ?> |
| 161 |
</div> |
| 162 |
</div> |
| 163 |
|