@@ -20,19 +20,20 @@ class Admin {
20
20
* Admin constructor.
21
21
*/
22
22
public function __construct () {
23
- $ this ->setup_otter_notice ();
23
+ $ this ->setup_admin_hooks ();
24
24
}
25
25
26
26
27
27
/**
28
- * Setup the Otter Blocks notice .
28
+ * Setup admin hooks .
29
29
*
30
30
* @return void
31
31
*/
32
- public function setup_otter_notice () {
32
+ public function setup_admin_hooks () {
33
33
add_action ( 'admin_notices ' , array ( $ this , 'render_welcome_notice ' ), 0 );
34
34
add_action ( 'wp_ajax_fork_dismiss_welcome_notice ' , array ( $ this , 'remove_welcome_notice ' ) );
35
35
add_action ( 'wp_ajax_fork_set_otter_ref ' , array ( $ this , 'set_otter_ref ' ) );
36
+ add_action ( 'admin_print_scripts ' , array ( $ this , 'add_nps_form ' ) );
36
37
}
37
38
38
39
/**
@@ -230,4 +231,52 @@ private function get_otter_status(): string {
230
231
231
232
return $ status ;
232
233
}
234
+
235
+ /**
236
+ * Add NPS form.
237
+ *
238
+ * @return void
239
+ */
240
+ public function add_nps_form () {
241
+ $ screen = get_current_screen ();
242
+
243
+ if ( current_user_can ( 'manage_options ' ) && ( 'dashboard ' === $ screen ->id || 'themes ' === $ screen ->id ) ) {
244
+ $ website_url = preg_replace ( '/[^a-zA-Z0-9]+/ ' , '' , get_site_url () );
245
+
246
+ $ config = array (
247
+ 'environmentId ' => 'clr7hsvmjeu0u8up04ydg210b ' ,
248
+ 'apiHost ' => 'https://app.formbricks.com ' ,
249
+ 'userId ' => 'fork_ ' . $ website_url ,
250
+ 'attributes ' => array (
251
+ 'days_since_install ' => self ::convert_to_category ( round ( ( time () - get_option ( 'fork_install ' , 0 ) ) / DAY_IN_SECONDS ) ),
252
+ ),
253
+ );
254
+
255
+ echo '<script type="text/javascript">!function(){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src="https://unpkg.com/@formbricks/js@^1.2.0/dist/index.umd.js";var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e),setTimeout(function(){window.formbricks.init( ' . wp_json_encode ( $ config ) . ')},500)}();</script> ' ;
256
+ }
257
+ }
258
+
259
+ /**
260
+ * Convert a number to a category.
261
+ *
262
+ * @param int $number Number to convert.
263
+ * @param int $scale Scale.
264
+ *
265
+ * @return int
266
+ */
267
+ public static function convert_to_category ( $ number , $ scale = 1 ) {
268
+ $ normalized_number = intval ( round ( $ number / $ scale ) );
269
+
270
+ if ( 0 === $ normalized_number || 1 === $ normalized_number ) {
271
+ return 0 ;
272
+ } elseif ( $ normalized_number > 1 && $ normalized_number < 8 ) {
273
+ return 7 ;
274
+ } elseif ( $ normalized_number >= 8 && $ normalized_number < 31 ) {
275
+ return 30 ;
276
+ } elseif ( $ normalized_number > 30 && $ normalized_number < 90 ) {
277
+ return 90 ;
278
+ } elseif ( $ normalized_number > 90 ) {
279
+ return 91 ;
280
+ }
281
+ }
233
282
}
0 commit comments