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

Only show admin tour within first day after installation. #196

Merged
merged 1 commit into from
Sep 23, 2024
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
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
Loading