Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: load survey via internal pages hook #4378

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion assets/apps/dashboard/src/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import selectors from './store/selectors';
import { NEVE_STORE } from './utils/constants';

import './utils/module-observer';
import './utils/survey';

maybeAddPolyFills();

Expand Down
44 changes: 0 additions & 44 deletions assets/apps/dashboard/src/utils/survey.js

This file was deleted.

48 changes: 44 additions & 4 deletions inc/admin/dashboard/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,22 @@ public function enqueue() {

$build_path = get_template_directory_uri() . '/assets/apps/dashboard/build/';
$dependencies = ( include get_template_directory() . '/assets/apps/dashboard/build/dashboard.asset.php' );
$dash_data = apply_filters( 'neve_dashboard_page_data', $this->get_localization() );

$this->register_survey( $dash_data );

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

if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations( 'neve-dash-script', 'neve' );
}

do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' );
do_action( 'themeisle_internal_page', 'neve', 'dashboard' );
}

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

if ( defined( 'NEVE_PRO_PATH' ) ) {
Expand Down Expand Up @@ -1084,4 +1085,43 @@ public function render_neve_header() {
</div>
<?php
}

/**
* Register the survey.
*
* @param array $dash_data The dashboard data.
*
* @return void
*/
public function register_survey( $dash_data ) {
add_filter(
'themeisle-sdk/survey/neve',
function( $data, $page_slug ) use ( $dash_data ) {

$install_days_number = intval( ( time() - get_option( 'neve_install', time() ) ) / DAY_IN_SECONDS );

$data = array(
'environmentId' => 'clr0ply35522h8up0bay2de4y',
'attributes' => array(
'plan' => isset( $dash_data['license'], $dash_data['license']['tier'] ) ? $dash_data['license']['tier'] : 0,
'license_status' => isset( $dash_data['license'], $dash_data['license']['valid'] ) ? $dash_data['license']['valid'] : 'invalid',
'install_days_number' => $install_days_number,
'free_version' => $dash_data['version'],
),
);

if ( isset( $dash_data['license'], $dash_data['license']['key'] ) ) {
$data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', $dash_data['license']['key'] );
}

if ( defined( 'NEVE_PRO_VERSION' ) ) {
$data['attributes']['pro_version'] = NEVE_PRO_VERSION;
}

return $data;
},
10,
2
);
}
}
Loading