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 6f20cfd commit bd61fb0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
10 changes: 5 additions & 5 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:
- '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
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 Down
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( '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 ) );
}

/**
Expand Down
36 changes: 35 additions & 1 deletion inc/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit bd61fb0

Please # to comment.