Skip to content

Commit

Permalink
Only show admin tour within first day after installation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Sep 23, 2024
1 parent 8f850ce commit c39390b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/Admin/AdminTour.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,47 @@ public function __construct( Plugin $plugin ) {
$this->plugin = $plugin;

// Actions.
add_action( 'admin_init', [ $this, 'admin_init' ] );
add_action( 'admin_init', [ $this, 'handle_ignore_tour_request' ] );
add_action( 'admin_init', [ $this, 'maybe_show_admin_tour' ] );
}

/**
* Admin initialize.
* Maybe show admin tour.
*
* @return void
*/
public function admin_init() {
$this->handle_ignore_tour_request();
public function maybe_show_admin_tour() {
// Ignore tour.
if ( \get_user_meta( \get_current_user_id(), 'pronamic_pay_ignore_tour', true ) ) {
return;
}

// Installation date.
$installation_date = (string) \get_option( 'pronamic_pay_installation_date', '' );

if ( '' !== $installation_date ) {
try {
$installation_date = new \DateTimeImmutable( $installation_date );

if ( ! get_user_meta( get_current_user_id(), 'pronamic_pay_ignore_tour', true ) ) {
add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
$day_ago = new \DateTimeImmutable( '-1 day' );

if ( $installation_date < $day_ago ) {
return;
}
} catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
// Nothing to do, ignore invalid installation date.
}
}

\add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
}

/**
* Handle ignore tour request.
*
* @return void
*/
private function handle_ignore_tour_request() {
public function handle_ignore_tour_request() {
if ( ! \array_key_exists( 'pronamic_pay_ignore_tour', $_GET ) ) {
return;
}
Expand Down
7 changes: 7 additions & 0 deletions src/Admin/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ private function install() {
// Version.
$version = $this->plugin->get_version();

// Installation date.
$installation_date = (string) \get_option( 'pronamic_pay_installation_date', '' );

if ( '' === $installation_date ) {
\update_option( 'pronamic_pay_installation_date', \current_time( 'mysql', true ) );
}

// Action.
\do_action( 'pronamic_pay_install' );

Expand Down

0 comments on commit c39390b

Please sign in to comment.