Skip to content

Commit

Permalink
feat: add otter ref to Neve Fse
Browse files Browse the repository at this point in the history
  • Loading branch information
HardeepAsrani committed Aug 14, 2024
1 parent ede2505 commit 43fc1f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
7 changes: 7 additions & 0 deletions assets/js/src/welcome-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function handleWelcomeNotice( $ ) {
activationUrl,
ajaxUrl,
nonce,
otterRefNonce,
otterStatus,
} = neveFSEData;

Expand All @@ -30,6 +31,12 @@ function handleWelcomeNotice( $ ) {
const activateOtter = async () => {
installText.text( activating );
await activatePlugin( activationUrl );

await $.post( ajaxUrl, {
nonce: otterRefNonce,
action: 'neve_fse_set_otter_ref',
} );

installSpinner.removeClass( 'dashicons-update' );
installSpinner.addClass( 'dashicons-yes' );
installText.text( done );
Expand Down
38 changes: 33 additions & 5 deletions inc/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class Admin {
*/
private $suspend_survey = true;

/**
* Otter reference key.
*
* @var string
*/
const OTTER_REF = 'otter_reference_key';

/**
* Admin constructor.
*/
Expand Down Expand Up @@ -59,6 +66,7 @@ public function setup_admin_hooks() {

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' ) );
add_action( 'wp_ajax_neve_fse_set_otter_ref', array( $this, 'set_otter_ref' ) );
}

/**
Expand All @@ -78,11 +86,12 @@ public function add_fse_design_pack_notice() {
true,
array(),
array(
'nonce' => wp_create_nonce( 'neve-fse-dismiss-design-pack-notice' ),
'ajaxUrl' => esc_url( admin_url( 'admin-ajax.php' ) ),
'ajaxAction' => 'neve_fse_dismiss_design_pack_notice',
'buttonLink' => tsdk_utmify( 'https://themeisle.com/plugins/fse-design-pack', 'editor', 'neve-fse' ),
'strings' => array(
'nonce' => wp_create_nonce( 'neve-fse-dismiss-design-pack-notice' ),
'otterRefNonce' => wp_create_nonce( 'neve-fse-set-otter-ref' ),
'ajaxUrl' => esc_url( admin_url( 'admin-ajax.php' ) ),
'ajaxAction' => 'neve_fse_dismiss_design_pack_notice',
'buttonLink' => tsdk_utmify( 'https://themeisle.com/plugins/fse-design-pack', 'editor', 'neve-fse' ),
'strings' => array(
'dismiss' => __( 'Dismiss', 'neve-fse' ),
'recommends' => __( 'Neve FSE recommends', 'neve-fse' ),
'learnMore' => __( 'Learn More', 'neve-fse' ),
Expand Down Expand Up @@ -428,6 +437,25 @@ private function get_otter_status(): string {
return $status;
}

/**
* Update Otter reference key.
*
* @return void
*/
public function set_otter_ref() {
if ( empty( $_POST['nonce'] ) ) {
return;
}

if ( ! wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), 'neve-fse-set-otter-ref' ) ) {
return;
}

update_option( self::OTTER_REF, 'neve-fse' );

wp_send_json_success();
}

/**
* Add NPS form.
*
Expand Down

0 comments on commit 43fc1f8

Please sign in to comment.