PluginProbe
Additional Terms Lite for WooCommerce / trunk
Additional Terms Lite for WooCommerce vtrunk
1.7.3 1.7.2.1 trunk 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 All 35 releases
woo-additional-terms / src / Settings / Options.php

Options.php in Additional Terms Lite for WooCommerce trunk, at src/Settings/Options.php

108 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin options class.
4 *
5 * @since 1.6.0
6 *
7 * @package woo-additional-terms
8 */
9
10 namespace Woo_Additional_Terms\Settings;
11
12 use Woo_Additional_Terms\Installer;
13
14 /**
15 * Options class.
16 */
17 class Options {
18
19 /**
20 * The plugin options name.
21 *
22 * @since 1.6.0
23 *
24 * @var string
25 */
26 const OPTION_NAME = 'woo_additional_terms_options';
27
28 /**
29 * The activation timestamp option name.
30 *
31 * @since 1.4.1
32 *
33 * @var string
34 */
35 const TIMESTAMP_OPTION_NAME = 'woo_additional_terms_activation_timestamp';
36
37 /**
38 * Get the plugin options.
39 *
40 * @since 1.6.0
41 *
42 * @param string $key The option key.
43 * @param mixed $default The default value.
44 *
45 * @return string|array
46 */
47 public function get( $key = '', $default = null ) {
48
49 $options = (array) get_option( self::OPTION_NAME, array() );
50
51 if ( empty( $key ) ) {
52 return $options;
53 }
54
55 return empty( $options[ $key ] ) ? $default : $options[ $key ];
56 }
57
58 /**
59 * Update the plugin options.
60 *
61 * @since 1.6.0
62 *
63 * @param array $value The new options value.
64 *
65 * @return array
66 */
67 public function update( $value ) {
68
69 // Bail early if the value is not an array or empty.
70 if ( ! is_array( $value ) || empty( $value ) ) {
71 return array();
72 }
73
74 update_option( self::OPTION_NAME, $value );
75
76 return $value;
77 }
78
79 /**
80 * Get the plugin activation timestamp.
81 *
82 * @since 1.6.0
83 *
84 * @return int
85 */
86 public function get_usage_timestamp() {
87
88 return (int) get_site_option( self::TIMESTAMP_OPTION_NAME, 0 );
89 }
90
91 /**
92 * Store a timestamp option on plugin activation.
93 *
94 * @since 1.4.1
95 *
96 * @return void
97 */
98 public function add_usage_timestamp() {
99
100 $activation_timestamp = get_site_option( self::TIMESTAMP_OPTION_NAME );
101
102 // Store the activation timestamp if it doesn't exist.
103 if ( ! $activation_timestamp ) {
104 add_site_option( self::TIMESTAMP_OPTION_NAME, time() );
105 }
106 }
107 }
108