diff --git a/.github/workflows/test-php.yml b/.github/workflows/test-php.yml index b8b0af0..72eb338 100644 --- a/.github/workflows/test-php.yml +++ b/.github/workflows/test-php.yml @@ -3,17 +3,17 @@ name: Test PHP on: push: branches-ignore: - - 'main' + - "main" 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 diff --git a/functions.php b/functions.php index 342be51..312d817 100644 --- a/functions.php +++ b/functions.php @@ -71,6 +71,7 @@ function define_constants() { define( 'NEVE_FSE_DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG === true ); define( 'NEVE_FSE_DIR', trailingslashit( get_template_directory() ) ); define( 'NEVE_FSE_URL', trailingslashit( get_template_directory_uri() ) ); + define( 'NEVE_FSE_PRODUCT_SLUG', basename( NEVE_FSE_DIR ) ); } /** diff --git a/inc/Admin.php b/inc/Admin.php index 0343e87..fafe371 100644 --- a/inc/Admin.php +++ b/inc/Admin.php @@ -62,7 +62,7 @@ public function setup_admin_hooks() { add_action( 'admin_notices', array( $this, 'render_survey_notice' ) ); add_action( 'wp_ajax_neve_fse_dismiss_welcome_notice', array( $this, 'remove_welcome_notice' ) ); add_action( 'wp_ajax_neve_fse_dismiss_survey_notice', array( $this, 'remove_survey_notice' ) ); - 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_neve_fse_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) ); @@ -529,6 +529,40 @@ public function add_nps_form() { } } + /** + * Register internal pages. + * + * @return void + */ + public function register_internal_page() { + $screen = get_current_screen(); + + if ( ! current_user_can( 'manage_options' ) || ( 'dashboard' !== $screen->id && 'themes' !== $screen->id ) ) { + return; + } + + add_filter( + 'themeisle-sdk/survey/' . NEVE_FSE_PRODUCT_SLUG, + function( $data, $page_slug ) { + $install_days_number = intval( ( time() - get_option( 'neve_fse_install', time() ) ) / DAY_IN_SECONDS ); + + $data = array( + 'environmentId' => 'clr7hcws7et2g8up0tpz8u8es', + 'attributes' => array( + 'days_since_install' => self::convert_to_category( $install_days_number ), + 'install_days_number' => $install_days_number, + 'version' => NEVE_FSE_VERSION, + ), + ); + + return $data; + }, + 10, + 2 + ); + do_action( 'themeisle_internal_page', NEVE_FSE_PRODUCT_SLUG, $screen->id ); + } + /** * Convert a number to a category. *