rollbar / rollbar-php-wordpress

Official WordPress plugin from Rollbar, Inc.
https://rollbar.com/
GNU General Public License v2.0
15 stars 20 forks source link

ROLLBAR_ACCESS_TOKEN cannot be set programmatically #72

Closed rkaiser0324 closed 5 years ago

rkaiser0324 commented 5 years ago

Might be related to, or a dupe of, https://github.com/rollbar/rollbar-php-wordpress/issues/41. Looks like this is either a bug in the way the plugin uses the Rollbar PHP library.

In vendor\rollbar\rollbar\src\Config.php::setAccessToken() you have

      if (isset($_ENV['ROLLBAR_ACCESS_TOKEN']) && !isset($config['access_token'])) {
            $config['access_token'] = $_ENV['ROLLBAR_ACCESS_TOKEN'];
        }

but in practice, $config['access_token'] is always set by the plugin, although it might be "". Thus you're unable to use $_ENV to set the token.

You can change this to

      if (!empty($_ENV['ROLLBAR_ACCESS_TOKEN'])) {
            $config['access_token'] = $_ENV['ROLLBAR_ACCESS_TOKEN'];
        }

but it might be safer to change the logic upstream in the plugin. I would also note that a more common WordPress pattern is to define strings like these in wp-config.php, rather than using $_ENV, so having the plugin support something like

define('ROLLBAR_ACCESS_TOKEN', '...');

would be ideal.

jessewgibbs commented 5 years ago

@rkaiser0324 thanks for bringing this to our attention.

@ArturMoczulski can you investigate when you get a chance?

ArturMoczulski commented 5 years ago

This has been implemented in master and released in 2.4.10

The plugin should respect both ROLLBAR_ACCESS_TOKEN environment variable and a constant with the same name.

The docs have been updated: https://docs.rollbar.com/docs/wordpress#section-setting-the-access-token-in-your-source-code-or-server-configuration