-
Notifications
You must be signed in to change notification settings - Fork 1
/
bbppu-settings.php
198 lines (147 loc) · 6.37 KB
/
bbppu-settings.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
<?php
class bbP_Pencil_Unread_Settings {
static $menu_slug = 'bbppu';
var $menu_page;
function __construct() {
add_action( 'admin_menu', array( $this, 'create_admin_menu' ) );
add_action( 'admin_init', array( $this, 'settings_init' ) );
}
function create_admin_menu(){
$menu_page = add_options_page(
__( 'bbPress Pencil Unread', 'bbppu' ), //page title - I never understood why this parameter is needed for. Put what you like ?
__( 'bbPress Pencil Unread', 'bbppu' ), //menu title
'manage_options', //cappability
self::$menu_slug,
array($this,'settings_page') //this function will output the content of the 'Music' page.
);
}
function settings_sanitize( $input ){
$new_input = array();
if( isset( $input['reset_options'] ) ){
$new_input = bbppu()->options_default;
}else{ //sanitize values
//test registration time
$new_input['forums_marks'] = ( isset($input['forums_marks']) ) ? 'on' : 'off';
$new_input['test_registration_time'] = ( isset($input['test_registration_time']) ) ? 'on' : 'off';
$new_input['bookmarks'] = ( isset($input['bookmarks']) ) ? 'on' : 'off';
}
//remove default values
foreach((array)$input as $slug => $value){
$default = bbppu()->get_default_option($slug);
if ($value == $default) unset ($input[$slug]);
}
//$new_input = array_filter($new_input); //disabled here because this will remove '0' values
return $new_input;
}
function settings_init(){
register_setting(
'bbppu_option_group', // Option group
bbppu()->options_metaname, // Option name
array( $this, 'settings_sanitize' ) // Sanitize
);
add_settings_section(
'settings_general', // ID
__('General','bbppu'), // Title
array( $this, 'bbppu_settings_general_desc' ), // Callback
'bbppu-settings-page' // Page
);
add_settings_field(
'marks',
__('Enable forums marks','bbppu'),
array( $this, 'enable_forums_marks_callback' ),
'bbppu-settings-page', // Page
'settings_general'//section
);
add_settings_field(
'test_registration_time',
__('Registration date check','bbppu'),
array( $this, 'test_registration_time_callback' ),
'bbppu-settings-page', // Page
'settings_general'//section
);
add_settings_field(
'bookmarks',
__('Enable bookmarks','bbppu'),
array( $this, 'enable_bookmark_callback' ),
'bbppu-settings-page', // Page
'settings_general'//section
);
add_settings_section(
'settings_system', // ID
__('System','bbppu'), // Title
array( $this, 'bbppu_settings_system_desc' ), // Callback
'bbppu-settings-page' // Page
);
add_settings_field(
'reset_options',
__('Reset Options','bbppu'),
array( $this, 'reset_options_callback' ),
'bbppu-settings-page', // Page
'settings_system'//section
);
}
function bbppu_settings_general_desc(){
}
function enable_forums_marks_callback(){
$option = bbppu()->get_options('forums_marks');
printf(
'<input type="checkbox" name="%s[forums_marks]" value="on" %s /> %s',
bbppu()->options_metaname,
checked( $option, 'on', false ),
__("Display a 'Mark as read' link in forums that marks all their topics","bbppu")
);
}
function test_registration_time_callback(){
$option = bbppu()->get_options('test_registration_time');
printf(
'<input type="checkbox" name="%s[test_registration_time]" value="on" %s /> %s',
bbppu()->options_metaname,
checked( $option, 'on', false ),
__("Items older than the registration date of the user should be marked as read.","bbppu")
);
}
function enable_bookmark_callback(){
$option = bbppu()->get_options('bookmarks');
printf(
'<input type="checkbox" name="%s[bookmarks]" value="on" %s /> %s',
bbppu()->options_metaname,
checked( $option, 'on', false ),
sprintf(__("Add bookmarks links %s after the topic title; to jump to the last read reply","bbppu"),'<code><span class="dashicons dashicons-flag"></span></code>')
);
}
function bbppu_settings_system_desc(){
}
function reset_options_callback(){
printf(
'<input type="checkbox" name="%1$s[reset_options]" value="on"/> %2$s',
bbppu()->options_metaname, // Option name
__("Reset options to their default values.","bbppu")
);
}
function settings_page() {
?>
<div class="wrap">
<h2><?php _e('bbPress Pencil Unread Settings','bbppu');?></h2>
<div>
<?php
$rate_link_wp = 'https://wordpress.org/support/view/plugin-reviews/bbpress-pencil-unread?rate#postform';
$rate_link = '<a href="'.$rate_link_wp.'" target="_blank" href=""><i class="fa fa-star"></i> '.__('Reviewing it','bbppu').'</a>';
$donate_link = '<a href="http://bit.ly/gbreant" target="_blank" href=""><i class="fa fa-usd"></i> '.__('make a donation','bbppu').'</a>';
echo '<p><em>'.sprintf(__('Great experience with this plugin ? %s and %s would help us maintaining it !','bbppu'),$rate_link,$donate_link).'</em></p>';
?>
</div>
<hr/>
<?php settings_errors('bbppu_option_group');?>
<form method="post" action="options.php">
<?php
// This prints out all hidden setting fields
settings_fields( 'bbppu_option_group' );
do_settings_sections( 'bbppu-settings-page' );
submit_button();
?>
</form>
</div>
<?php
}
}
new bbP_Pencil_Unread_Settings;