Skip to content

Copy-Paste Snippets

Use this page as a quick snippet bank during implementation.

<?php
add_action('notificator_companion_register_templates', function () {
if (!function_exists('notificator_companion_register_template')) {
return;
}
notificator_companion_register_template(array(
'icon' => 'dashicons-admin-generic',
'title' => 'My Plugin: Event',
'hook_name' => 'my_plugin_event',
'description' => 'Fires when my plugin event runs',
'scenario_name' => 'My Plugin Event',
'required_plugin' => 'my-plugin-slug',
'hook_meta' => array(
'label' => 'My plugin event',
'type' => 'action',
'arg_names' => array('user_id'),
'payload_arity' => 1,
),
));
});

Whitelist custom plugin slug for template visibility

Section titled “Whitelist custom plugin slug for template visibility”
<?php
add_filter('notificator_companion_active_plugin_identifiers', function ($ids) {
$ids[] = 'my-plugin-slug';
return $ids;
});
<?php
do_action('my_plugin_order_created', $order_id, $user_id, $amount);
<?php
$value = apply_filters('my_plugin_before_export', $value, $context);
<?php
$monitor = UptimeMonitor::get_instance();
$result = $monitor->send_monitoring_check();
if ($result) {
echo 'Monitoring check sent successfully';
}
Terminal window
curl -X POST "https://api.notificator-project.com" \
-H "Authorization: Bearer wpnotif_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Queue Backlog High",
"body": "Order queue is above threshold.",
"source": "erp_worker",
"serviceName": "ERP Worker",
"eventName": "QueueBacklogHigh",
"category": "task",
"severity": "warning"
}'

Public notify troubleshooting quick checks

Section titled “Public notify troubleshooting quick checks”
  • 401 + Invalid API key: verify header value and that the key is not revoked.
  • 401 + key type error: use public_client or internal_service.
  • 401 + origin error: match Origin/Referer to key allowed_domains.
  • 400 empty payload: include at least one meaningful field (for example title or payload).
<?php
$timestamp = (string) (int) round(microtime(true) * 1000);
$signature = hash_hmac('sha256', $timestamp . $body, $api_key);
$headers = array(
'Authorization' => 'Bearer ' . $api_key,
'Content-Type' => 'application/json',
'Origin' => rtrim(home_url(), '/'),
'Referer' => rtrim(home_url(), '/') . '/',
'X-Timestamp' => $timestamp,
'X-Signature' => $signature,
);