# WordPress updates available notifications on your phone

> Get a push notification when WordPress core, plugin or theme updates are waiting, once per new set of updates.

- Company: WordPress (https://www.justpush.io/recipes/wordpress)
- Event: `updates.available` (Updates available)
- Tags: Websites, Monitoring
- Install: https://studio.justpush.io/recipes/wordpress/updates-available
- Web page: https://www.justpush.io/recipes/wordpress/updates-available

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. Copy the PHP snippet from the setup notes below. It already contains your endpoint URL.
3. Save it as a new .php file in wp-content/mu-plugins/ on your site (create the folder if it doesn't exist).
4. WordPress loads it automatically. Trigger a Updates available to test.
5. WordPress doesn't send webhooks by itself, so this recipe comes with a small **must-use plugin**. Save the code below as `wp-content/mu-plugins/justpush-updates-available.php` (create the `mu-plugins` folder if it doesn't exist). WordPress loads files there automatically; there's nothing to activate.
6. ```php
7. <?php
8. /**
9. Plugin Name: JustPush — Updates available
10. Description: Sends a push through JustPush Studio when WordPress, plugin or theme updates are available.
11. */
12. // Check twice a day (WordPress already looks for updates on its own schedule), and only
13. // push when the list of available updates has changed since the last push.
14. add_action('justpush_check_updates', function () {
15. require_once ABSPATH . 'wp-admin/includes/plugin.php';
16. require_once ABSPATH . 'wp-admin/includes/update.php';
17. $items = array();
18. foreach ((array) get_core_updates() as $update) {
19. if (isset($update->response) && $update->response === 'upgrade') {
20. $items[] = 'WordPress ' . $update->current;
21. }
22. }
23. foreach (get_plugin_updates() as $plugin) {
24. $items[] = $plugin->Name . ' ' . $plugin->update->new_version;
25. }
26. foreach (get_theme_updates() as $theme) {
27. $items[] = $theme->get('Name') . ' ' . $theme->update['new_version'];
28. }
29. // Nothing waiting: forget what we sent, so the next update pushes again.
30. if (!$items) {
31. delete_option('justpush_updates_sent');
32. return;
33. }
34. $fingerprint = md5(implode('|', $items));
35. if (get_option('justpush_updates_sent') === $fingerprint) {
36. return;
37. }
38. update_option('justpush_updates_sent', $fingerprint, false);
39. wp_remote_post('your webhook URL (shown in Studio after install)', array(
40. 'blocking' => false, // don't slow the page down waiting for JustPush
41. 'timeout'  => 3,
42. 'headers'  => array('Content-Type' => 'application/json'),
43. 'body'     => wp_json_encode(array(
44. 'event' => 'updates.available',
45. 'site'  => get_bloginfo('name'),
46. 'items' => $items,
47. 'url'   => admin_url('update-core.php'),
48. )),
49. ));
50. });
51. add_action('init', function () {
52. if (!wp_next_scheduled('justpush_check_updates')) {
53. wp_schedule_event(time() + 60, 'twicedaily', 'justpush_check_updates');
54. }
55. });
56. ```
57. The check runs on WP-Cron, which needs visits to your site to trigger. If you remove the file later, the scheduled `justpush_check_updates` event stays behind but does nothing.
58. To stop the notifications, delete the file.

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// WordPress → updates available
// Fires when the "JustPush — Updates available" mu-plugin (see INSTALL.md) reports a
// "updates.available" event. WordPress has no webhooks of its own, so the snippet sends them.

// The snippet sends plain strings; treat blanks as missing.
function text(value) {
    return typeof value === "string" && value.trim() ? value.trim() : null
}

// Only link to real http(s) URLs.
function link(url, cta) {
    return typeof url === "string" && /^https?:\/\//.test(url) ? [{ cta, url }] : []
}

function handleRequest(request) {
    const event = request.body

    // Guard: only handle this recipe's event, so other snippets on this integration stay quiet.
    if (event?.event !== "updates.available") {
        console.log(`Ignoring WordPress event "${event?.event ?? "unknown"}"`)
        return null
    }

    const items = Array.isArray(event.items) ? event.items.map(text).filter(Boolean) : []

    if (!items.length) {
        console.log("Update check without any updates — skipping")
        return null
    }

    // Name the first few; a long list doesn't fit a notification.
    const shown = items.slice(0, 3).join(", ")
    const more = items.length > 3 ? ` and ${items.length - 3} more` : ""
    const site = text(event.site) ?? "Your site"

    return {
        title: `🔄 ${items.length} update${items.length === 1 ? "" : "s"} available`,
        message: `${site}: ${shown}${more}`,
        topic: "WordPress",
        priority: 0, // Normal — updates often carry security fixes, but can wait a few hours
        buttons: link(event.url, "Open updates"),
    }
}
```

## WordPress updates.available webhook payload (sample)

```json
{
  "url": "https://example.com/wp-admin/update-core.php",
  "site": "My Site",
  "event": "updates.available",
  "items": [
    "WordPress 6.8.3",
    "Akismet Anti-spam 5.5",
    "Yoast SEO 26.1",
    "Twenty Twenty-Five 1.4"
  ]
}
```

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into WordPress and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
