Skip to content

Commit d6b5e8f

Browse files
authored
Merge pull request #77 from Codeinwp/refactor/internal-pages
Refactor/internal pages
2 parents e2c69af + 176ccc6 commit d6b5e8f

3 files changed

Lines changed: 32 additions & 46 deletions

File tree

.github/workflows/test-php.yml

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function define_constants() {
7171
define( 'FORK_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG === true );
7272
define( 'FORK_DIR', trailingslashit( get_template_directory() ) );
7373
define( 'FORK_URL', trailingslashit( get_template_directory_uri() ) );
74+
define( 'FORK_PRODUCT_SLUG', basename( FORK_DIR ) );
7475
}
7576

7677
/**

inc/Admin.php

Lines changed: 25 additions & 40 deletions
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_fork_dismiss_welcome_notice', array( $this, 'remove_welcome_notice' ) );
3535
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+
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_fork_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) );
@@ -307,50 +307,35 @@ private function get_otter_status(): string {
307307
}
308308

309309
/**
310-
* Add NPS form.
310+
* Register internal pages.
311311
*
312312
* @return void
313313
*/
314-
public function add_nps_form() {
314+
public function register_internal_page() {
315315
$screen = get_current_screen();
316-
317-
if ( current_user_can( 'manage_options' ) && ( 'dashboard' === $screen->id || 'themes' === $screen->id ) ) {
318-
$website_url = preg_replace( '/[^a-zA-Z0-9]+/', '', get_site_url() );
319-
320-
$config = array(
321-
'environmentId' => 'clr7hsvmjeu0u8up04ydg210b',
322-
'apiHost' => 'https://app.formbricks.com',
323-
'userId' => 'fork_' . $website_url,
324-
'attributes' => array(
325-
'days_since_install' => self::convert_to_category( round( ( time() - get_option( 'fork_install', time() ) ) / DAY_IN_SECONDS ) ),
326-
),
327-
);
328-
329-
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>';
316+
317+
if ( ! current_user_can( 'manage_options' ) || ( 'dashboard' !== $screen->id && 'themes' !== $screen->id ) ) {
318+
return;
330319
}
331-
}
320+
321+
add_filter(
322+
'themeisle-sdk/survey/' . FORK_PRODUCT_SLUG,
323+
function( $data, $page_slug ) {
324+
$install_days_number = intval( ( time() - get_option( 'fork_install', time() ) ) / DAY_IN_SECONDS );
325+
326+
$data = array(
327+
'environmentId' => 'clr7hsvmjeu0u8up04ydg210b',
328+
'attributes' => array(
329+
'install_days_number' => $install_days_number,
330+
'version' => FORK_VERSION,
331+
),
332+
);
332333

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

0 commit comments

Comments
 (0)