essential-addons-for-elementor-lite
/
vendor
/
priyomukul
/
wp-notice
/
src
/
Utils
Last commit date
Base.php
2 years ago
CacheBank.php
2 years ago
Helper.php
2 years ago
NoticeRemover.php
2 years ago
Storage.php
2 years ago
Storage.php
58 lines
| 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 | } |