(int) ( $state['sends'] ?? 0 ), 'dismissed' => ! empty( $state['dismissed'] ), 'snoozed_until' => (int) ( $state['snoozed_until'] ?? 0 ), ]; } private function save( array $state ) { update_option( self::OPTION, $state, false ); } /** Fired by Button::send on every successful send. Stops counting once the notice is retired. */ public function count_send() { $state = $this->state(); if ( $state['dismissed'] || $state['sends'] > self::REVIEW_AFTER ) { return; } $state['sends']++; $this->save( $state ); } private function on_our_screen() { $screen = get_current_screen(); if ( ! $screen ) { return false; } return $screen->id === 'toplevel_page_webhook-buttons' || $screen->id === 'woocommerce_page_wc-orders' || $screen->post_type === 'shop_order'; } public function maybe_show() { if ( ! current_user_can( 'manage_woocommerce' ) || ! $this->on_our_screen() ) { return; } $state = $this->state(); if ( $state['dismissed'] || $state['sends'] < self::REVIEW_AFTER || $state['snoozed_until'] > time() ) { return; } $nonce = wp_create_nonce( 'webhook_buttons_review_dismiss' ); wp_enqueue_script( 'webhook-buttons-review-notice', WEBHOOK_BUTTONS_PLUGIN_URL . 'assets/review-notice.js', [], WEBHOOK_BUTTONS_VERSION, true ); ?>
state(); if ( $what === 'done' ) { $state['dismissed'] = true; } else { $state['snoozed_until'] = time() + self::SNOOZE_DAYS * DAY_IN_SECONDS; } $this->save( $state ); wp_send_json_success(); } }