PluginProbe
Assistant – Every Day Productivity Apps / 0.3.1
Assistant – Every Day Productivity Apps v0.3.1
1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 1.0 All 71 releases
assistant / backend / src / Data / UserState.php

UserState.php in Assistant – Every Day Productivity Apps 0.3.1, at backend/src/Data/UserState.php

75 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace FL\Assistant\Data;
5
6
7 /**
8 * Class UserState
9 * @package FL\Assistant\Data
10 */
11 class UserState {
12
13 /**
14 * Storage key for user meta
15 */
16 const FL_ASSISTANT_STATE = 'fl_assistant_state';
17
18 /**
19 * Default state for the current user.
20 */
21 public static $default_state = [
22 'appOrder' => [],
23 'window' => [
24 'origin' => [ 1, 0 ],
25 'size' => 'mini',
26 'isHidden' => false,
27 'hiddenAppearance' => '',
28 'overlayToolbar' => false,
29 ],
30 'appearance' => [
31 'brightness' => 'light',
32 ],
33 'history' => [
34 'index' => 0,
35 'entries' => [],
36 ],
37 'searchHistory' => [],
38 'shouldReduceMotion' => false,
39 'shouldShowLabels' => true,
40 'shouldShowInAdmin' => true,
41 ];
42
43 /**
44 * Get the saved state for the current user.
45 */
46 public static function get() {
47
48 $saved = get_user_meta(
49 wp_get_current_user()->ID,
50 static::FL_ASSISTANT_STATE,
51 true
52 );
53
54 return array_replace_recursive(
55 static::$default_state,
56 $saved ? (array) $saved : []
57 );
58 }
59
60 /**
61 * Update the saved state for the current user
62 */
63 public static function update( array $state = [] ) {
64
65 $saved = static::get();
66
67 update_user_meta(
68 wp_get_current_user()->ID,
69 static::FL_ASSISTANT_STATE,
70 array_merge( $saved, $state )
71 );
72 }
73
74 }
75