PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 1.3.3
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v1.3.3
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 / core / class-db.php

class-db.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 1.3.3, at core/class-db.php

163 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately;
4
5 class DB {
6 /**
7 * Get an option
8 *
9 * @param string $key
10 * @param mixed $default
11 *
12 * @return void
13 */
14 public static function get_option( $key, $default = false ) {
15 $trimmed_key = trim( $key );
16
17 return empty( $trimmed_key ) ? false : \get_option( $trimmed_key, $default );
18 }
19
20 /**
21 * Update an option
22 *
23 * @param string $key
24 * @param mixed $value
25 * @param string|boolean $autoload
26 *
27 * @return void
28 */
29 public static function update_option( $key, $value, $autoload = null ) {
30 $trimmed_key = trim( $key );
31
32 return empty( $trimmed_key ) ? false : \update_option( $trimmed_key, $value, $autoload );
33 }
34 public static function set_transient( $key, $value, $expiration = DAY_IN_SECONDS ){
35 return set_transient( $key, $value, $expiration );
36 }
37 public static function get_transient( $key ){
38 return get_transient( $key );
39 }
40 public static function delete_transient( $key ){
41 return \delete_transient( $key );
42 }
43 /**
44 * Update|Set user meta.
45 *
46 * @param int $user_id
47 * @param string $meta_key
48 * @param mixed $meta_value
49 */
50 public static function update_user_meta( $user_id, $meta_key, $meta_value ) {
51
52 if ( ! $user_id ) {
53 $user_id = get_current_user_id();
54 }
55
56 $user_id = absint( $user_id );
57 $meta_key = trim( $meta_key );
58
59 if ( ! $user_id && empty( $meta_key ) ) {
60 return false;
61 }
62
63 return \update_user_meta( $user_id, $meta_key, $meta_value );
64 }
65
66 /**
67 * Get an option
68 *
69 * @param int $user_id
70 * @param string $meta_key
71 * @param bool $single
72 */
73 public static function get_user_meta( $user_id, $meta_key, $default = false, $single = true ) {
74
75 if ( ! $user_id ) {
76 $user_id = get_current_user_id();
77 }
78
79 $user_id = absint( $user_id );
80 $meta_key = trim( $meta_key );
81
82 if ( ! $user_id && empty( $meta_key ) ) {
83 return false;
84 }
85
86 $res = \get_user_meta( $user_id, $meta_key, $single );
87
88 return ( ! $res ) ? $default : $res;
89
90 }
91
92 /**
93 * Delete a user meta.
94 *
95 * @param int $user_id
96 * @param string $meta_key
97 */
98 public static function delete_user_meta( $user_id, $meta_key ) {
99
100 if ( ! $user_id ) {
101 return false;
102 }
103
104 $user_id = absint( $user_id );
105 $meta_key = trim( $meta_key );
106
107 if ( ! $user_id && empty( $meta_key ) ) {
108 return false;
109 }
110
111 return \delete_user_meta( $user_id, $meta_key );
112
113 }
114
115 /**
116 * Delete an option
117 *
118 * @param string $key
119 *
120 * @return void
121 */
122 public static function delete_option( $key ) {
123 $trimmed_key = trim( $key );
124 if ( ! empty( $trimmed_key ) ) {
125 return \delete_option( $trimmed_key );
126 }
127
128 return false;
129 }
130
131 /**
132 * Update user specif data based on login choice $global|$local.
133 *
134 * @param string $meta_key
135 * @param string $value;
136 * @return void
137 */
138 public static function update_user_specific_login_meta( $meta_key, $value ) {
139 return Login::get_link_my_account() ? self::update_user_meta( get_current_user_id(), $meta_key, $value ) : self::update_option( $meta_key, $value );
140 }
141
142 /**
143 * Get user speficic data based on login choiche $global|$local
144 *
145 * @param string $meta_key
146 * @return mixed
147 */
148 public static function get_user_specific_login_meta( $meta_key, $default = false, $single = true ) {
149 return Login::get_link_my_account() ? self::get_user_meta( get_current_user_id(), $meta_key, $default, $single ) : self::get_option( $meta_key, $default );
150 }
151
152 /**
153 * Delete user speficic data based on login choiche $global|$local
154 *
155 * @param string $meta_key
156 * @return mixed
157 */
158 public static function delete_user_specific_login_meta( $meta_key ) {
159 return Login::get_link_my_account() ? self::delete_user_meta( get_current_user_id(), $meta_key ) : self::delete_option( $meta_key );
160 }
161
162 }
163