-
Notifications
You must be signed in to change notification settings - Fork 1
/
buddypress-first-letter-avatar-config.php
269 lines (201 loc) · 9.47 KB
/
buddypress-first-letter-avatar-config.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
<?php
/*
PHP file containing whole back-end of the BuddyPress First Letter Avatar plugin.
BuddyPress First Letter Avatar prefix - 'bpfla'
*/
// Exit if accessed directly:
if (!defined('ABSPATH')){
exit;
}
class BuddyPress_First_Letter_Avatar_Config {
private $options;
public function __construct(){
add_action('admin_menu', array($this, 'add_admin_menu')); // add plugin settings page
add_action('admin_init', array($this, 'settings_init')); // create plugin settings page content
}
/*
* Add plugin settings page
*/
public function add_admin_menu(){
add_options_page('BuddyPress First Letter Avatar', 'BuddyPress First Letter Avatar', 'manage_options', 'buddypress_first_letter_avatar', array($this, 'options_page'));
}
/*
* Create plugin settings page content
*/
public function settings_init(){
register_setting('bpfla_pluginPage', 'bpfla_settings');
add_settings_section(
'bpfla_pluginPage_section',
__('Plugin configuration', 'buddypress-first-letter-avatar'),
array($this, 'settings_section_callback'),
'bpfla_pluginPage'
);
add_settings_field(
'bpfla_letter_index',
__('Letter index', 'buddypress-first-letter-avatar') . '<br/>' . __('Default:', 'buddypress-first-letter-avatar') . ' 0',
array($this, 'letter_index_render'),
'bpfla_pluginPage',
'bpfla_pluginPage_section'
);
add_settings_field(
'bpfla_file_format',
__('File format', 'buddypress-first-letter-avatar') . '<br/>' . __('Default:', 'buddypress-first-letter-avatar') . ' png',
array($this, 'file_format_render'),
'bpfla_pluginPage',
'bpfla_pluginPage_section'
);
add_settings_field(
'bpfla_unknown_image',
__('Unknown image name', 'buddypress-first-letter-avatar') . '<br/>' . __('Default:', 'buddypress-first-letter-avatar') . ' mystery',
array($this, 'unknown_image_render'),
'bpfla_pluginPage',
'bpfla_pluginPage_section'
);
add_settings_field(
'bpfla_avatar_set',
__('Avatar set', 'buddypress-first-letter-avatar') . '<br/>' . __('Default:', 'buddypress-first-letter-avatar') . ' default',
array($this, 'avatar_set_render'),
'bpfla_pluginPage',
'bpfla_pluginPage_section'
);
add_settings_field(
'bpfla_use_profile_avatar',
__("Use users' and groups' avatars", 'buddypress-first-letter-avatar') . '<br/>' . __('Default:', 'buddypress-first-letter-avatar') . ' ' . __('check', 'buddypress-first-letter-avatar'),
array($this, 'use_profile_avatar_render'),
'bpfla_pluginPage',
'bpfla_pluginPage_section'
);
add_settings_field(
'bpfla_use_gravatar',
__('Use Gravatar', 'buddypress-first-letter-avatar') . '<br/>' . __('Default:', 'buddypress-first-letter-avatar') . ' ' . __('check', 'buddypress-first-letter-avatar'),
array($this, 'use_gravatar_render'),
'bpfla_pluginPage',
'bpfla_pluginPage_section'
);
add_settings_field(
'bpfla_round_avatars',
__('Round avatars', 'buddypress-first-letter-avatar') . '<br/>' . __('Default:', 'buddypress-first-letter-avatar') . ' ' . __('uncheck', 'buddypress-first-letter-avatar'),
array($this, 'round_avatars_render'),
'bpfla_pluginPage',
'bpfla_pluginPage_section'
);
add_settings_field(
'bpfla_filter_priority',
__('Plugin filter priority', 'buddypress-first-letter-avatar') . '<br/>' . __('Default:', 'buddypress-first-letter-avatar') . ' 10',
array($this, 'filter_priority_render'),
'bpfla_pluginPage',
'bpfla_pluginPage_section'
);
}
/*
* Below methods are responsible for rendering each settings field
*/
public function letter_index_render(){
?>
<input style="width:40px;" type='text' name='bpfla_settings[bpfla_letter_index]' value='<?php if (array_key_exists('bpfla_letter_index', $this->options)) echo $this->options['bpfla_letter_index']; ?>' />
<?php
}
public function file_format_render(){
?>
<input style="width: 100px;" type='text' name='bpfla_settings[bpfla_file_format]' value='<?php if (array_key_exists('bpfla_file_format', $this->options)) echo $this->options['bpfla_file_format']; ?>' />
<?php
}
public function unknown_image_render(){
?>
<input type='text' name='bpfla_settings[bpfla_unknown_image]' value='<?php if (array_key_exists('bpfla_unknown_image', $this->options)) echo $this->options['bpfla_unknown_image']; ?>' />
<?php
}
public function avatar_set_render(){
?>
<input type='text' name='bpfla_settings[bpfla_avatar_set]' value='<?php if (array_key_exists('bpfla_avatar_set', $this->options)) echo $this->options['bpfla_avatar_set']; ?>' />
<?php
}
public function use_profile_avatar_render(){
?>
<input type='checkbox' name='bpfla_settings[bpfla_use_profile_avatar]' <?php if (array_key_exists('bpfla_use_profile_avatar', $this->options)) checked($this->options['bpfla_use_profile_avatar'], 1); ?> value='1' />
<?php
}
public function use_gravatar_render(){
?>
<input type='checkbox' name='bpfla_settings[bpfla_use_gravatar]' <?php if (array_key_exists('bpfla_use_gravatar', $this->options)) checked($this->options['bpfla_use_gravatar'], 1); ?> value='1' />
<?php
}
public function round_avatars_render(){
?>
<input type='checkbox' name='bpfla_settings[bpfla_round_avatars]' <?php if (array_key_exists('bpfla_round_avatars', $this->options)) checked($this->options['bpfla_round_avatars'], 1); ?> value='1' />
<?php
}
public function filter_priority_render(){
?>
<input type='text' name='bpfla_settings[bpfla_filter_priority]' value='<?php if (array_key_exists('bpfla_filter_priority', $this->options)) echo $this->options['bpfla_filter_priority']; ?>' />
<?php
}
/*
* Get plugin options from database
*/
public function settings_section_callback(){
$this->options = get_option('bpfla_settings');
}
/*
* Create a settings form
*/
public function options_page(){
?>
<form action='options.php' method='post'>
<h2>BuddyPress First Letter Avatar</h2>
<?php
settings_fields('bpfla_pluginPage');
do_settings_sections('bpfla_pluginPage');
submit_button();
?>
<hr />
<h3><?php _e('Fields description:', 'buddypress-first-letter-avatar'); ?></h3>
<p>
<strong><?php _e('Letter index', 'buddypress-first-letter-avatar'); ?></strong><br />
<?php echo sprintf(__('%s use first letter for the avatar; %s use second letter; %s use last letter, etc.', 'buddypress-first-letter-avatar'),
'<span style="text-decoration: underline">0</span>:', '<span style="text-decoration: underline">1</span>:', '<span style="text-decoration: underline">-1</span>:'); ?>
</p>
<p>
<strong><?php _e('File format', 'buddypress-first-letter-avatar'); ?></strong><br />
<?php echo sprintf(__('File format of your avatars, for example %s or %s.', 'buddypress-first-letter-avatar'),
'<span style="text-decoration: underline">png</span>', '<span style="text-decoration: underline">jpg</span>'); ?>
</p>
<p>
<strong><?php _e('Unknown image name', 'buddypress-first-letter-avatar'); ?></strong><br />
<?php _e('Name of the file used for unknown usernames (without extension).', 'buddypress-first-letter-avatar'); ?>
</p>
<p>
<strong><?php _e('Avatar set', 'buddypress-first-letter-avatar'); ?></strong><br />
<?php _e('Directory where your avatars are stored. Supplied sets: "default", "opensans" and "roboto".', 'buddypress-first-letter-avatar'); ?>
</p>
<p>
<strong><?php _e("Use users' and groups' avatars", 'buddypress-first-letter-avatar'); ?></strong><br />
<?php echo sprintf(__("%sCheck%s: use users' and groups' avatars when available; %sUncheck%s: use Gravatar or custom avatars.", 'buddypress-first-letter-avatar'),
'<span style="text-decoration: underline">', '</span>', '<span style="text-decoration: underline">', '</span>'); ?>
</p>
<p>
<strong><?php _e('Use Gravatar', 'buddypress-first-letter-avatar'); ?></strong><br />
<?php echo sprintf(__("%sCheck%s: use Gravatar when available; %sUncheck%s: use users' profile avatars or custom avatars.", 'buddypress-first-letter-avatar'),
'<span style="text-decoration: underline">', '</span>', '<span style="text-decoration: underline">', '</span>'); ?>
</p>
<p>
<strong><?php _e('Round avatars', 'buddypress-first-letter-avatar'); ?></strong><br />
<?php echo sprintf(__('%sCheck%s: use rounded avatars; %sUncheck%s: use standard avatars. This may not always work - your theme may override this setting.', 'buddypress-first-letter-avatar'),
'<span style="text-decoration: underline">', '</span>', '<span style="text-decoration: underline">', '</span>'); ?>
</p>
<p>
<strong><?php _e('Filter priority', 'buddypress-first-letter-avatar'); ?></strong><br />
<?php _e('If you are using multiple avatar plugins, you can increase or decrease execution priority of this plugin. If BuddyPress First Letter Avatar is overriding your other plugins, try changing this to a lower value (for example 9).', 'buddypress-first-letter-avatar'); ?>
</p>
<p><?php _e('In case of any problems, please use default values.', 'buddypress-first-letter-avatar'); ?></p>
<hr />
<p style="text-align: right; margin-right:30px"><?php
$ending_text = sprintf(__('If you like the plugin, please <a href="%s">leave a rating in WordPress Plugin Directory</a>!', 'buddypress-first-letter-avatar'), 'https://wordpress.org/support/view/plugin-reviews/buddypress-first-letter-avatar#postform');
$ending_text .= '<br />';
$ending_text .= sprintf(__('BuddyPress First Letter Avatar was created by <a href="%s">Daniel Wroblewski</a>', 'buddypress-first-letter-avatar'), 'http://dev49.net/');
echo $ending_text;
?></p>
</form>
<?php
}
}