HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/html/ielts-store/wp-content/plugins/woocommerce-zapier/src/NewUser/NewUser.php
<?php

namespace OM4\WooCommerceZapier\NewUser;

use OM4\WooCommerceZapier\Auth\KeyDataStore;
use OM4\WooCommerceZapier\NewUser\NewUserWelcomeNotice;
use OM4\WooCommerceZapier\Settings;
use OM4\WooCommerceZapier\TaskHistory\TaskDataStore;

defined( 'ABSPATH' ) || exit;

/**
 * Detects if a user is using the extension/plugin for the first time.
 *
 * @since 2.0.0
 */
class NewUser {

	/**
	 * Settings instance.
	 *
	 * @var Settings
	 */
	protected $settings;

	/**
	 * TaskDataStore instance.
	 *
	 * @var TaskDataStore
	 */
	protected $task_data_store;

	/**
	 * KeyDataStore instance.
	 *
	 * @var KeyDataStore
	 */
	protected $key_data_store;

	/**
	 * NewUserWelcomeNotice instance.
	 *
	 * @var NewUserWelcomeNotice
	 */
	protected $welcome_notice;

	/**
	 * Constructor.
	 *
	 * @param Settings             $settings Settings instance.
	 * @param TaskDataStore        $task_data_store TaskDataStore instance.
	 * @param KeyDataStore         $key_data_store KeyDataStore instance.
	 * @param NewUserWelcomeNotice $welcome_notice NewUserWelcomeNotice instance.
	 */
	public function __construct(
		Settings $settings,
		TaskDataStore $task_data_store,
		KeyDataStore $key_data_store,
		NewUserWelcomeNotice $welcome_notice
	) {
		$this->settings        = $settings;
		$this->task_data_store = $task_data_store;
		$this->key_data_store  = $key_data_store;
		$this->welcome_notice  = $welcome_notice;
	}

	/**
	 * Initialise the functionality by hooking into the relevant hooks.
	 *
	 * @return void
	 */
	public function initialise() {
		// Initialise Notice.
		$this->welcome_notice->initialise();

		add_action( 'wc_zapier_db_upgrade_v_11_to_12', array( $this, 'maybe_enable_new_user_notice' ) );
	}

	/**
	 * During the database upgrade routine, enable the new user welcome notice if the installation is new.
	 *
	 * Executed during the `wc_zapier_db_upgrade_v_11_to_12` hook.
	 *
	 * @return void
	 */
	public function maybe_enable_new_user_notice() {
		if ( $this->is_new_user() ) {
			$this->welcome_notice->enable();
		}
	}

	/**
	 * Whether or not the installation is a "new" user, which is someone with all of the following:
	 * - legacy mode disabled
	 * - 0 task history records
	 * - 0 authentication keys
	 *
	 * @return bool
	 */
	public function is_new_user() {
		if ( $this->settings->is_legacy_mode_enabled() ) {
			return false;
		}
		if ( 0 !== $this->task_data_store->get_tasks_count() ) {
			return false;
		}
		if ( 0 !== $this->key_data_store->count() ) {
			return false;
		}
		return true;
	}
}