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

160 lines 3.5 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 /**
41 * Update|Set user meta.
42 *
43 * @param int $user_id
44 * @param string $meta_key
45 * @param mixed $meta_value
46 */
47 public static function update_user_meta( $user_id, $meta_key, $meta_value ) {
48
49 if ( ! $user_id ) {
50 $user_id = get_current_user_id();
51 }
52
53 $user_id = absint( $user_id );
54 $meta_key = trim( $meta_key );
55
56 if ( ! $user_id && empty( $meta_key ) ) {
57 return false;
58 }
59
60 return \update_user_meta( $user_id, $meta_key, $meta_value );
61 }
62
63 /**
64 * Get an option
65 *
66 * @param int $user_id
67 * @param string $meta_key
68 * @param bool $single
69 */
70 public static function get_user_meta( $user_id, $meta_key, $default = false, $single = true ) {
71
72 if ( ! $user_id ) {
73 $user_id = get_current_user_id();
74 }
75
76 $user_id = absint( $user_id );
77 $meta_key = trim( $meta_key );
78
79 if ( ! $user_id && empty( $meta_key ) ) {
80 return false;
81 }
82
83 $res = \get_user_meta( $user_id, $meta_key, $single );
84
85 return ( ! $res ) ? $default : $res;
86
87 }
88
89 /**
90 * Delete a user meta.
91 *
92 * @param int $user_id
93 * @param string $meta_key
94 */
95 public static function delete_user_meta( $user_id, $meta_key ) {
96
97 if ( ! $user_id ) {
98 return false;
99 }
100
101 $user_id = absint( $user_id );
102 $meta_key = trim( $meta_key );
103
104 if ( ! $user_id && empty( $meta_key ) ) {
105 return false;
106 }
107
108 return \delete_user_meta( $user_id, $meta_key );
109
110 }
111
112 /**
113 * Delete an option
114 *
115 * @param string $key
116 *
117 * @return void
118 */
119 public static function delete_option( $key ) {
120 $trimmed_key = trim( $key );
121 if ( ! empty( $trimmed_key ) ) {
122 return \delete_option( $trimmed_key );
123 }
124
125 return false;
126 }
127
128 /**
129 * Update user specif data based on login choice $global|$local.
130 *
131 * @param string $meta_key
132 * @param string $value;
133 * @return void
134 */
135 public static function update_user_specific_login_meta( $meta_key, $value ) {
136 return Login::get_link_my_account() ? self::update_user_meta( get_current_user_id(), $meta_key, $value ) : self::update_option( $meta_key, $value );
137 }
138
139 /**
140 * Get user speficic data based on login choiche $global|$local
141 *
142 * @param string $meta_key
143 * @return mixed
144 */
145 public static function get_user_specific_login_meta( $meta_key, $default = false, $single = true ) {
146 return Login::get_link_my_account() ? self::get_user_meta( get_current_user_id(), $meta_key, $default, $single ) : self::get_option( $meta_key, $default );
147 }
148
149 /**
150 * Delete user speficic data based on login choiche $global|$local
151 *
152 * @param string $meta_key
153 * @return mixed
154 */
155 public static function delete_user_specific_login_meta( $meta_key ) {
156 return Login::get_link_my_account() ? self::delete_user_meta( get_current_user_id(), $meta_key ) : self::delete_option( $meta_key );
157 }
158
159 }
160