Skip to content

Commit 5473b53

Browse files
feat: load survey vis internal pages hooks
1 parent 7446c0a commit 5473b53

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

.github/workflows/test-php.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ name: Test PHP
33
on:
44
push:
55
branches-ignore:
6-
- 'master'
6+
- "master"
77

88
jobs:
99
phplint:
1010
name: Phplint
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1212
steps:
1313
- name: Setup PHP version
1414
uses: shivammathur/setup-php@v2
1515
with:
16-
php-version: '7.2'
16+
php-version: "7.2"
1717
extensions: simplexml
1818
- name: Checkout source code
1919
uses: actions/checkout@v2
@@ -34,7 +34,7 @@ jobs:
3434
run: composer run lint
3535
phpunit:
3636
name: Phpunit
37-
runs-on: ubuntu-latest
37+
runs-on: ubuntu-22.04
3838
services:
3939
mysql:
4040
image: mysql:5.7
@@ -47,7 +47,7 @@ jobs:
4747
- name: Setup PHP version
4848
uses: shivammathur/setup-php@v2
4949
with:
50-
php-version: '7.2'
50+
php-version: "7.2"
5151
extensions: simplexml, mysql
5252
tools: phpunit-polyfills
5353
- name: Checkout source code
@@ -69,4 +69,4 @@ jobs:
6969
- name: Install composer
7070
run: composer install --prefer-dist --no-progress --no-suggest
7171
- name: Run phpunit
72-
run: composer run-script phpunit
72+
run: composer run-script phpunit

functions.php

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function define_constants() {
7171
define( 'RAFT_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG === true );
7272
define( 'RAFT_DIR', trailingslashit( get_template_directory() ) );
7373
define( 'RAFT_URL', trailingslashit( get_template_directory_uri() ) );
74+
define( 'RAFT_PRODUCT_SLUG', basename( RAFT_DIR ) );
7475
}
7576

7677
/**

inc/Admin.php

+27-17
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function setup_admin_hooks() {
3333
add_action( 'wp_ajax_raft_dismiss_welcome_notice', array( $this, 'remove_welcome_notice' ) );
3434
add_action( 'wp_ajax_raft_set_otter_ref', array( $this, 'set_otter_ref' ) );
3535
add_action( 'activated_plugin', array( $this, 'after_otter_activation' ) );
36-
add_action( 'admin_print_scripts', array( $this, 'add_nps_form' ) );
36+
add_action( 'admin_enqueue_scripts', array( $this, 'register_internal_page' ) );
3737

3838
add_action( 'enqueue_block_editor_assets', array( $this, 'add_fse_design_pack_notice' ) );
3939
add_action( 'wp_ajax_raft_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) );
@@ -380,27 +380,37 @@ public function after_otter_activation( $plugin ) {
380380
}
381381

382382
/**
383-
* Add NPS form.
383+
* Register internal pages.
384384
*
385385
* @return void
386386
*/
387-
public function add_nps_form() {
387+
public function register_internal_page() {
388388
$screen = get_current_screen();
389-
390-
if ( current_user_can( 'manage_options' ) && ( 'dashboard' === $screen->id || 'themes' === $screen->id ) ) {
391-
$website_url = preg_replace( '/[^a-zA-Z0-9]+/', '', get_site_url() );
392-
393-
$config = array(
394-
'environmentId' => 'clp9hp3j71oqndl2ietgq8nej',
395-
'apiHost' => 'https://app.formbricks.com',
396-
'userId' => 'raft_' . $website_url,
397-
'attributes' => array(
398-
'days_since_install' => self::convert_to_category( round( ( time() - get_option( 'raft_install', time() ) ) / DAY_IN_SECONDS ) ),
399-
),
400-
);
401-
402-
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.6.5/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>';
389+
390+
if ( ! current_user_can( 'manage_options' ) || ( 'dashboard' !== $screen->id && 'themes' !== $screen->id ) ) {
391+
return;
403392
}
393+
394+
add_filter(
395+
'themeisle-sdk/survey/' . RAFT_PRODUCT_SLUG,
396+
function( $data, $page_slug ) {
397+
$install_days_number = intval( ( time() - get_option( 'raft_install', time() ) ) / DAY_IN_SECONDS );
398+
399+
$data = array(
400+
'environmentId' => 'clp9hp3j71oqndl2ietgq8nej',
401+
'attributes' => array(
402+
'days_since_install' => self::convert_to_category( $install_days_number ),
403+
'install_days_number' => $install_days_number,
404+
'version' => RAFT_VERSION,
405+
),
406+
);
407+
408+
return $data;
409+
},
410+
10,
411+
2
412+
);
413+
do_action( 'themeisle_internal_page', RAFT_PRODUCT_SLUG, $screen->id );
404414
}
405415

406416
/**

0 commit comments

Comments
 (0)