DocsoPWAWP-CLI, REST API & Developer Hooks
Developer

WP-CLI, REST API & Developer Hooks

oPWAorravo.com/docs/opwa/cli-rest-hooks

WP-CLI Commands

bash# Show PWA status (HTTPS, manifest, SW, VAPID)
wp opwa status

# Generate VAPID key pair
wp opwa vapid generate

# Send a push notification to all subscribers
wp opwa push send --title="Hello" --body="World" --url="https://example.com"

# List all push subscribers
wp opwa subscribers list

# Clear all subscribers
wp opwa subscribers clear

# Rebuild service worker cache config
wp opwa sw rebuild

REST API Endpoints

MethodEndpointAuthDescription
GET/wp-json/opwa/v1/manifestNoneWeb App Manifest JSON
POST/wp-json/opwa/v1/push/subscribeNoneSubscribe to push
DELETE/wp-json/opwa/v1/push/subscribeNoneUnsubscribe
POST/wp-json/opwa/v1/analytics/beaconNoneSend analytics beacon
GET/wp-json/opwa/v1/sw-configNoneSW config for dynamic SW

Developer Filters

php// Modify the manifest before output
add_filter( 'opwa_manifest', function( array $manifest ): array {
    $manifest['categories'] = ['news', 'productivity'];
    return $manifest;
} );

// Modify service worker config
add_filter( 'opwa_sw_config', function( array $config ): array {
    $config['custom_routes'][] = [
        'pattern'  => '/api/*',
        'strategy' => 'network-only',
    ];
    return $config;
} );

// Extend precache URL list
add_filter( 'opwa_precache_urls', function( array $urls ): array {
    $urls[] = '/offline-page/';
    return $urls;
} );

// Modify push payload before send
add_filter( 'opwa_push_payload', function( array $payload, string $endpoint ): array {
    return $payload;
}, 10, 2 );

Developer Actions

phpadd_action( 'opwa_push_sent',           function( int $campaign_id, int $count ) {} );
add_action( 'opwa_subscriber_added',    function( string $endpoint ) {} );
add_action( 'opwa_subscriber_removed',  function( string $endpoint ) {} );
add_action( 'opwa_sw_registered',       function() {} );
WP-CLI, REST API & Developer Hooks — oPWA Docs — Orravo