PluginProbe
Additional Terms Lite for WooCommerce / 1.6.2
Additional Terms Lite for WooCommerce v1.6.2
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 1.6.2, at src/Settings/Options.php

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