| @@ -4,103 +4,103 @@ | ||
| 4 | 4 | |
| 5 | 5 | use WP_Error; |
| 6 | 6 | |
| 7 | 7 | class Database { |
| 8 | - /** | |
| 9 | - * Cache DB Data | |
| 10 | - * @var array | |
| 11 | - */ | |
| 12 | - private $cache = []; | |
| 8 | + /** | |
| 9 | + * Cache DB Data | |
| 10 | + * @var array | |
| 11 | + */ | |
| 12 | + private $cache = []; | |
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * Retrieves theme modification value for the active theme. | |
| 16 | - * | |
| 17 | - * @since 2.5.0 | |
| 18 | - * | |
| 19 | - * @param string $key | |
| 20 | - * @param mixed $default | |
| 21 | - * | |
| 22 | - * @return mixed | |
| 23 | - */ | |
| 24 | - public function get_theme_mod( $key, $default = false ) { | |
| 25 | - return get_theme_mod( $key, $default ); | |
| 26 | - } | |
| 14 | + /** | |
| 15 | + * Retrieves theme modification value for the active theme. | |
| 16 | + * | |
| 17 | + * @since 2.5.0 | |
| 18 | + * | |
| 19 | + * @param string $key | |
| 20 | + * @param mixed $default | |
| 21 | + * | |
| 22 | + * @return mixed | |
| 23 | + */ | |
| 24 | + public function get_theme_mod( $key, $default = false ) { | |
| 25 | + return get_theme_mod( $key, $default ); | |
| 26 | + } | |
| 27 | 27 | |
| 28 | - public function get( $key, $default = false ) { | |
| 29 | - if ( empty( $key ) ) { | |
| 30 | - return new WP_Error( 'invalid_key', __( 'Key cannot be empty.', 'betterdocs' ), ['status' => 404] ); | |
| 31 | - } | |
| 28 | + public function get( $key, $default = false ) { | |
| 29 | + if ( empty( $key ) ) { | |
| 30 | + return new WP_Error( 'invalid_key', __( 'Key cannot be empty.', 'betterdocs' ), [ 'status' => 404 ] ); | |
| 31 | + } | |
| 32 | 32 | |
| 33 | - if( ! isset( $this->cache[ $key ] ) ) { | |
| 34 | - $this->cache[ $key ] = get_option( $key, $default ); | |
| 35 | - } | |
| 33 | + if ( ! isset( $this->cache[ $key ] ) ) { | |
| 34 | + $this->cache[ $key ] = get_option( $key, $default ); | |
| 35 | + } | |
| 36 | 36 | |
| 37 | - // update the cache when new values are updated(for wpml specifically, other usecase might be available) | |
| 38 | - if ( $this->cache[$key] != get_option( $key, $default ) ) { | |
| 39 | - $this->cache[$key] = get_option( $key, $default ); | |
| 40 | - } | |
| 37 | + // update the cache when new values are updated(for wpml specifically, other usecase might be available) | |
| 38 | + if ( $this->cache[ $key ] != get_option( $key, $default ) ) { | |
| 39 | + $this->cache[ $key ] = get_option( $key, $default ); | |
| 40 | + } | |
| 41 | 41 | |
| 42 | - return $this->cache[$key]; | |
| 43 | - } | |
| 42 | + return $this->cache[ $key ]; | |
| 43 | + } | |
| 44 | 44 | |
| 45 | - /** | |
| 46 | - * Summary of save | |
| 47 | - * @param mixed $key | |
| 48 | - * @param mixed $value | |
| 49 | - * @return bool | |
| 50 | - */ | |
| 51 | - public function save( $key, $value ) { | |
| 52 | - $_updated = update_option( $key, $value, 'no' ); | |
| 45 | + /** | |
| 46 | + * Summary of save | |
| 47 | + * @param mixed $key | |
| 48 | + * @param mixed $value | |
| 49 | + * @return bool | |
| 50 | + */ | |
| 51 | + public function save( $key, $value ) { | |
| 52 | + $_updated = update_option( $key, $value, 'no' ); | |
| 53 | 53 | |
| 54 | - if( $_updated ) { | |
| 55 | - $this->cache[ $key ] = $value; | |
| 56 | - } | |
| 54 | + if ( $_updated ) { | |
| 55 | + $this->cache[ $key ] = $value; | |
| 56 | + } | |
| 57 | 57 | |
| 58 | - return $_updated; | |
| 59 | - } | |
| 58 | + return $_updated; | |
| 59 | + } | |
| 60 | 60 | |
| 61 | - /** | |
| 62 | - * Summary of get_cache | |
| 63 | - * @param string|int $key | |
| 64 | - * @param bool $force | |
| 65 | - * @param string $group | |
| 66 | - * @return bool|mixed | |
| 67 | - */ | |
| 68 | - public function get_cache( $key, $force = false, $group = 'betterdocs' ) { | |
| 69 | - return wp_cache_get( $key, $group, $force ); | |
| 70 | - } | |
| 61 | + /** | |
| 62 | + * Summary of get_cache | |
| 63 | + * @param string|int $key | |
| 64 | + * @param bool $force | |
| 65 | + * @param string $group | |
| 66 | + * @return bool|mixed | |
| 67 | + */ | |
| 68 | + public function get_cache( $key, $force = false, $group = 'betterdocs' ) { | |
| 69 | + return wp_cache_get( $key, $group, $force ); | |
| 70 | + } | |
| 71 | 71 | |
| 72 | - /** | |
| 73 | - * Set cache | |
| 74 | - * | |
| 75 | - * @param string $key | |
| 76 | - * @param mixed $value | |
| 77 | - * @param int $expire | |
| 78 | - * @param string $group | |
| 79 | - * @return bool | |
| 80 | - */ | |
| 81 | - public function set_cache( $key, $value, $expire = 2, $group = 'betterdocs' ) { | |
| 82 | - $expire = $expire * DAY_IN_SECONDS; | |
| 83 | - return wp_cache_set( $key, $value, $group, $expire ); | |
| 84 | - } | |
| 72 | + /** | |
| 73 | + * Set cache | |
| 74 | + * | |
| 75 | + * @param string $key | |
| 76 | + * @param mixed $value | |
| 77 | + * @param int $expire | |
| 78 | + * @param string $group | |
| 79 | + * @return bool | |
| 80 | + */ | |
| 81 | + public function set_cache( $key, $value, $expire = 2, $group = 'betterdocs' ) { | |
| 82 | + $expire = $expire * DAY_IN_SECONDS; | |
| 83 | + return wp_cache_set( $key, $value, $group, $expire ); | |
| 84 | + } | |
| 85 | 85 | |
| 86 | - public function flush_cache( $group = 'betterdocs' ){ | |
| 87 | - if( function_exists('wp_cache_flush_group') ) { | |
| 88 | - wp_cache_flush_group( $group ); | |
| 89 | - } else { | |
| 90 | - // @todo need to do by cache_key | |
| 91 | - } | |
| 92 | - } | |
| 86 | + public function flush_cache( $group = 'betterdocs' ) { | |
| 87 | + if ( function_exists( 'wp_cache_flush_group' ) ) { | |
| 88 | + wp_cache_flush_group( $group ); | |
| 89 | + } else { | |
| 90 | + // @todo need to do by cache_key | |
| 91 | + } | |
| 92 | + } | |
| 93 | 93 | |
| 94 | - public function set_transient( $transient, $value, $expiration = null ) { | |
| 95 | - $expiration = $expiration == null ? MINUTE_IN_SECONDS : $expiration; | |
| 96 | - return set_transient( $transient, $value, $expiration ); | |
| 97 | - } | |
| 94 | + public function set_transient( $transient, $value, $expiration = null ) { | |
| 95 | + $expiration = $expiration == null ? MINUTE_IN_SECONDS : $expiration; | |
| 96 | + return set_transient( $transient, $value, $expiration ); | |
| 97 | + } | |
| 98 | 98 | |
| 99 | - public function get_transient( $transient ) { | |
| 100 | - return get_transient( $transient ); | |
| 101 | - } | |
| 99 | + public function get_transient( $transient ) { | |
| 100 | + return get_transient( $transient ); | |
| 101 | + } | |
| 102 | 102 | |
| 103 | - public function delete_transient( $transient ) { | |
| 104 | - return delete_transient( $transient ); | |
| 105 | - } | |
| 103 | + public function delete_transient( $transient ) { | |
| 104 | + return delete_transient( $transient ); | |
| 105 | + } | |
| 106 | 106 | } |