← Back to Push Notifications for WordPress
Answers to some common questions about Push Notifications for WordPress.
General
Please make sure your server supports the following requirements:
- PHP >= 7.2
- lib-curl >= 7.46.0 (with HTTP/2 support enabled)
- lib-openssl >= 1.0.2e
- PHP's cURL and GMP support
Ubuntu 20.04 meets all of these requirements.
For Web Push notifications:
For mobile notifications:
Oh, and if you use only Safari and Web Push (Chrome, Firefox, Edge, Opera and others) notifications, you do not need to create the apps! When visiting a site that supports notifications, the user will receive a prompt asking you if he would like to turn them on.
The Web Push notifications also work on Android, even if the browser isn't currently active--just like an installed native app. That's a big deal!
- WordPress 5.0 or later with "pretty" permalinks.
- PHP 7.0 or later (PHP 7.2 for iOS, Safari and Web Push notifications).
- PHP's cURL and GMP support (for Web Push notifications).
- PHP's cURL with HTTP/2 support enabled (for iOS and Safari notifications)
- An app (for iOS and Android notifications).
Moreover, to activate Safari and Web Push notifications on your multisite, we strongly recommend it uses sub-domains instead of sub-directories (i.e. https://site1.yournetwork.com
instead of https://yournetwork.com/site1
).
More requirements for Safari and Web Push notifications here.
Two things in particular:
- In Performance → Page cache → Rejected user agents you have to add the user agent of your app so that it is never sent a cached copy:
- In Performance → Database cache → Never cache the following pages you have to add
/pnfw/*
andpush_sw.js
Two things in particular:
- In Advanced → Rejected User Agents you have to add the user agent of your app so that it is never sent a cached copy.
- In Advanced → Add here strings (not a filename) that forces a page not to be cached you have to add
/pnfw/
andpush_sw.js
server { [...] location / { try_files $uri $uri/ /index.php?$args; } [...] }
To give you an idea, with a basic VPS hosting and older PHP versions you can expect:
- iOS: 15/20 notifications per second
- Android: 20/25 notifications per second
- Safari: 15/20 notifications per second
- Web Push: 20/25 notifications per second
Of course, you can get better performances with higher level servers and PHP 7.4+.
Desktop Notifications
Safari and Web Push notifications work just like push notifications for apps, but you don't need to build an app (see requirements below).
- An Apple Developer Program account (info here).
- A website under HTTPS protocol.
- PHP 7.2 or greater.
- lib-curl >= 7.46.0 (with HTTP/2 support enabled).
- lib-openssl >= 1.0.2e.
HTTPS is obligatory for serving the push package. You do not need to spend a fortune for the SSL certificate--there are some cheap options available. For example, Namecheap offers domain-level SSL certificates starting from $9.00/yr. Please note a dedicated IP is also highly recommended.
Beyond the Safari notifications going HTTPS is a good thing: Google has announced that it will give you a ranking boost (more info here).
Please note all Safari users will be anonymous (info here).
To enable logging on macOS, as reported in the Technical Note TN2265, use the following commands:
$ sudo defaults write /Library/Preferences/com.apple.apsd APSWriteLogs -bool TRUE
$ sudo defaults write /Library/Preferences/com.apple.apsd APSLogLevel -int 7
$ sudo killall apsd
The logs are stored in /Library/Logs/apsd.log
.
- PHP 7.2 or greater with GMP extension.
- A website under HTTPS protocol.
Service workers require secure origins to ensure that the service worker script is from the intended origin and hasn’t come about from a man-in-the-middle attack. That means using HTTPS on live sites. You do not need to spend a fortune for the SSL certificate--there are some cheap options available. For example, Namecheap offers domain-level SSL certificates starting from $9.00/yr. Please note a dedicated IP is also highly recommended.
Beyond the Web Push notifications going HTTPS is a good thing: Google has announced that it will give you a ranking boost (more info here).
- Chrome 50 and later.
- Firefox 46 and later.
- Edge from Windows 10 April 2018 Update and later.
- Opera mobile version 37 and later, desktop version 42 and later.
Please note all Web Push users will be anonymous (info here).
Moreover, web push notifications are not supported in private browsing mode.
Licensing
Please note you can only download Push Notifications for WordPress if you have an active subscription. Hence, please download your updates as they come out.
Troubleshooting
Sorry, this file type is not permitted for security reasons
while uploading the P12 file?In short, to send in the background push notifications, we use the WordPress standard function wp_schedule_single_event()
. We have verified that it does not work properly if:
- Your hosting is blocking the call to
fsockopen()
. WordPress uses thefsockopen
PHP function to make a request to thewp-cron.php
file that's located in the WordPress installation directory. - You are using CloudFlare or a caching plugin which does not trigger the WP Cron.
- Your server is unable to resolve itself.
Our advice is to contact your hosting provider.
To debug, you can force to run a cron job by launching:
$ wget --delete-after http://yourwebsite/wp-cron.php
or
$ wget --delete-after http://yourwebsite/wp-cron.php?doing_wp_cron
We also recommend you to install a plugin like WP Crontrol. Then go to the Tools → Cron Events menu and search for the event pnfw_send_notifications_for_post_in_background
. If it is present it's a warning: it means that WP Cron is not configured correctly and has not been able to to consume the event properly. Click on the button Run Now and see what happens.
FCM didn't return a 200 or 503 status
?This can be caused by:
- The fact that cURL is not installed on your server.
- The fact that Push Notifications for WordPress can't reach the URL
https://fcm.googleapis.com/fcm/send
. - The fact that cURL is unable to verify the certificate provided by the server. You should properly add the root CA in the CA store directory of your machine.
You can do a simple test by launching this command on your server:
curl --header "Authorization: key=xxx" --header Content-Type:"application/json" https://fcm.googleapis.com/fcm/send -d "{\"registration_ids\":[\"ABC\"]}"
Please change xxx
with your Google API Key.
If you are using Apache with mod_fcgid
, likely the FcgidIOTimeout
is too low (the default timeout for FastCGI scripts is 45 seconds).
If you are using a VPS with WHM installed you can change it in this way:
- Login to WHM → Apache Configuration → Include Editor → Post VirtualHost Include → All
- Copy and paste following code:
<IfModule mod_fcgid.c>
FcgidIOTimeout 360
</IfModule>
- Restart Apache.
401 Unauthorized : "oauth_consumer_key parameter is missing"
?- By disabling OAuth under Push Notifications → OAuth.
- By passing the required parameters (info here).
Please note: if you just did a migration of your site to HTTPS, you should accept signed requests for both HTTP and HTTPS. Go to: Push Notifications → OAuth, and enable "Accept both HTTP and HTTPS requests".
401 Invalid HTTP method
. What should I do?POST
HTTP method (e.g. the Register API) and other using the GET
HTTP method (e.g. the Posts API list). More info here.
If you are sure you have used the correct HTTP method be sure to check the settings of your web server. In particular, some users have reported that nginx has different URL mapping rules than Apache (see above).
You can debug with cURL using this command:
$ curl https://yourwebsite.com/pnfw/register/ -i --data "os=Android&token=aa"
Server-side, you can set a post as read using the Posts API (details): "When this API is called, the post is considered "read" by this specific device token–and consequently by the corresponding user. Therefore, the statistics and the badge on iOS are updated."
Client-side, when a user read a post it's up to you to decrease it using the UIApplication
's applicationIconBadgeNumber
property.
In general, if a plugin says network activate then do so. If it does not, then don't.
http://yoursite/pnfw/register/
?To fix this, follow these steps:
- Log in to your WordPress site as an administrator.
- Go to Settings → General.
- Change the timezone dropdown to a city that’s in your timezone.
- Click the Save Changes button at the bottom of the screen.
- Log in to your WordPress site as an administrator.
- Go to Plugins → Installed Plugins.
- Press on Deactivate under Push Notifications for WordPress.
- Press on Activate under Push Notifications for WordPress.
- Reenter the license data under Push Notifications → License.
- Open the Settings app.
- Choose Apps (on some Samsung phones, touch the General tab atop the Settings app screen, and then choose the Application Manager item).
- Choose the app that’s causing problems.
- Make sure the Force Stop button is not grayed out. If it's the case open your application almost once to exit this state.
Please note that some security applications try to force stop state at startup so you have to whitelist them.
If you develop with Android Studio you must be warned that running applications with debugger leaves them in a forced stop state.
With the Notification message Firebase automatically displays the message to end-user devices on behalf of the client app. With the Data message client app is responsible for processing data messages.
More info in the official FCM documentation.
You can enable Notification messages in the Settings → Android → Firebase enabling Use the Notification message instead of the Data message
Migration
Follow these steps:
- Make sure the setting "Remove data on uninstall" is unchecked.
- Upload Push Notification for WordPress without activating it.
- Disable Push Notification for WordPress (Lite).
- Activate Push Notification for WordPress.
- Uninstall Push Notification for Posts (Lite).
That's all! Enjoy all the advanced features of Push Notification for WordPress!
Follow these steps:
- Backup your WordPress database as explained here.
- Upgrade Push Notification for Posts to version 2.0 or later without uninstalling previous version (very important: previous versions, when uninstalled, would remove all subscribers and tokens).
- Make sure the setting "Remove data on uninstall" is unchecked.
- Upload Push Notification for WordPress without activating it.
- Disable Push Notification for Posts.
- Activate Push Notification for WordPress.
- Uninstall Push Notification for Posts.
That's all! Enjoy all the advanced features of Push Notification for WordPress!
The following are some ideas to proceed in a different way, but the implementation is left to you (our team does not offer support):
- Go to the Push Notifications → Tokens and click on the Export CSV button. This will download a file with all the tokens plus some information about each of them.
- For each of these tokens, make a cURL call like this:
$ curl https://yoursite/pnfw/register/ --data "os=xxx&token=yyy&lang=zzz"
Note that in this way a new user for each token will be created, thus losing its past history.
Other
Here are some tips:
- Make sure that Push Notifications for WordPress is updated to the latest version.
- Speed up the APIs as shown in the next FAQ.
- Replace the WordPress Cron with a real cron job (tutorial).
- Reduce the size of some tables that may have grown too much. First, make a backup copy of the tables
wp_push_sent
,wp_push_viewed
, andwp_push_logs
. Then run these SQL commands:TRUNCATE TABLE wp_push_sent;
TRUNCATE TABLE wp_push_viewed;
TRUNCATE TABLE wp_push_logs;OPTIMIZE TABLE wp_push_sent;
OPTIMIZE TABLE wp_push_viewed;
OPTIMIZE TABLE wp_push_logs;Please note: in your case the prefix
wp_
could be different. - Consider moving to a more performing hosting.
In general our advice is not to send too many notifications a day. If you send many notifications a day, the previous ones may not be finished, and therefore overlap, causing a double (or triple) load on the server!
Luckily there are some great solutions, such as the one described here. Please remember to whitelist:
- Push Notifications for WordPress.
- Its add-ons (App Only Post Type, Merge Push Notifications) you are eventually using.
- WPML.
- The plugins of which your are using the shortcodes.
- The plugins you have developed that implement its hooks.