-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.php
406 lines (393 loc) · 13 KB
/
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?php
/**
* cbnet Different Posts Per Page Plugin Options
*
* This file defines the Options for the cbnet Different Posts Per Page Plugin.
*
* Plugin Options Functions
*
* - Define Default Plugin Options
* - Register/Initialize Plugin Options
* - Define Admin Settings Page
* - Register Contextual Help
*
* @package cbnetdppp
* @copyright Copyright (c) 2012, Chip Bennett
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer)
*
* @since cbnetdppp 2.0
*/
/**
* Globalize the variable that holds the Plugin Options
*
* @global array $cbnetdppp_options holds Plugin options
*/
global $cbnetdppp_options;
/**
* cbnetdppp Plugin Settings API Implementation
*
* Implement the WordPress Settings API for the
* cbnetdppp Plugin Settings.
*
* @link http://codex.wordpress.org/Settings_API Codex Reference: Settings API
* @link http://ottopress.com/2009/wordpress-settings-api-tutorial/ Otto
* @link http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/ Ozh
*/
function cbnetdppp_register_options(){
require( plugin_dir_path( __FILE__ ) . 'options-register.php' );
}
// Settings API options initilization and validation
add_action( 'admin_init', 'cbnetdppp_register_options' );
/**
* Get cbnetdppp Plugin Options
*
* Array that holds all of the defined values
* for cbnetdppp Plugin options. If the user
* has not specified a value for a given Plugin
* option, then the option's default value is
* used instead.
*
* @uses cbnetdppp_get_option_defaults() defined in \functions\options.php
*
* @uses get_option()
* @uses wp_parse_args()
*
* @return array $cbnetdppp_options current values for all Plugin options
*/
function cbnetdppp_get_options() {
// Get option default values
$default_options = cbnetdppp_get_option_defaults();
// Get user-configured option values
global $cbnetdppp_options;
// Use user-configured option value;
// if not defined, use the default value
$cbnetdppp_options = wp_parse_args( get_option( 'plugin_cbnetdppp_options', array() ), $default_options );
// Return option values
return $cbnetdppp_options;
}
/**
* cbnetdppp Plugin Option Defaults
*
* Returns an associative array that holds
* all of the default values for all Plugin
* options.
*
* @uses cbnetdppp_get_option_parameters() defined in \functions\options.php
*
* @return array $defaults associative array of option defaults
*/
function cbnetdppp_get_option_defaults() {
$parameters = cbnetdppp_get_option_parameters();
$defaults = array();
foreach ( $parameters as $parameter ) {
$name = $parameter['name'];
$defaults[$name] = $parameter['default'];
}
return apply_filters( 'cbnetdppp_option_defaults', $defaults );
}
/**
* cbnetdppp Plugin Option Parameters
*
* Array that holds parameters for all options for
* cbnetdppp. The 'type' key is used to generate
* the proper form field markup and to sanitize
* the user-input data properly. The 'tab' key
* determines the Settings Page on which the
* option appears, and the 'section' tab determines
* the section of the Settings Page tab in which
* the option appears.
*
* @return array $options array of arrays of option parameters
*/
function cbnetdppp_get_option_parameters() {
$parameters = array(
// Search Index Page Options
'search_posts_per_page' => array(
'name' => 'search_posts_per_page',
'title' => __( 'Posts per page', 'cbnetdpp' ),
'type' => 'text',
'sanitize' => 'integer',
'section' => 'search_index',
'default' => cbnetdppp_get_default_posts_per_page(),
),
'search_order' => array(
'name' => 'search_order',
'title' => __( 'Order', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_order_options(),
'section' => 'search_index',
'default' => cbnetdppp_get_default_order(),
),
'search_orderby' => array(
'name' => 'search_orderby',
'title' => __( 'Order By', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_orderby_options(),
'section' => 'search_index',
'default' => cbnetdppp_get_default_orderby(),
),
// Blog Posts Index Page Options
'blog_posts_per_page' => array(
'name' => 'blog_posts_per_page',
'title' => __( 'Posts per page', 'cbnetdpp' ),
'type' => 'text',
'sanitize' => 'integer',
'section' => 'blog_index',
'default' => cbnetdppp_get_default_posts_per_page(),
),
'blog_order' => array(
'name' => 'blog_order',
'title' => __( 'Order', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_order_options(),
'section' => 'blog_index',
'default' => cbnetdppp_get_default_order(),
),
'blog_orderby' => array(
'name' => 'blog_orderby',
'title' => __( 'Order By', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_orderby_options(),
'section' => 'blog_index',
'default' => cbnetdppp_get_default_orderby(),
),
// Category Archive Index Page Options
'category_posts_per_page' => array(
'name' => 'category_posts_per_page',
'title' => __( 'Posts per page', 'cbnetdpp' ),
'type' => 'text',
'sanitize' => 'integer',
'section' => 'category_index',
'default' => cbnetdppp_get_default_posts_per_page(),
),
'category_order' => array(
'name' => 'category_order',
'title' => __( 'Order', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_order_options(),
'section' => 'category_index',
'default' => cbnetdppp_get_default_order(),
),
'category_orderby' => array(
'name' => 'category_orderby',
'title' => __( 'Order By', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_orderby_options(),
'section' => 'category_index',
'default' => cbnetdppp_get_default_orderby(),
),
// Tag Archive Index Page Options
'tag_posts_per_page' => array(
'name' => 'tag_posts_per_page',
'title' => __( 'Posts per page', 'cbnetdpp' ),
'type' => 'text',
'sanitize' => 'integer',
'section' => 'tag_index',
'default' => cbnetdppp_get_default_posts_per_page(),
),
'tag_order' => array(
'name' => 'tag_order',
'title' => __( 'Order', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_order_options(),
'section' => 'tag_index',
'default' => cbnetdppp_get_default_order(),
),
'tag_orderby' => array(
'name' => 'tag_orderby',
'title' => __( 'Order By', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_orderby_options(),
'section' => 'tag_index',
'default' => cbnetdppp_get_default_orderby(),
),
// Taxonomy Archive Index Page Options
'taxonomy_posts_per_page' => array(
'name' => 'taxonomy_posts_per_page',
'title' => __( 'Posts per page', 'cbnetdpp' ),
'type' => 'text',
'sanitize' => 'integer',
'section' => 'taxonomy_index',
'default' => cbnetdppp_get_default_posts_per_page(),
),
'taxonomy_order' => array(
'name' => 'taxonomy_order',
'title' => __( 'Order', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_order_options(),
'section' => 'taxonomy_index',
'default' => cbnetdppp_get_default_order(),
),
'taxonomy_orderby' => array(
'name' => 'taxonomy_orderby',
'title' => __( 'Order By', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_orderby_options(),
'section' => 'taxonomy_index',
'default' => cbnetdppp_get_default_orderby(),
),
// Author Archive Index Page Options
'author_posts_per_page' => array(
'name' => 'author_posts_per_page',
'title' => __( 'Posts per page', 'cbnetdpp' ),
'type' => 'text',
'sanitize' => 'integer',
'section' => 'author_index',
'default' => cbnetdppp_get_default_posts_per_page(),
),
'author_order' => array(
'name' => 'author_order',
'title' => __( 'Order', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_order_options(),
'section' => 'author_index',
'default' => cbnetdppp_get_default_order(),
),
'author_orderby' => array(
'name' => 'author_orderby',
'title' => __( 'Order By', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_orderby_options(),
'section' => 'author_index',
'default' => cbnetdppp_get_default_orderby(),
),
// Date Archive Index Page Options
'date_posts_per_page' => array(
'name' => 'date_posts_per_page',
'title' => __( 'Posts per page', 'cbnetdpp' ),
'type' => 'text',
'sanitize' => 'integer',
'section' => 'date_index',
'default' => cbnetdppp_get_default_posts_per_page(),
),
'date_order' => array(
'name' => 'date_order',
'title' => __( 'Order', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_order_options(),
'section' => 'date_index',
'default' => cbnetdppp_get_default_order(),
),
'date_orderby' => array(
'name' => 'date_orderby',
'title' => __( 'Order By', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_orderby_options(),
'section' => 'date_index',
'default' => cbnetdppp_get_default_orderby(),
),
// Archive Index Page Options
'archive_posts_per_page' => array(
'name' => 'archive_posts_per_page',
'title' => __( 'Posts per page', 'cbnetdpp' ),
'type' => 'text',
'sanitize' => 'integer',
'section' => 'archive_index',
'default' => cbnetdppp_get_default_posts_per_page(),
),
'archive_order' => array(
'name' => 'archive_order',
'title' => __( 'Order', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_order_options(),
'section' => 'archive_index',
'default' => cbnetdppp_get_default_order(),
),
'archive_orderby' => array(
'name' => 'archive_orderby',
'title' => __( 'Order By', 'cbnetdpp' ),
'type' => 'select',
'valid_options' => cbnetdppp_get_orderby_options(),
'section' => 'archive_index',
'default' => cbnetdppp_get_default_orderby(),
),
);
return apply_filters( 'cbnetdppp_option_parameters', $parameters );
}
/**
* cbnetdppp Plugin Admin Settings Page Sections
*
* Array that holds all of the tabs for the
* cbnetdppp Plugin Settings Page. Each tab
* key holds an array that defines the
* sections for each tab, including the
* description text.
*
* @return array $tabs array of arrays of section parameters
*/
function cbnetdppp_get_options_page_sections() {
$sections = array(
'search_index' => array(
'name' => 'search_index',
'title' => __( 'Search Index Page', 'cbnetdpp' ),
'description' => __( 'Set query options for the Search index page.', 'cbnetdppp' ),
),
'blog_index' => array(
'name' => 'blog_index',
'title' => __( 'Blog Posts Index Page', 'cbnetdpp' ),
'description' => __( 'Set query options for the Blog Posts Index page.', 'cbnetdppp' ),
),
'category_index' => array(
'name' => 'category_index',
'title' => __( 'Category Archive Index Page', 'cbnetdpp' ),
'description' => __( 'Set query options for the Category archive index page.', 'cbnetdppp' ),
),
'tag_index' => array(
'name' => 'tag_index',
'title' => __( 'Tag Archive Index Page', 'cbnetdpp' ),
'description' => __( 'Set query options for the Tag archive index page.', 'cbnetdppp' ),
),
'taxonomy_index' => array(
'name' => 'taxonomy_index',
'title' => __( 'Taxonomy Archive Index Page', 'cbnetdpp' ),
'description' => __( 'Set query options for the Taxonomy archive index page.', 'cbnetdppp' ),
),
'author_index' => array(
'name' => 'author_index',
'title' => __( 'Author Archive Index Page', 'cbnetdpp' ),
'description' => __( 'Set query options for the Author archive index page.', 'cbnetdppp' ),
),
'date_index' => array(
'name' => 'date_index',
'title' => __( 'Date Archive Index Page', 'cbnetdpp' ),
'description' => __( 'Set query options for the Date archive index page.', 'cbnetdppp' ),
),
'archive_index' => array(
'name' => 'archive_index',
'title' => __( 'Archive Index Page', 'cbnetdpp' ),
'description' => __( 'Set query options for the default Archive index page.', 'cbnetdppp' ),
),
);
return apply_filters( 'cbnetdppp_sections', $sections );
}
function cbnetdppp_get_orderby_options() {
$orderby_options = array(
'none' => __( 'None', 'cbnetdppp' ),
'ID' => __( 'Post ID', 'cbnetdppp' ),
'author' => __( 'Post Author', 'cbnetdppp' ),
'title' => __( 'Post Title', 'cbnetdppp' ),
'name' => __( 'Post Slug', 'cbnetdppp' ),
'date' => __( 'Post Published Date', 'cbnetdppp' ),
'modified' => __( 'Post Modified Date', 'cbnetdppp' ),
'rand' => __( 'Random', 'cbnetdppp' ),
'comment_count' => __( 'Post Comment Count', 'cbnetdppp' ),
);
return apply_filters( 'cbnetdppp_orderby_options', $orderby_options );
}
function cbnetdppp_get_order_options() {
$order_options = array(
'ASC' => __( 'Ascending', 'cbnetdppp' ),
'DESC' => __( 'Descending', 'cbnetdppp' ),
);
return apply_filters( 'cbnetdppp_order_options', $order_options );
}
function cbnetdppp_get_default_posts_per_page() {
return apply_filters( 'cbnetdppp_default_posts_per_page', get_option( 'posts_per_page' ) );
}
function cbnetdppp_get_default_order() {
return apply_filters( 'cbnetdppp_default_order', 'DESC' );
}
function cbnetdppp_get_default_orderby() {
return apply_filters( 'cbnetdppp_default_orderby', 'date' );
}
?>