diff --git a/.github/workflows/test-php.yml b/.github/workflows/test-php.yml index e465cd8..9f0f463 100644 --- a/.github/workflows/test-php.yml +++ b/.github/workflows/test-php.yml @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file + run: composer run-script phpunit diff --git a/functions.php b/functions.php index c71ee12..b00804b 100644 --- a/functions.php +++ b/functions.php @@ -71,6 +71,7 @@ function define_constants() { define( 'JAXON_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG === true ); define( 'JAXON_DIR', trailingslashit( get_template_directory() ) ); define( 'JAXON_URL', trailingslashit( get_template_directory_uri() ) ); + define( 'JAXON_PRODUCT_SLUG', basename( JAXON_DIR ) ); } /** diff --git a/inc/Admin.php b/inc/Admin.php index 40d196c..489daf2 100644 --- a/inc/Admin.php +++ b/inc/Admin.php @@ -33,7 +33,7 @@ public function setup_admin_hooks() { add_action( 'admin_notices', array( $this, 'render_welcome_notice' ), 0 ); add_action( 'wp_ajax_jaxon_dismiss_welcome_notice', array( $this, 'remove_welcome_notice' ) ); add_action( 'wp_ajax_jaxon_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_jaxon_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) ); @@ -307,50 +307,35 @@ 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' => 'clr7jjqypey8v8up0bg5lk2nw', - 'apiHost' => 'https://app.formbricks.com', - 'userId' => 'jaxon_' . $website_url, - 'attributes' => array( - 'days_since_install' => self::convert_to_category( round( ( time() - get_option( 'jaxon_install', time() ) ) / DAY_IN_SECONDS ) ), - ), - ); - - echo ''; + + if ( ! current_user_can( 'manage_options' ) || ( 'dashboard' !== $screen->id && 'themes' !== $screen->id ) ) { + return; } - } + + add_filter( + 'themeisle-sdk/survey/' . JAXON_PRODUCT_SLUG, + function( $data, $page_slug ) { + $install_days_number = intval( ( time() - get_option( 'jaxon_install', time() ) ) / DAY_IN_SECONDS ); + + $data = array( + 'environmentId' => 'clr7jjqypey8v8up0bg5lk2nw', + 'attributes' => array( + 'install_days_number' => $install_days_number, + 'version' => JAXON_VERSION, + ), + ); - /** - * Convert a number to a category. - * - * @param int $number Number to convert. - * @param int $scale Scale. - * - * @return int - */ - public static function convert_to_category( $number, $scale = 1 ) { - $normalized_number = intval( round( $number / $scale ) ); - - if ( 0 === $normalized_number || 1 === $normalized_number ) { - return 0; - } elseif ( $normalized_number > 1 && $normalized_number < 8 ) { - return 7; - } elseif ( $normalized_number >= 8 && $normalized_number < 31 ) { - return 30; - } elseif ( $normalized_number > 30 && $normalized_number < 90 ) { - return 90; - } elseif ( $normalized_number > 90 ) { - return 91; - } + return $data; + }, + 10, + 2 + ); + do_action( 'themeisle_internal_page', JAXON_PRODUCT_SLUG, $screen->id ); } }