plugin + readme
This commit is contained in:
parent
3ed0132c5e
commit
447806b202
88
readme.txt
Normal file
88
readme.txt
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
=== Total Pushover ===
|
||||||
|
Contributors: Jason Cosper
|
||||||
|
Donate link: https://littleroom.studio/
|
||||||
|
Tags: pushover, notifications, email, wp_mail
|
||||||
|
Requires at least: 6.0
|
||||||
|
Tested up to: 6.6
|
||||||
|
Requires PHP: 7.4
|
||||||
|
Stable tag: 1.0
|
||||||
|
License: GPLv2 or later
|
||||||
|
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
|
||||||
|
Redirects all WordPress emails to the Pushover notification service.
|
||||||
|
|
||||||
|
== Description ==
|
||||||
|
|
||||||
|
Total Pushover redirects all WordPress generated emails to the Pushover notification service. Pushover is an app that provides real-time notifications on your iOS or Android devices.
|
||||||
|
|
||||||
|
This is especially handy when you don't want to worry about setting up either an SMTP or transactional mail plugin on your development sites.
|
||||||
|
|
||||||
|
It is suggested that this plugin only be used on single-user WordPress installs. Everything that your site would usually mail out — including password reset requests for all site users — will be sent to the Pushover account that you've configured.
|
||||||
|
|
||||||
|
= Features =
|
||||||
|
* Automatically intercepts all `wp_mail` function and redirects the output to Pushover.
|
||||||
|
* Logs errors if the notification fails to be sent to Pushover.
|
||||||
|
* Configuration via constants in `wp-config.php`.
|
||||||
|
|
||||||
|
== Installation ==
|
||||||
|
|
||||||
|
1. Upload the plugin to the `/wp-content/plugins/` directory, or install the plugin directly via the WordPress plugins screen.
|
||||||
|
2. Activate the plugin through the 'Plugins' screen in WordPress.
|
||||||
|
3. Add the following constants to your `wp-config.php` file:
|
||||||
|
|
||||||
|
```
|
||||||
|
define('PUSHOVER_API_TOKEN', 'your-pushover-api-token');
|
||||||
|
define('PUSHOVER_USER_KEY', 'your-pushover-user-key');
|
||||||
|
```
|
||||||
|
|
||||||
|
== Frequently Asked Questions ==
|
||||||
|
|
||||||
|
= Why is there not a settings page? =
|
||||||
|
|
||||||
|
This plugin should be considered a developer tool. If you are not comfortable adding constants to `wp-config.php` you should reconsider using this plugin on your site.
|
||||||
|
|
||||||
|
= How do I get a Pushover User Key and API Token? =
|
||||||
|
|
||||||
|
To use this plugin, you need both a Pushover User Key and an API Token:
|
||||||
|
|
||||||
|
1. **Create a Pushover Account**
|
||||||
|
First, visit [Pushover.net](https://pushover.net/) and create a free account. You can use the same account on both your desktop and mobile devices.
|
||||||
|
|
||||||
|
2. **Find Your User Key**
|
||||||
|
After logging in, navigate to your Pushover dashboard. Your **User Key** will be displayed under the "Your User Key" section. This is a unique identifier that allows you to receive notifications.
|
||||||
|
|
||||||
|
3. **Generate an API Token**
|
||||||
|
To generate a new API Token, visit [Pushover Apps](https://pushover.net/apps/build).
|
||||||
|
- Click "Create a New Application/API Token".
|
||||||
|
- Fill in the details like the application's name and description.
|
||||||
|
- After submitting, your **API Token** will be shown. This token authorizes the plugin to send notifications to your account.
|
||||||
|
|
||||||
|
4. **Configure in `wp-config.php`**
|
||||||
|
After copying both your User Key and API Token, add the following constants to your `wp-config.php` file:
|
||||||
|
|
||||||
|
```
|
||||||
|
define('PUSHOVER_API_TOKEN', 'your-pushover-api-token');
|
||||||
|
define('PUSHOVER_USER_KEY', 'your-pushover-user-key');
|
||||||
|
```
|
||||||
|
|
||||||
|
= 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.
|
||||||
|
|
||||||
|
= Will you add support for per-user Pushover settings? =
|
||||||
|
|
||||||
|
I would prefer not to.
|
||||||
|
|
||||||
|
== Changelog ==
|
||||||
|
|
||||||
|
= 1.0 =
|
||||||
|
* Initial release of the plugin.
|
||||||
|
|
||||||
|
== Upgrade Notice ==
|
||||||
|
|
||||||
|
= 1.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).
|
52
total-pushover.php
Normal file
52
total-pushover.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Plugin Name: Total Pushover
|
||||||
|
* Version: 1.0
|
||||||
|
* Requires at least: 6.0
|
||||||
|
* Requires PHP: 7.4
|
||||||
|
* Author: Jason Cosper
|
||||||
|
* Author URI: https://littleroom.studio/
|
||||||
|
* License: GPL-2.0+
|
||||||
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
|
||||||
|
* Description: Redirects all WordPress email to the Pushover notification service.
|
||||||
|
* GitHub Plugin URI: boogah/total-pushover
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly
|
||||||
|
if (! defined('ABSPATH')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a filter to intercept wp_mail
|
||||||
|
add_filter('wp_mail', 'wp_pushover_intercept_mail', 10, 1);
|
||||||
|
|
||||||
|
function wp_pushover_intercept_mail($atts)
|
||||||
|
{
|
||||||
|
$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)) {
|
||||||
|
return $atts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare the message for Pushover
|
||||||
|
$message = [
|
||||||
|
'token' => sanitize_text_field($pushover_token),
|
||||||
|
'user' => sanitize_text_field($pushover_user),
|
||||||
|
'title' => sanitize_text_field($atts['subject']),
|
||||||
|
'message' => wp_kses_post($atts['message']),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Send the message to Pushover
|
||||||
|
$response = wp_remote_post('https://api.pushover.net/1/messages.json', [
|
||||||
|
'body' => $message,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (is_wp_error($response)) {
|
||||||
|
// Handle error if needed
|
||||||
|
error_log('Pushover notification failed: ' . $response->get_error_message());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return false to prevent wp_mail from sending the email
|
||||||
|
return false;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user