Skip to content

Instantly share code, notes, and snippets.

@mostafasoufi
Created March 3, 2024 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostafasoufi/83665af548f20e46f15d2b2bfc76662e to your computer and use it in GitHub Desktop.
Save mostafasoufi/83665af548f20e46f15d2b2bfc76662e to your computer and use it in GitHub Desktop.
Show FeedbackBird widget in the WordPress admin area
add_action('admin_enqueue_scripts', function () {
wp_enqueue_script('feedbackbird-app-script', 'https://cdn.jsdelivr.net/gh/feedbackbird/assets@master/wp/app.js?uid=YOUR_UID');
wp_add_inline_script('feedbackbird-app-script', sprintf('var feedbackBirdObject = %s;', json_encode([
'user_email' => function_exists('wp_get_current_user') ? wp_get_current_user()->user_email : '',
'platform' => 'wordpress-admin',
'meta' => [
'php_version' => PHP_VERSION,
'active_plugins' => array_map(function ($plugin, $pluginPath) {
return [
'name' => $plugin['Name'],
'version' => $plugin['Version'],
'status' => is_plugin_active($pluginPath) ? 'active' : 'deactivate',
];
}, get_plugins(), array_keys(get_plugins())),
]
])));
add_filter('script_loader_tag', function ($tag, $handle, $src) {
if ('feedbackbird-app-script' === $handle) {
return preg_replace('/^<script /i', '<script type="module" crossorigin="crossorigin" ', $tag);
}
return $tag;
}, 10, 3);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment