Skip to content

Commit

Permalink
feat: load survey vis internal pages hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Feb 17, 2025
1 parent 3e002e5 commit c152980
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ name: Test PHP
on:
push:
branches-ignore:
- 'master'
- "master"

jobs:
phplint:
name: Phplint
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Setup PHP version
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: "7.2"
extensions: simplexml
- name: Checkout source code
uses: actions/checkout@v2
Expand All @@ -34,7 +34,7 @@ jobs:
run: composer run lint
phpunit:
name: Phpunit
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
services:
mysql:
image: mysql:5.7
Expand All @@ -47,7 +47,7 @@ jobs:
- name: Setup PHP version
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: "7.2"
extensions: simplexml, mysql
tools: phpunit-polyfills
- name: Checkout source code
Expand All @@ -69,4 +69,4 @@ jobs:
- name: Install composer
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run phpunit
run: composer run-script phpunit
run: composer run-script phpunit
1 change: 1 addition & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function define_constants() {
define( 'RIVERBANK_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG === true );
define( 'RIVERBANK_DIR', trailingslashit( get_template_directory() ) );
define( 'RIVERBANK_URL', trailingslashit( get_template_directory_uri() ) );
define( 'RIVERBANK_PRODUCT_SLUG', basename( RIVERBANK_DIR ) );
}

/**
Expand Down
44 changes: 27 additions & 17 deletions inc/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setup_admin_hooks() {
add_action( 'admin_notices', array( $this, 'render_welcome_notice' ), 0 );
add_action( 'wp_ajax_riverbank_dismiss_welcome_notice', array( $this, 'remove_welcome_notice' ) );
add_action( 'wp_ajax_riverbank_set_otter_ref', array( $this, 'set_otter_ref' ) );
add_action( 'admin_print_scripts', array( $this, 'add_nps_form' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'register_internal_page' ) );

add_action( 'enqueue_block_editor_assets', array( $this, 'add_fse_design_pack_notice' ) );
add_action( 'wp_ajax_riverbank_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) );
Expand Down Expand Up @@ -308,27 +308,37 @@ private function get_otter_status(): string {
}

/**
* Add NPS form.
* Register internal pages.
*
* @return void
*/
public function add_nps_form() {
public function register_internal_page() {
$screen = get_current_screen();

if ( current_user_can( 'manage_options' ) && ( 'dashboard' === $screen->id || 'themes' === $screen->id ) ) {
$website_url = preg_replace( '/[^a-zA-Z0-9]+/', '', get_site_url() );

$config = array(
'environmentId' => 'clr7jal6eexcy8up0wdufqz2d',
'apiHost' => 'https://app.formbricks.com',
'userId' => 'riverbank_' . $website_url,
'attributes' => array(
'days_since_install' => self::convert_to_category( round( ( time() - get_option( 'riverbank_install', time() ) ) / DAY_IN_SECONDS ) ),
),
);

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>';

if ( ! current_user_can( 'manage_options' ) || ( 'dashboard' !== $screen->id && 'themes' !== $screen->id ) ) {
return;
}

add_filter(
'themeisle-sdk/survey/' . RIVERBANK_PRODUCT_SLUG,
function( $data, $page_slug ) {
$install_days_number = intval( ( time() - get_option( 'riverbank_install', time() ) ) / DAY_IN_SECONDS );

$data = array(
'environmentId' => 'clr7jal6eexcy8up0wdufqz2d',
'attributes' => array(
'days_since_install' => self::convert_to_category( $install_days_number ),
'install_days_number' => $install_days_number,
'version' => RIVERBANK_VERSION,
),
);

return $data;
},
10,
2
);
do_action( 'themeisle_internal_page', RIVERBANK_PRODUCT_SLUG, $screen->id );
}

/**
Expand Down

0 comments on commit c152980

Please sign in to comment.