diff --git a/README.md b/README.md index e18cabe..1e0be40 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,18 @@ As of 2.0.0, errors that fail to send to Raygun will be logged to the standard W As of 2.1.0, you can now ignore 3rd-party errors from being sent to Raygun. You can enable this option via the plugin settings. +## Custom Version + +By default, Raygun will send the current WordPress core version as the version for your app. If you wish to send something different as your app version (for example, your deployment ID), set the `RAYGUN_VERSION` global constant. + +Set this constant as early as possible (e.g. in `wp-config.php`, and not in a plugin or theme), to ensure all PHP and JS errors throughout the lifecycle of a request report the same version number. + +For example: + +```php +define('RAYGUN_VERSION', '1.0.0.0'); +``` + --------- Changelog diff --git a/main.php b/main.php index 906f3c7..79e6a44 100644 --- a/main.php +++ b/main.php @@ -14,6 +14,14 @@ add_action('wp_enqueue_script', 'load_jquery'); add_action('plugins_loaded', 'rg4wp_checkUser'); +function rg4wp_version(): string { + static $version = null; + if ($version === null) { + $version = defined('RAYGUN_VERSION') ? RAYGUN_VERSION : get_bloginfo('version'); + } + return $version; +} + function rg4wp_isIgnoredDomain(): bool { $domains = array_map('trim', explode(',', get_option('rg4wp_ignoredomains', ''))); return array_key_exists('SERVER_NAME', $_SERVER) && in_array($_SERVER['SERVER_NAME'], $domains); @@ -79,7 +87,7 @@ function rg4wp_js() { } $script .= ''; - printf($script, get_option('rg4wp_apikey'), get_bloginfo('version')); + printf($script, get_option('rg4wp_apikey'), rg4wp_version()); } if ( @@ -88,7 +96,7 @@ function rg4wp_js() { && get_option('rg4wp_apikey') && !(1 == get_option('rg4wp_noadmintracking', 0) && is_admin()) ) { - RaygunClientManager::getInstance()->SetVersion(get_bloginfo('version')); + RaygunClientManager::getInstance()->SetVersion(rg4wp_version()); function getErrorTag(int $errno): string { if (!array_key_exists($errno, ERROR_CONSTANTS)) { @@ -173,7 +181,7 @@ function rg4wp_404_handler() { && !(1 == get_option('rg4wp_noadmintracking', 0) && is_admin()) ) { rg4wp_checkUser(); - RaygunClientManager::getInstance()->SetVersion(get_bloginfo('version')); + RaygunClientManager::getInstance()->SetVersion(rg4wp_version()); $uri = $_SERVER['REQUEST_URI']; $tags = array_map('trim', explode(',', get_option('rg4wp_tags'))); $tags = array_merge($tags, ['404-error']);