WP Manifestindependent plugin directory
manifest / integrations / onesignal-custom-notify-api

OneSignal Notify API Custom

A WordPress plugin that extends OneSignal functionality with a custom REST API to send notifications and manage user notification history within a local WordPress database.

by A.DEV · github.com/srivastava-abhigyan/onesignal-custom-notify-api

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/srivastava-abhigyan/onesignal-custom-notify-api/archive/refs/heads/main.zip

OneSignal Custom Notify API (WordPress Plugin)

A professional WordPress plugin that provides a custom REST API to send OneSignal notifications and manage user notification history within a local database.

🚀 Overview

This plugin bridges the gap between WordPress and OneSignal by allowing you to send push notifications via a custom REST API endpoint and store those notifications in your WordPress database. This allows users to view their notification history even if they missed the push message.

✨ Features

  • Custom REST API Endpoints:
    • POST /wp-json/osna/v1/notify: Send notifications to users.
    • GET /wp-json/osna/v1/notifications: Fetch notification history for the logged-in user.
    • POST /wp-json/osna/v1/notifications/{id}/read: Mark notifications as read.
  • Local History Tracking: Automatically saves sent notifications to a custom database table (wp_user_notifications).
  • User-Specific Filtering: Supports fetching notifications based on the logged-in user's ID.
  • OneSignal Integration: Seamlessly connects with the OneSignal API for mobile and web push.

📋 Prerequisites

To use this plugin, ensure you have the following installed and configured:

  1. OneSignal Free Web Push Notifications
  2. JWT Authentication for WP REST API

🛠️ Installation

  1. Download the repository as a ZIP file.
  2. Upload the plugin to your WordPress site via Plugins > Add New > Upload Plugin.
  3. Activate the plugin.
  4. The plugin will automatically create the required database table upon activation.

⚙️ Configuration

Open onesignal_custom_notify.php and update the following lines with your OneSignal credentials:

$app_id = 'YOUR_ONESIGNAL_APP_ID';
$api_key = 'YOUR_ONESIGNAL_REST_API_KEY';

📡 API Usage

1. Send a Notification

Endpoint: POST /wp-json/osna/v1/notify
Authentication: Required (JWT or Session)

Request Body (JSON):

{
    "title": "New Update",
    "message": "Check out our latest post!",
    "link": "https://example.com/post-url",
    "user_id": 123
}

2. Fetch User Notifications

Endpoint: GET /wp-json/osna/v1/notifications
Authentication: Required

Response:

[
    {
        "ID": "1",
        "user_id": "123",
        "title": "New Update",
        "message": "Check out our latest post!",
        "link": "https://example.com/post-url",
        "read_status": "0",
        "created_at": "2023-10-27 10:00:00"
    }
]

3. Mark as Read

Endpoint: POST /wp-json/osna/v1/notifications/{id}/read
Authentication: Required

🛡️ Security

This plugin uses permission_callback for all REST API routes to ensure that only authenticated and authorized users can access the endpoints.

📄 License

This project is open-source and available under the MIT License.