diff --git a/readme.txt b/readme.txt index d67979e..8d2ac40 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: pushover, notifications, email, wp_mail Requires at least: 6.0 Tested up to: 6.6 Requires PHP: 7.4 -Stable tag: 1.0.0 +Stable tag: 1.1.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -65,6 +65,10 @@ To use this plugin, you need both a Pushover User Key and an API Token: define('PUSHOVER_USER_KEY', 'your-pushover-user-key'); ``` += How do I make sure I've configured my API Token and User Key correctly? = + +As of version 1.1.0, there's a link on the "Plugins -> Installed Plugins" page (when the plugin is active) that will send you a test message. + = Would you consider adding Pushbullet support? = This plugin was created and — continues to be maintained — for totally selfish personal reasons. Since I don't use Pushbullet at all, I don't feel that I could adequately support that service. @@ -75,14 +79,12 @@ I would prefer not to. == Changelog == += 1.1.0 = +* Added Test link to Plugins page so you could check that things are configured correctly. + = 1.0.0 = * Initial release of the plugin. -== Upgrade Notice == - -= 1.0.0 = -Initial release. No upgrade is needed. - == License == This plugin is licensed under the GPLv2 or later. For more details, please refer to the license file in the plugin package or visit the [GPLv2 License page](https://www.gnu.org/licenses/gpl-2.0.html). diff --git a/total-pushover.php b/total-pushover.php index 945e2c1..759db15 100644 --- a/total-pushover.php +++ b/total-pushover.php @@ -1,7 +1,7 @@ ' . __('Test') . ''; + array_unshift($links, $test_link); + return $links; +} + +/** + * Handle the test message when "Test" link is clicked + */ +add_action('admin_init', 'total_pushover_send_test_message'); + +/** + * Send a test message to Pushover when the "Send Test" link is clicked + */ +function total_pushover_send_test_message() +{ + // Check if the test message was requested + if (isset($_GET['total_pushover_test']) && $_GET['total_pushover_test'] === 'true') { + // Start output buffering to prevent any output + ob_start(); + + $pushover_token = defined('PUSHOVER_API_TOKEN') ? PUSHOVER_API_TOKEN : ''; + $pushover_user = defined('PUSHOVER_USER_KEY') ? PUSHOVER_USER_KEY : ''; + + if (empty($pushover_token) || empty($pushover_user)) { + set_transient('total_pushover_notice', 'error', 10); + } else { + $message = [ + 'token' => sanitize_text_field($pushover_token), + 'user' => sanitize_text_field($pushover_user), + 'title' => '[Total Pushover] Success!', + 'message' => 'This is a test of the Total Pushover Notification System. The admin of your WordPress install, in voluntary cooperation with Little Room, have deployed this plugin to keep you informed in the event of a site email. If this had been an actual email, you would have received it instead of this message. This is only a test.', + ]; + + $response = wp_remote_post('https://api.pushover.net/1/messages.json', [ + 'body' => $message, + ]); + + if (is_wp_error($response)) { + set_transient('total_pushover_notice', 'error', 10); + } else { + set_transient('total_pushover_notice', 'success', 10); + } + } + + // Redirect back to the Plugins page + wp_safe_redirect(admin_url('plugins.php')); + exit; + } +} + +/** + * Display admin notice after test message + */ +add_action('admin_notices', 'total_pushover_test_notice'); + +/** + * Display an admin notice after sending a test message to Pushover + */ +function total_pushover_test_notice() +{ + // Check if there is a notice to display + $notice = get_transient('total_pushover_notice'); + + if ($notice === 'success') { + echo '
' . __('Pushover test sent successfully.') . '
' . __('Pushover test failed! Please check your API credentials.') . '