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

add filter for Rollbar JS config #29

Closed jluxenberg closed 6 years ago

jluxenberg commented 6 years ago

Allows a plugin to modify the JS config passed to Rollbar.

You can use this e.g. to add the currently logged in user to the "person" field of the payload. With this change, you could have this plugin:

class RollbarWPUser {
  public function __construct(){
    add_filter( 'rollbar_js_config', array($this, 'rollbar_js_config') );
  }

  function rollbar_js_config($config) {
    if(is_user_logged_in()) {
      $user = wp_get_current_user();  

      if(empty($config['payload']['person'])) {
        $config['payload']['person'] = array(
          'id' => $user->ID,
          'username' => $user->user_login,
          'email' => $user->user_email
        );
      }
    }

    return $config;
  }
}
ArturMoczulski commented 6 years ago

This is a great idea @jluxenberg Thanks for the PR

We need to make a test for this as well.

therealgilles commented 3 years ago

I know this is old, but a couple quick thoughts: 1) The rollbar_js_config function should probably be declared as public. 2) It may be good to make it clear that a RollbarWPUser object needs to be created for the filter to be set.