PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.7.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.7.2
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / API / Tour.php

Tour.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.7.2, at includes/API/Tour.php

87 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\API;
4
5 class Tour extends API {
6
7 private static $tour_meta_key = 'tour_status';
8
9 public function register_routes() {
10 $this->get( 'tour/status', [ $this, 'get_status' ] );
11 $this->post( 'tour/complete', [ $this, 'mark_complete' ] );
12 $this->post( 'tour/reset', [ $this, 'reset' ] );
13 }
14
15 /**
16 * Get the current tour completion status.
17 *
18 * @return \WP_REST_Response
19 */
20 public function get_status() {
21 $status = $this->utils( 'options' )->get( self::$tour_meta_key, [] );
22
23 if ( ! is_array( $status ) ) {
24 $status = [];
25 }
26
27 return $this->success( $status );
28 }
29
30 /**
31 * Mark a tour as complete.
32 *
33 * Expects a `tour_key` parameter (e.g. "templately_library_tour_v1").
34 *
35 * @return \WP_REST_Response|\WP_Error
36 */
37 public function mark_complete() {
38 $tour_key = $this->get_param( 'tour_key', '' );
39
40 if ( empty( $tour_key ) ) {
41 return $this->error( 'missing_tour_key', __( 'tour_key is required.', 'templately' ), 'tour/complete', 400 );
42 }
43
44 $status = $this->utils( 'options' )->get( self::$tour_meta_key, [] );
45
46 if ( ! is_array( $status ) ) {
47 $status = [];
48 }
49
50 $status[ $tour_key ] = 'done';
51
52 $this->utils( 'options' )->set( self::$tour_meta_key, $status );
53
54 return $this->success( $status );
55 }
56
57 /**
58 * Reset one or all tours.
59 *
60 * Optional `tour_key` parameter — if omitted, resets all tours.
61 *
62 * @return \WP_REST_Response
63 */
64 public function reset() {
65 $tour_key = $this->get_param( 'tour_key', '' );
66
67 if ( ! empty( $tour_key ) ) {
68 $status = $this->utils( 'options' )->get( self::$tour_meta_key, [] );
69
70 if ( ! is_array( $status ) ) {
71 $status = [];
72 }
73
74 unset( $status[ $tour_key ] );
75
76 $this->utils( 'options' )->set( self::$tour_meta_key, $status );
77
78 return $this->success( $status );
79 }
80
81 // Reset all
82 $this->utils( 'options' )->set( self::$tour_meta_key, [] );
83
84 return $this->success( [] );
85 }
86 }
87