Skip to content

Commit 43fc1f8

Browse files
committed
feat: add otter ref to Neve Fse
1 parent ede2505 commit 43fc1f8

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

assets/js/src/welcome-notice.js

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function handleWelcomeNotice( $ ) {
1010
activationUrl,
1111
ajaxUrl,
1212
nonce,
13+
otterRefNonce,
1314
otterStatus,
1415
} = neveFSEData;
1516

@@ -30,6 +31,12 @@ function handleWelcomeNotice( $ ) {
3031
const activateOtter = async () => {
3132
installText.text( activating );
3233
await activatePlugin( activationUrl );
34+
35+
await $.post( ajaxUrl, {
36+
nonce: otterRefNonce,
37+
action: 'neve_fse_set_otter_ref',
38+
} );
39+
3340
installSpinner.removeClass( 'dashicons-update' );
3441
installSpinner.addClass( 'dashicons-yes' );
3542
installText.text( done );

inc/Admin.php

+33-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ class Admin {
2222
*/
2323
private $suspend_survey = true;
2424

25+
/**
26+
* Otter reference key.
27+
*
28+
* @var string
29+
*/
30+
const OTTER_REF = 'otter_reference_key';
31+
2532
/**
2633
* Admin constructor.
2734
*/
@@ -59,6 +66,7 @@ public function setup_admin_hooks() {
5966

6067
add_action( 'enqueue_block_editor_assets', array( $this, 'add_fse_design_pack_notice' ) );
6168
add_action( 'wp_ajax_neve_fse_dismiss_design_pack_notice', array( $this, 'remove_design_pack_notice' ) );
69+
add_action( 'wp_ajax_neve_fse_set_otter_ref', array( $this, 'set_otter_ref' ) );
6270
}
6371

6472
/**
@@ -78,11 +86,12 @@ public function add_fse_design_pack_notice() {
7886
true,
7987
array(),
8088
array(
81-
'nonce' => wp_create_nonce( 'neve-fse-dismiss-design-pack-notice' ),
82-
'ajaxUrl' => esc_url( admin_url( 'admin-ajax.php' ) ),
83-
'ajaxAction' => 'neve_fse_dismiss_design_pack_notice',
84-
'buttonLink' => tsdk_utmify( 'https://themeisle.com/plugins/fse-design-pack', 'editor', 'neve-fse' ),
85-
'strings' => array(
89+
'nonce' => wp_create_nonce( 'neve-fse-dismiss-design-pack-notice' ),
90+
'otterRefNonce' => wp_create_nonce( 'neve-fse-set-otter-ref' ),
91+
'ajaxUrl' => esc_url( admin_url( 'admin-ajax.php' ) ),
92+
'ajaxAction' => 'neve_fse_dismiss_design_pack_notice',
93+
'buttonLink' => tsdk_utmify( 'https://themeisle.com/plugins/fse-design-pack', 'editor', 'neve-fse' ),
94+
'strings' => array(
8695
'dismiss' => __( 'Dismiss', 'neve-fse' ),
8796
'recommends' => __( 'Neve FSE recommends', 'neve-fse' ),
8897
'learnMore' => __( 'Learn More', 'neve-fse' ),
@@ -428,6 +437,25 @@ private function get_otter_status(): string {
428437
return $status;
429438
}
430439

440+
/**
441+
* Update Otter reference key.
442+
*
443+
* @return void
444+
*/
445+
public function set_otter_ref() {
446+
if ( empty( $_POST['nonce'] ) ) {
447+
return;
448+
}
449+
450+
if ( ! wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), 'neve-fse-set-otter-ref' ) ) {
451+
return;
452+
}
453+
454+
update_option( self::OTTER_REF, 'neve-fse' );
455+
456+
wp_send_json_success();
457+
}
458+
431459
/**
432460
* Add NPS form.
433461
*

0 commit comments

Comments
 (0)