WP Manifestindependent plugin directory
manifest / analytics / rah-plugin-monitor

RAH Plugin Monitor

Displays WordPress.org public statistics for approved plugins.

by Your Name · github.com/ridhwanahsan/rah-plugin-monitor

★ 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/ridhwanahsan/rah-plugin-monitor/archive/refs/heads/main.zip

RAH Plugin Monitor (Server-Side)

This plugin acts as the central server to monitor statistics for your WordPress.org plugins and track real-time activations from your distributed plugins.

Features

  • Dashboard Widget: View key metrics for multiple plugins in a clean, modern card layout.
  • Real-time Data: Fetches data directly from the WordPress.org Plugin API.
  • Real-time Activations: Tracks installations of your own plugins via a secure API.
  • Performance Optimized: API responses are cached for 12 hours.
  • Privacy Focused: No tracking, no external data collection, no telemetry.

Installation (Server Side)

Where to install: Install this plugin ONLY on your own website (e.g., portal-application.com).

  1. Upload the rah-plugin-monitor folder to the /wp-content/plugins/ directory.
  2. Activate the plugin through the 'Plugins' menu.
  3. Go to the "RAH Monitor" menu in your admin dashboard.
  4. Enter the slugs of the plugins you want to monitor in the settings.

Integration Guide for Client Plugins

To track installations of your other plugins (e.g., grt-booking, grt-ticket), you need to add the following code to THEIR main plugin files.

Where to add: Inside the main PHP file of the plugin you want to track (the file with the Plugin Name: header).

Step 1: Add the Remote Connector Class

Copy and paste this class at the bottom of your client plugin's main file.

/**
 * RAH Telemetry Connector
 * Adds secure connection to your central monitoring server.
 */
if ( ! class_exists( 'MyPlugin_Remote_Connector' ) ) {
    class MyPlugin_Remote_Connector {
        // This is your RAH Monitor Server URL
        private $api_endpoint = 'https://portal-application.com/monitor/wp-json/rah-monitor/v1/api';

        public function send_payload( $action, $data = array() ) {
            // Check for user consent (REQUIRED for WP.org compliance)
            // You should provide an option/checkbox in your plugin settings for this.
            if ( ! get_option( 'myplugin_allow_connection', false ) ) {
                return false;
            }

            $payload = array_merge( array(
                'site_url'       => get_site_url(),
                'plugin_version' => MYPLUGIN_VERSION, // Ensure this constant is defined in your plugin
                'wp_version'     => get_bloginfo( 'version' ),
                'php_version'    => phpversion(),
                'action_type'    => sanitize_key( $action ),
                'timestamp'      => current_time( 'mysql' ),
                'admin_email'    => get_option( 'admin_email' ),
            ), $data );

            wp_remote_post( $this->api_endpoint, array(
                'blocking'    => false,
                'headers'     => array( 'Content-Type' => 'application/json' ),
                'body'        => wp_json_encode( $payload ),
                'data_format' => 'body',
            ) );
        }
    }
}

Step 2: Add the Event Listener Class

Paste this class right after the previous one. It handles activation, deactivation, and updates.

if ( ! class_exists( 'MyPlugin_Event_Listener' ) ) {
    class MyPlugin_Event_Listener {
        private $connector;

        public function __construct() {
            $this->connector = new MyPlugin_Remote_Connector();

            // Hooks
            register_activation_hook( __FILE__, array( $this, 'on_activate' ) );
            register_deactivation_hook( __FILE__, array( $this, 'on_deactivate' ) );
            add_action( 'admin_init', array( $this, 'check_version' ) );
        }

        public function on_activate() {
            // Send activation signal
            $this->connector->send_payload( 'connect' );
        }

        public function on_deactivate() {
            $this->connector->send_payload( 'disconnect' );
        }

        public function check_version() {
            $saved = get_option( 'myplugin_version' );
            if ( version_compare( MYPLUGIN_VERSION, $saved, '>' ) ) {
                $this->connector->send_payload( 'update', array( 'prev_ver' => $saved ) );
                update_option( 'myplugin_version', MYPLUGIN_VERSION );
            }
        }
    }
}

Step 3: Initialize the Tracker

Finally, add this code at the end of your main plugin file to start the tracking system.

// 1. Define your plugin version constant (if not already defined)
if ( ! defined( 'MYPLUGIN_VERSION' ) ) {
    define( 'MYPLUGIN_VERSION', '1.0.0' ); // Update this with your plugin's version
}

// 2. Initialize the Event Listener
add_action( 'plugins_loaded', function() {
    if ( class_exists( 'MyPlugin_Event_Listener' ) ) {
        new MyPlugin_Event_Listener();
    }
} );

Summary

  • Server Plugin (rah-plugin-monitor): Installs on your main site to receive data.
  • Client Code: Goes into your distributed plugins (grt-booking, etc.) to send data.