Skip to content

Commit 66a7205

Browse files
refactor: load survey via internal pages hook
1 parent aa2d541 commit 66a7205

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

assets/apps/dashboard/src/dashboard.js

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import selectors from './store/selectors';
1212
import { NEVE_STORE } from './utils/constants';
1313

1414
import './utils/module-observer';
15-
import './utils/survey';
1615

1716
maybeAddPolyFills();
1817

assets/apps/dashboard/src/utils/survey.js

-44
This file was deleted.

inc/admin/dashboard/main.php

+58-4
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,22 @@ public function enqueue() {
270270

271271
$build_path = get_template_directory_uri() . '/assets/apps/dashboard/build/';
272272
$dependencies = ( include get_template_directory() . '/assets/apps/dashboard/build/dashboard.asset.php' );
273+
$dash_data = apply_filters( 'neve_dashboard_page_data', $this->get_localization() );
274+
275+
$this->register_survey( $dash_data );
273276

274277
wp_register_style( 'neve-dash-style', $build_path . 'style-dashboard.css', [ 'wp-components', 'neve-components' ], $dependencies['version'] );
275278
wp_style_add_data( 'neve-dash-style', 'rtl', 'replace' );
276279
wp_enqueue_style( 'neve-dash-style' );
277280
wp_register_script( 'neve-dash-script', $build_path . 'dashboard.js', array_merge( $dependencies['dependencies'], [ 'updates' ] ), $dependencies['version'], true );
278-
wp_localize_script( 'neve-dash-script', 'neveDash', apply_filters( 'neve_dashboard_page_data', $this->get_localization() ) );
281+
wp_localize_script( 'neve-dash-script', 'neveDash', $dash_data );
279282
wp_enqueue_script( 'neve-dash-script' );
280283

281284
if ( function_exists( 'wp_set_script_translations' ) ) {
282285
wp_set_script_translations( 'neve-dash-script', 'neve' );
283286
}
284287

285-
do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' );
288+
do_action( 'themeisle_internal_page', 'neve', 'dashboard' );
286289
}
287290

288291
/**
@@ -361,8 +364,6 @@ private function get_localization() {
361364
'canActivatePlugins' => current_user_can( 'activate_plugins' ),
362365
'deal' => $offer->get_localized_data(),
363366
'rootUrl' => get_site_url(),
364-
'daysSinceInstall' => round( ( time() - get_option( 'neve_install', 0 ) ) / DAY_IN_SECONDS ),
365-
'proPluginVersion' => defined( 'NEVE_PRO_VERSION' ) ? NEVE_PRO_VERSION : '',
366367
];
367368

368369
if ( defined( 'NEVE_PRO_PATH' ) ) {
@@ -1084,4 +1085,57 @@ public function render_neve_header() {
10841085
</div>
10851086
<?php
10861087
}
1088+
1089+
/**
1090+
* Register the survey.
1091+
*
1092+
* @param array $dash_data The dashboard data.
1093+
*
1094+
* @return void
1095+
*/
1096+
public function register_survey( $dash_data ) {
1097+
add_filter(
1098+
'themeisle-sdk/survey/neve',
1099+
function( $data, $page_slug ) use ( $dash_data ) {
1100+
1101+
$install_category = 0;
1102+
$install_days_number = intval( ( time() - get_option( 'neve_install', 0 ) ) / DAY_IN_SECONDS );
1103+
1104+
if ( 0 === $install_days_number || 1 === $install_days_number ) {
1105+
$install_category = 0;
1106+
} elseif ( 1 < $install_days_number && 8 > $install_days_number ) {
1107+
$install_category = 7;
1108+
} elseif ( 8 <= $install_days_number && 31 > $install_days_number ) {
1109+
$install_category = 30;
1110+
} elseif ( 30 < $install_days_number && 90 > $install_days_number ) {
1111+
$install_category = 90;
1112+
} elseif ( 90 <= $install_days_number ) {
1113+
$install_category = 91;
1114+
}
1115+
1116+
$data = array(
1117+
'environmentId' => 'clr0ply35522h8up0bay2de4y',
1118+
'attributes' => array(
1119+
'plan' => isset( $dash_data['license'], $dash_data['license']['tier'] ) ? $dash_data['license']['tier'] : 0,
1120+
'license_status' => isset( $dash_data['license'], $dash_data['license']['valid'] ) ? $dash_data['license']['valid'] : 'invalid',
1121+
'days_since_install' => $install_category,
1122+
'install_days_number' => $install_days_number,
1123+
'free_version' => $dash_data['version'],
1124+
),
1125+
);
1126+
1127+
if ( isset( $dash_data['license'], $dash_data['license']['key'] ) ) {
1128+
$data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', $dash_data['license']['key'] );
1129+
}
1130+
1131+
if ( defined( 'NEVE_PRO_VERSION' ) ) {
1132+
$data['attributes']['pro_version'] = NEVE_PRO_VERSION;
1133+
}
1134+
1135+
return $data;
1136+
},
1137+
10,
1138+
2
1139+
);
1140+
}
10871141
}

0 commit comments

Comments
 (0)