Skip to content

Commit 7dc2022

Browse files
authored
Merge pull request #84 from Codeinwp/refactor/internal-pages
feat: load survey vis internal pages hooks
2 parents 3e002e5 + d3af6ff commit 7dc2022

File tree

3 files changed

+32
-46
lines changed

3 files changed

+32
-46
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( 'RIVERBANK_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG === true );
7272
define( 'RIVERBANK_DIR', trailingslashit( get_template_directory() ) );
7373
define( 'RIVERBANK_URL', trailingslashit( get_template_directory_uri() ) );
74+
define( 'RIVERBANK_PRODUCT_SLUG', basename( RIVERBANK_DIR ) );
7475
}
7576

7677
/**

inc/Admin.php

+25-40
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function setup_admin_hooks() {
3333
add_action( 'admin_notices', array( $this, 'render_welcome_notice' ), 0 );
3434
add_action( 'wp_ajax_riverbank_dismiss_welcome_notice', array( $this, 'remove_welcome_notice' ) );
3535
add_action( 'wp_ajax_riverbank_set_otter_ref', array( $this, 'set_otter_ref' ) );
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_riverbank_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) );
@@ -308,50 +308,35 @@ private function get_otter_status(): string {
308308
}
309309

310310
/**
311-
* Add NPS form.
311+
* Register internal pages.
312312
*
313313
* @return void
314314
*/
315-
public function add_nps_form() {
315+
public function register_internal_page() {
316316
$screen = get_current_screen();
317-
318-
if ( current_user_can( 'manage_options' ) && ( 'dashboard' === $screen->id || 'themes' === $screen->id ) ) {
319-
$website_url = preg_replace( '/[^a-zA-Z0-9]+/', '', get_site_url() );
320-
321-
$config = array(
322-
'environmentId' => 'clr7jal6eexcy8up0wdufqz2d',
323-
'apiHost' => 'https://app.formbricks.com',
324-
'userId' => 'riverbank_' . $website_url,
325-
'attributes' => array(
326-
'days_since_install' => self::convert_to_category( round( ( time() - get_option( 'riverbank_install', time() ) ) / DAY_IN_SECONDS ) ),
327-
),
328-
);
329-
330-
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>';
317+
318+
if ( ! current_user_can( 'manage_options' ) || ( 'dashboard' !== $screen->id && 'themes' !== $screen->id ) ) {
319+
return;
331320
}
332-
}
321+
322+
add_filter(
323+
'themeisle-sdk/survey/' . RIVERBANK_PRODUCT_SLUG,
324+
function( $data, $page_slug ) {
325+
$install_days_number = intval( ( time() - get_option( 'riverbank_install', time() ) ) / DAY_IN_SECONDS );
326+
327+
$data = array(
328+
'environmentId' => 'clr7jal6eexcy8up0wdufqz2d',
329+
'attributes' => array(
330+
'install_days_number' => $install_days_number,
331+
'version' => RIVERBANK_VERSION,
332+
),
333+
);
333334

334-
/**
335-
* Convert a number to a category.
336-
*
337-
* @param int $number Number to convert.
338-
* @param int $scale Scale.
339-
*
340-
* @return int
341-
*/
342-
public static function convert_to_category( $number, $scale = 1 ) {
343-
$normalized_number = intval( round( $number / $scale ) );
344-
345-
if ( 0 === $normalized_number || 1 === $normalized_number ) {
346-
return 0;
347-
} elseif ( $normalized_number > 1 && $normalized_number < 8 ) {
348-
return 7;
349-
} elseif ( $normalized_number >= 8 && $normalized_number < 31 ) {
350-
return 30;
351-
} elseif ( $normalized_number > 30 && $normalized_number < 90 ) {
352-
return 90;
353-
} elseif ( $normalized_number > 90 ) {
354-
return 91;
355-
}
335+
return $data;
336+
},
337+
10,
338+
2
339+
);
340+
do_action( 'themeisle_internal_page', RIVERBANK_PRODUCT_SLUG, $screen->id );
356341
}
357342
}

0 commit comments

Comments
 (0)