-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass-mint-ab-testing-options.php
195 lines (163 loc) · 3.48 KB
/
class-mint-ab-testing-options.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* Handles get/set of plugin options and WordPress options page
*
* @since 0.9.0.0
* @version 0.9.0.7
*/
class Mint_AB_Testing_Options
{
/**
* String to use for the plugin name. Used for generating class names, etc.
*
* @since 0.9.0.0
* @version 0.9.0.6
*
* @constant string
*/
const plugin_id = 'mint-ab-testing';
/**
*
*
* @since 0.9.0.3
* @version 0.9.0.6
*
* @constant string
*/
const cookie_name = 'mint_alternate_theme';
/**
*
*
* @since 0.9.0.7
* @version 0.9.0.7
*
* @constant string
*/
const referrer_cookie_name = 'mint_ab_referrer';
/**
* Name of the option group for WordPress settings API
*
* @since 0.9.0.0
* @version 0.9.0.6
*
* @constant string
*/
const option_group = 'mint-ab-testing-group';
/**
* Name of the option for WordPress settings API
*
* @since 0.9.0.0
* @version 0.9.0.6
*
* @constant string
*/
const option_name = 'mint_ab_testing_options';
/**
* Contains default options that get overridden in the constructor
*
* @since 0.9.0.0
* @version 0.9.0.7
*
* @var array
*/
protected $_options_defaults = array(
'enable' => 'no',
'ratio' => 50,
'alternate_theme' => 'Twenty Ten',
'cookie_ttl' => 0,
'endpoint' => 'v02',
'javascript_redirect' => 0,
'entrypoints' => array(
'home' => true,
'singular' => true, // post, page, attachment, custom post type
'archive' => true, // tag, category, custom post type archive, author
'search' => true,
'404' => true,
),
);
/**
* Contains merged defaults + saved options
*
*
* @since 0.9.0.0
* @version 0.9.0.6
* @var array
*/
protected $_options = array();
/**
* Hook into actions and filters here, along with any other global setup
* that needs to run when this plugin is invoked
*
* @since 0.9.0.0
* @version 0.9.0.6
*/
public function __construct() {
$this->_setup_options();
}
/**
* Merge the saved options with the defaults
*
* @since 0.9.0.3
* @version 0.9.0.6
*/
protected function _setup_options() {
$this->_options = array_merge( $this->_options_defaults, get_option( self::option_name, array() ) );
}
/**
* Returns Singleton instance of this class. Singleton pattern is used to pass
* options back and forth between the Options class and the business logic class, via
* static methods. This overcomes some of the limitations of working with a
* procedural framework.
*
* The singleton pattern isn't necessary for the rest of the Options class --
* rendering settings pages, etc.
*
* @since 0.9.0.0
* @version 0.9.0.6
*
* @return Mint_AB_Testing_Options
*/
public static function instance()
{
static $_instance = null;
if ( is_null( $_instance ) ) {
$class = __CLASS__;
$_instance = new $class();
}
return $_instance;
}
/**
* Get default value
*
* @since 0.9.0.7
* @version 0.9.0.7
*/
public function get_option_default( $option_key = '' ) {
if ( isset( $this->_options_defaults[$option_key] ) ) {
return $this->_options_defaults[$option_key];
}
return null;
}
/**
* Plugin option getter
*
* @since 0.9.0.0
* @version 0.9.0.6
*/
public function get_option( $option_key = '' ) {
if ( isset( $this->_options[$option_key] ) ) {
return $this->_options[$option_key];
}
return null;
}
/**
* Plugin option setter
*
* @since 0.9.0.0
* @version 0.9.0.6
*/
public function set_option( $option_key, $option_value = '' ) {
$this->_options[$option_key] = $option_value;
}
}
// EOF