Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions main.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
add_action('wp_enqueue_script', 'load_jquery');
add_action('plugins_loaded', 'rg4wp_checkUser');

function rg4wp_version(): string {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a defensive (string) cast on the constant value?

define() accepts any scalar, so someone writing define('RAYGUN_VERSION', 1.0) or define('RAYGUN_VERSION', 2) would probably trigger a TypeError here.

Suggested change:

function rg4wp_version(): string {
    static $version = null;
    if ($version === null) {
        $version = defined('RAYGUN_VERSION') ? (string) RAYGUN_VERSION : get_bloginfo('version');
    }
    return $version;
}

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);
Expand Down Expand Up @@ -79,7 +87,7 @@ function rg4wp_js() {
}

$script .= '</script>';
printf($script, get_option('rg4wp_apikey'), get_bloginfo('version'));
printf($script, get_option('rg4wp_apikey'), rg4wp_version());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above for context

If you append it to the script code after encoding it, then this line would become:

printf($script, get_option('rg4wp_apikey'));

}

if (
Expand All @@ -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)) {
Expand Down Expand Up @@ -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']);
Expand Down