HEX
Server: LiteSpeed
System: Linux lt-bnk-web1368.main-hosting.eu 5.14.0-611.26.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jan 29 05:24:47 EST 2026 x86_64
User: u362014288 (362014288)
PHP: 8.2.30
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: /home/u362014288/public_html/wp-content/plugins/templately/includes/API/Tour.php
<?php

namespace Templately\API;

class Tour extends API {

	private static $tour_meta_key = 'tour_status';

	public function register_routes() {
		$this->get( 'tour/status', [ $this, 'get_status' ] );
		$this->post( 'tour/complete', [ $this, 'mark_complete' ] );
		$this->post( 'tour/reset', [ $this, 'reset' ] );
	}

	/**
	 * Get the current tour completion status.
	 *
	 * @return \WP_REST_Response
	 */
	public function get_status() {
		$status = $this->utils( 'options' )->get( self::$tour_meta_key, [] );

		if ( ! is_array( $status ) ) {
			$status = [];
		}

		return $this->success( $status );
	}

	/**
	 * Mark a tour as complete.
	 *
	 * Expects a `tour_key` parameter (e.g. "templately_library_tour_v1").
	 *
	 * @return \WP_REST_Response|\WP_Error
	 */
	public function mark_complete() {
		$tour_key = $this->get_param( 'tour_key', '' );

		if ( empty( $tour_key ) ) {
			return $this->error( 'missing_tour_key', __( 'tour_key is required.', 'templately' ), 'tour/complete', 400 );
		}

		$status = $this->utils( 'options' )->get( self::$tour_meta_key, [] );

		if ( ! is_array( $status ) ) {
			$status = [];
		}

		$status[ $tour_key ] = 'done';

		$this->utils( 'options' )->set( self::$tour_meta_key, $status );

		return $this->success( $status );
	}

	/**
	 * Reset one or all tours.
	 *
	 * Optional `tour_key` parameter — if omitted, resets all tours.
	 *
	 * @return \WP_REST_Response
	 */
	public function reset() {
		$tour_key = $this->get_param( 'tour_key', '' );

		if ( ! empty( $tour_key ) ) {
			$status = $this->utils( 'options' )->get( self::$tour_meta_key, [] );

			if ( ! is_array( $status ) ) {
				$status = [];
			}

			unset( $status[ $tour_key ] );

			$this->utils( 'options' )->set( self::$tour_meta_key, $status );

			return $this->success( $status );
		}

		// Reset all
		$this->utils( 'options' )->set( self::$tour_meta_key, [] );

		return $this->success( [] );
	}
}