PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 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 All 112 releases
templately / vendor / priyomukul / wp-notice / src / Utils / Storage.php

Storage.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at vendor/priyomukul/wp-notice/src/Utils/Storage.php

58 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PriyoMukul\WPNotice\Utils;
4
5 use function property_exists;
6
7 #[\AllowDynamicProperties]
8 class Storage extends Base {
9 private $id = 'wpnotice';
10 private $type = 'options';
11 private $version = '1.1.0';
12 private $storage_key = 'notices';
13
14 public function __construct( $args ) {
15 $this->id = ! empty( $args['id'] ) ? $args['id'] : $this->id;
16 $this->type = ! empty( $args['store'] ) ? $args['store'] : $this->type;
17 $this->storage_key = ! empty( $args['storage_key'] ) ? $this->id . '_' . $args['storage_key'] : "{$this->id}_{$this->storage_key}";
18 }
19
20 public function __get( $name ) {
21 return property_exists( $this, $name ) ? $this->$name : null;
22 }
23
24 public function save( $value, $key = '' ) {
25 if ( empty( $key ) ) {
26 $key = $this->storage_key;
27 $value['version'] = $this->version;
28 }
29
30 if ( $this->type === 'options' ) {
31 return update_site_option( $key, $value );
32 }
33
34 return false;
35 }
36
37 public function get( $key = '', $default = false ) {
38 $key = empty( $key ) ? $this->storage_key : $key;
39
40 if ( $this->type === 'options' ) {
41 return get_site_option( $key, $default );
42 }
43
44 return $default;
45 }
46
47 public function save_meta( $id, $value = true ) {
48 return update_user_meta( get_current_user_id(), "{$this->id}_{$id}_notice_dismissed", $value );
49 }
50
51 public function get_meta( $id ) {
52 return boolval( get_user_meta( get_current_user_id(), "{$this->id}_{$id}_notice_dismissed", true ) );
53 }
54
55 public function remove_meta( $id ) {
56 return delete_user_meta( get_current_user_id(), "{$this->id}_{$id}_notice_dismissed" );
57 }
58 }