Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add filter for Rollbar JS config #29

Merged

Conversation

jluxenberg
Copy link

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;
  }
}

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.
@ArturMoczulski
Copy link

This is a great idea @jluxenberg Thanks for the PR

We need to make a test for this as well.

@ArturMoczulski ArturMoczulski merged commit e70ba22 into rollbar:master Nov 8, 2017
@therealgilles
Copy link

therealgilles commented Jun 2, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants