The Userback plugin for WordPress allows you to gather feedback from all of your WordPress pages, including specific or draft pages.
You won't need to install any code.
Install the plugin
Go to Feedback > Settings > Widget > Install and select the WordPress tile to get your access token.
In your WordPress admin, install and activate the Userback plugin from the plugin repository.
Open the plugin's Userback settings menu and paste in your access token.
Choose which pages the widget should appear on, for example, all pages or all draft pages.
Check Enable Userback and click Save.
Identify logged-in users
To link submissions from WordPress to a real member instead of an anonymous visitor, add the following snippet to your theme (typically footer.php)
<?php if ( is_user_logged_in() ) { ?>
<script>
<?php $current_user = wp_get_current_user(); ?>
Userback.user_data = {
id: <?php echo ''.$current_user->ID;?>,
info: {
username: '<?php echo ''.$current_user->user_login;?>',
email: '<?php echo ''.$current_user->user_email;?>',
name: '<?php echo ''.$current_user->user_firstname;?> <?php echo ''.$current_user->user_lastname;?>',
display_name: '<?php echo ''.$current_user->display_name;?>',
}
};
</script>
<?php } ?>
This will pass the logged-in user's data to Userback
Alternatively hook into WordPress's wp_login action to call Userback.identify() dynamically once someone logs in with this code:
// Example callback for WP login hook
function example_log_user_login( $user_login, $user ) {
$current_user = wp_get_current_user();
?>
<script>
window.Userback = window.Userback || {};
Userback.identify(
<?php echo $current_user->ID; ?>,
{
username: "<?php echo $current_user->user_login; ?>",
email: "<?php echo $current_user->user_email; ?>",
name: "<?php echo $current_user->user_firstname . ' ' . $current_user->user_lastname; ?>",
display_name: "<?php echo $current_user->display_name; ?>"
}
);
</script>
<?php
}
// Hook into WordPress login
add_action(
'wp_login', // Triggered when a user logs in
'example_log_user_login', // Our callback function
10, // Priority (default 10; lower = earlier)
2 // Number of arguments passed to the callback ($user_login, $user)
);
See How to Identify Users for what identify() expects.
Test this by logging in and submitting a piece of feedback and verify the user details were submitted along with the feedback.
Note: This section is purely an example of how to use Userback.identify after login. Replace example_log_user_login with your own function name if needed.
