PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.8
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.8
8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 All 46 releases
gamipress / integrations / buddypress / includes / admin.php

admin.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at integrations/buddypress/includes/admin.php

876 lines 39.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin
4 *
5 * @package GamiPress\BuddyPress\Admin
6 * @since 1.0.3
7 */
8
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 require_once GAMIPRESS_BP_DIR . 'includes/admin/recount-activity.php';
13
14 /**
15 * Shortcut function to get plugin options
16 *
17 * @since 1.0.8
18 *
19 * @param string $option_name
20 * @param bool $default
21 *
22 * @return mixed
23 */
24 function gamipress_bp_get_option( $option_name, $default = false ) {
25
26 $prefix = 'bp_';
27
28 return gamipress_get_option( $prefix . $option_name, $default );
29 }
30
31 /**
32 * BuddyPress Settings meta boxes
33 *
34 * @since 1.0.3
35 *
36 * @param $meta_boxes
37 *
38 * @return mixed
39 */
40 function gamipress_bp_settings_meta_boxes( $meta_boxes ) {
41
42 $prefix = 'bp_';
43
44 // Setup dynamic achievement fields
45 $achievement_fields = array();
46
47 foreach( GamiPress()->shortcodes['gamipress_achievement']->fields as $field_id => $field_args ) {
48
49 if( $field_id === 'id' ) {
50 continue;
51 }
52
53 if( $field_args['type'] === 'checkbox' && isset( $field_args['default'] ) ) {
54 unset( $field_args['default'] );
55 }
56
57 $achievement_fields[$prefix . 'members_achievements_' . $field_id] = $field_args;
58
59 }
60
61 // Setup dynamic rank fields
62 $rank_fields = array();
63
64 foreach( GamiPress()->shortcodes['gamipress_rank']->fields as $field_id => $field_args ) {
65
66 if( $field_id === 'id' ) {
67 continue;
68 }
69
70 if( $field_args['type'] === 'checkbox' && isset( $field_args['default'] ) ) {
71 unset( $field_args['default'] );
72 }
73
74 $rank_fields[$prefix . 'members_ranks_' . $field_id] = $field_args;
75
76 }
77
78 $meta_boxes['gamipress-bp-settings'] = array(
79 'title' => __( 'BuddyPress', 'gamipress' ),
80 'fields' => apply_filters( 'gamipress_bp_settings_fields', array(
81
82 // Points Types
83
84 $prefix . 'points_placement' => array(
85 'name' => __( 'Where Place User Points?', 'gamipress' ),
86 'tooltip' => __( 'Areas you wish to show the user points.', 'gamipress' ),
87 'label_cb' => 'cmb_tooltip_label_cb',
88 'type' => 'multicheck',
89 'classes' => 'gamipress-switch',
90 'options' => array(
91 'top' => __( 'At top of the user profile (before the user name)', 'gamipress' ),
92 'listing' => __( 'On members listing', 'gamipress' ),
93 'activity' => __( 'On activities', 'gamipress' ),
94 ),
95 ),
96 $prefix . 'members_points_types' => array(
97 'name' => __( 'Points Types', 'gamipress' ),
98 'tooltip' => __( 'Points types you want to show.', 'gamipress' )
99 . '<br>' . __( '<strong>Note:</strong> You can drag and drop this options to reorder them. The order you set will affect to the order they will get displayed.', 'gamipress' ),
100 'label_cb' => 'cmb_tooltip_label_cb',
101 'type' => 'multicheck',
102 'options_cb' => 'gamipress_bp_members_points_types_option_cb',
103 ),
104 $prefix . 'members_points_types_hide' => array(
105 'name' => __( 'Hide If No Earnings', 'gamipress' ),
106 'tooltip' => __( 'Hide the points types where user has not earned anything. Applied to users with a balance of 0 points.', 'gamipress' ),
107 'label_cb' => 'cmb_tooltip_label_cb',
108 'type' => 'checkbox',
109 'classes' => 'gamipress-switch',
110 ),
111 $prefix . 'members_points_types_top_thumbnail' => array(
112 'name' => __( 'Show Thumbnail', 'gamipress' ),
113 'tooltip' => __( 'Show the points type featured image.', 'gamipress' ),
114 'label_cb' => 'cmb_tooltip_label_cb',
115 'type' => 'checkbox',
116 'classes' => 'gamipress-switch',
117 ),
118 $prefix . 'members_points_types_top_thumbnail_size' => array(
119 'name' => __( 'Thumbnail Size', 'gamipress' ),
120 'tooltip' => __( 'Set the thumbnail size (in pixels).', 'gamipress' ),
121 'label_cb' => 'cmb_tooltip_label_cb',
122 'type' => 'text',
123 'default' => '25',
124 ),
125 $prefix . 'members_points_types_top_label' => array(
126 'name' => __( 'Show Label', 'gamipress' ),
127 'tooltip' => __( 'Show the points type singular or plural label.', 'gamipress' ),
128 'label_cb' => 'cmb_tooltip_label_cb',
129 'type' => 'checkbox',
130 'classes' => 'gamipress-switch',
131 ),
132
133 // Achievement Types
134
135 $prefix . 'achievements_placement' => array(
136 'name' => __( 'Where Place User Achievements?', 'gamipress' ),
137 'tooltip' => __( 'Areas you wish to show the user achievements.', 'gamipress' ),
138 'label_cb' => 'cmb_tooltip_label_cb',
139 'type' => 'multicheck',
140 'classes' => 'gamipress-switch',
141 'options' => array(
142 'top' => __( 'At top of the user profile (before the user name)', 'gamipress' ),
143 'listing' => __( 'On members listing', 'gamipress' ),
144 'activity' => __( 'On activities', 'gamipress' ),
145 ),
146 ),
147 $prefix . 'members_achievements_types' => array(
148 'name' => __( 'User Profile Achievement Types', 'gamipress' ),
149 'tooltip' => __( 'Choose the achievement types you want to show.', 'gamipress' )
150 . '<br>' . __( '<strong>Note:</strong> You can drag and drop this options to reorder them. The order you set will affect to the order they will get displayed.', 'gamipress' ),
151 'label_cb' => 'cmb_tooltip_label_cb',
152 'type' => 'multicheck',
153 'options_cb' => 'gamipress_bp_members_achievements_types_option_cb',
154 ),
155 $prefix . 'members_achievements_top_thumbnail' => array(
156 'name' => __( 'Show Thumbnail', 'gamipress' ),
157 'tooltip' => __( 'Show the achievement featured image.', 'gamipress' ),
158 'label_cb' => 'cmb_tooltip_label_cb',
159 'type' => 'checkbox',
160 'classes' => 'gamipress-switch',
161 ),
162 $prefix . 'members_achievements_top_thumbnail_size' => array(
163 'name' => __( 'Thumbnail Size', 'gamipress' ),
164 'tooltip' => __( 'Set the thumbnail size (in pixels).', 'gamipress' ),
165 'label_cb' => 'cmb_tooltip_label_cb',
166 'type' => 'text',
167 'default' => '25',
168 ),
169 $prefix . 'members_achievements_top_title' => array(
170 'name' => __( 'Show Title', 'gamipress' ),
171 'tooltip' => __( 'Show the achievements title.', 'gamipress' ),
172 'label_cb' => 'cmb_tooltip_label_cb',
173 'type' => 'checkbox',
174 'classes' => 'gamipress-switch',
175 ),
176 $prefix . 'members_achievements_top_link' => array(
177 'name' => __( 'Show Link', 'gamipress' ),
178 'tooltip' => __( 'Add a link to the achievement page.', 'gamipress' ),
179 'label_cb' => 'cmb_tooltip_label_cb',
180 'type' => 'checkbox',
181 'classes' => 'gamipress-switch',
182 ),
183 $prefix . 'members_achievements_top_label' => array(
184 'name' => __( 'Show Label', 'gamipress' ),
185 'tooltip' => __( 'Show the achievement type label.', 'gamipress' ),
186 'label_cb' => 'cmb_tooltip_label_cb',
187 'type' => 'checkbox',
188 'classes' => 'gamipress-switch',
189 ),
190 $prefix . 'members_achievements_top_limit' => array(
191 'name' => __( 'Limit', 'gamipress' ),
192 'tooltip' => __( 'Number of achievements to display.', 'gamipress' ),
193 'label_cb' => 'cmb_tooltip_label_cb',
194 'type' => 'text',
195 'default' => '10',
196 ),
197
198 // Rank Types
199
200 $prefix . 'ranks_placement' => array(
201 'name' => __( 'Where Place User Ranks?', 'gamipress' ),
202 'tooltip' => __( 'Areas you wish to show the user ranks.', 'gamipress' ),
203 'label_cb' => 'cmb_tooltip_label_cb',
204 'type' => 'multicheck',
205 'classes' => 'gamipress-switch',
206 'options' => array(
207 'top' => __( 'At top of the user profile (before the user name)', 'gamipress' ),
208 'listing' => __( 'On members listing', 'gamipress' ),
209 'activity' => __( 'On activities', 'gamipress' ),
210 ),
211 ),
212 $prefix . 'members_ranks_types' => array(
213 'name' => __( 'Rank Types', 'gamipress' ),
214 'tooltip' => __( 'Choose the rank types you want to show.', 'gamipress' )
215 . '<br>' . __( '<strong>Note:</strong> You can drag and drop this options to reorder them. The order you set will affect to the order they will get displayed.', 'gamipress' ),
216 'label_cb' => 'cmb_tooltip_label_cb',
217 'type' => 'multicheck',
218 'options_cb' => 'gamipress_bp_members_ranks_types_option_cb',
219 ),
220 $prefix . 'members_ranks_types_hide' => array(
221 'name' => __( 'Hide If No Earnings', 'gamipress' ),
222 'tooltip' => __( 'Hide the rank types where user has not earned anything. Applied to users in the default rank.', 'gamipress' ),
223 'label_cb' => 'cmb_tooltip_label_cb',
224 'type' => 'checkbox',
225 'classes' => 'gamipress-switch',
226 ),
227 $prefix . 'members_ranks_top_thumbnail' => array(
228 'name' => __( 'Show Thumbnail', 'gamipress' ),
229 'tooltip' => __( 'Show the achievement featured image.', 'gamipress' ),
230 'label_cb' => 'cmb_tooltip_label_cb',
231 'type' => 'checkbox',
232 'classes' => 'gamipress-switch',
233 ),
234 $prefix . 'members_ranks_top_thumbnail_size' => array(
235 'name' => __( 'Thumbnail Size', 'gamipress' ),
236 'tooltip' => __( 'Set the thumbnail size (in pixels).', 'gamipress' ),
237 'label_cb' => 'cmb_tooltip_label_cb',
238 'type' => 'text',
239 'default' => '25',
240 ),
241 $prefix . 'members_ranks_top_title' => array(
242 'name' => __( 'Show Title', 'gamipress' ),
243 'tooltip' => __( 'Show the rank title.', 'gamipress' ),
244 'label_cb' => 'cmb_tooltip_label_cb',
245 'type' => 'checkbox',
246 'classes' => 'gamipress-switch',
247 ),
248 $prefix . 'members_ranks_top_link' => array(
249 'name' => __( 'Show Link', 'gamipress' ),
250 'tooltip' => __( 'Add a link to the rank page.', 'gamipress' ),
251 'label_cb' => 'cmb_tooltip_label_cb',
252 'type' => 'checkbox',
253 'classes' => 'gamipress-switch',
254 ),
255 $prefix . 'members_ranks_top_label' => array(
256 'name' => __( 'Show Label', 'gamipress' ),
257 'tooltip' => __( 'Show the rank type label.', 'gamipress' ),
258 'label_cb' => 'cmb_tooltip_label_cb',
259 'type' => 'checkbox',
260 'classes' => 'gamipress-switch',
261 ),
262
263 // Email Settings
264
265 $prefix . 'email_settings' => array(
266 'name' => __( 'Add GamiPress Email Settings', 'gamipress' ),
267 'tooltip' => __( 'Display the GamiPress email settings to the user\'s email preferences.', 'gamipress' ),
268 'label_cb' => 'cmb_tooltip_label_cb',
269 'type' => 'checkbox',
270 'classes' => 'gamipress-switch',
271 ),
272 $prefix . 'email_groups' => array(
273 'name' => __( 'Divide Email Settings By Group', 'gamipress' ),
274 'tooltip' => __( 'Display email settings divided by group.', 'gamipress' ),
275 'label_cb' => 'cmb_tooltip_label_cb',
276 'type' => 'checkbox',
277 'classes' => 'gamipress-switch',
278 ),
279 $prefix . 'email_types' => array(
280 'name' => __( 'Divide Email Settings By Type', 'gamipress' ),
281 'tooltip' => __( 'Display email settings divided by type.', 'gamipress' ),
282 'label_cb' => 'cmb_tooltip_label_cb',
283 'type' => 'checkbox',
284 'classes' => 'gamipress-switch',
285 ),
286
287 ) ),
288 'vertical_tabs' => true,
289 'tabs' => apply_filters( 'gamipress_bp_settings_tabs', array(
290 'points' => array(
291 'title' => __( 'Points', 'gamipress' ),
292 'icon' => 'dashicons-star-filled',
293 'fields' => array(
294 $prefix . 'points_placement',
295 $prefix . 'members_points_types',
296 $prefix . 'members_points_types_hide',
297 $prefix . 'members_points_types_top_thumbnail',
298 $prefix . 'members_points_types_top_thumbnail_size',
299 $prefix . 'members_points_types_top_label'
300 )
301 ),
302 'achievements' => array(
303 'title' => __( 'Achievements', 'gamipress' ),
304 'icon' => 'dashicons-awards',
305 'fields' => array(
306 $prefix . 'achievements_placement',
307 $prefix . 'members_achievements_types',
308 $prefix . 'members_achievements_top_thumbnail',
309 $prefix . 'members_achievements_top_thumbnail_size',
310 $prefix . 'members_achievements_top_title',
311 $prefix . 'members_achievements_top_link',
312 $prefix . 'members_achievements_top_label',
313 $prefix . 'members_achievements_top_limit',
314 ),
315 ),
316 'ranks' => array(
317 'title' => __( 'Ranks', 'gamipress' ),
318 'icon' => 'dashicons-rank',
319 'fields' => array(
320 $prefix . 'ranks_placement',
321 $prefix . 'members_ranks_types',
322 $prefix . 'members_ranks_types_hide',
323 $prefix . 'members_ranks_top_thumbnail',
324 $prefix . 'members_ranks_top_thumbnail_size',
325 $prefix . 'members_ranks_top_title',
326 $prefix . 'members_ranks_top_link',
327 $prefix . 'members_ranks_top_label',
328 ),
329 ),
330 'emails' => array(
331 'title' => __( 'Email Settings', 'gamipress' ),
332 'icon' => 'dashicons-email',
333 'fields' => array(
334 $prefix . 'email_settings',
335 $prefix . 'email_groups',
336 $prefix . 'email_types',
337 ),
338 )
339 ) )
340 );
341
342 // Profile Tab settings
343 $meta_boxes['gamipress-bp-tab-settings'] = array(
344 'title' => __( 'BuddyPress Profile Tab', 'gamipress' ),
345 'fields' => apply_filters( 'gamipress_bp_tab_settings_fields', array_merge( array(
346
347 // Points Types
348
349 $prefix . 'points_tab' => array(
350 'name' => __( 'Enable Profile Points Tab', 'gamipress' ),
351 'tooltip' => __( 'Show the user points on a profile tab.', 'gamipress' ),
352 'label_cb' => 'cmb_tooltip_label_cb',
353 'type' => 'checkbox',
354 'classes' => 'gamipress-switch',
355 ),
356 $prefix . 'points_tab_title' => array(
357 'name' => __( 'Tab Title', 'gamipress' ),
358 'tooltip' => __( 'Text to show on the BuddyPress user profile.', 'gamipress' ),
359 'label_cb' => 'cmb_tooltip_label_cb',
360 'type' => 'text',
361 'default' => __( 'Points', 'gamipress' ),
362 ),
363 $prefix . 'points_tab_slug' => array(
364 'name' => __( 'Tab Slug (Optional)', 'gamipress' ),
365 'tooltip' => __( 'URL slug to use on the profile tab. Leave blank and slug will be a URL version of the tab title (eg: "My Tab Title" will have a slug like "my-tab-title").', 'gamipress' )
366 . '<br>' . __( '<strong>Important:</strong> If you set a tab title with special characters then provide a slug with URL friendly characters.', 'gamipress' ),
367 'label_cb' => 'cmb_tooltip_label_cb',
368 'type' => 'text',
369 ),
370 $prefix . 'tab_points_types' => array(
371 'name' => __( 'Points Types', 'gamipress' ),
372 'tooltip' => __( 'Points types you want to show on BuddyPress user profile.', 'gamipress' )
373 . '<br>' . __( '<strong>Note:</strong> You can drag and drop this options to reorder them. The order you set will affect to the order they will get displayed on the profile.', 'gamipress' ),
374 'label_cb' => 'cmb_tooltip_label_cb',
375 'type' => 'multicheck',
376 'options_cb' => 'gamipress_bp_tab_points_types_option_cb',
377 ),
378 $prefix . 'tab_points_types_hide' => array(
379 'name' => __( 'Hide If No Earnings', 'gamipress' ),
380 'tooltip' => __( 'Hide the points types where user has not earned anything. Applied to users with a balance of 0 points.', 'gamipress' ),
381 'label_cb' => 'cmb_tooltip_label_cb',
382 'type' => 'checkbox',
383 'classes' => 'gamipress-switch',
384 ),
385
386 // Achievement Types
387
388 $prefix . 'achievements_tab' => array(
389 'name' => __( 'Enable Profile Achievements Tab', 'gamipress' ),
390 'tooltip' => __( 'Show the user achievements on a profile tab.', 'gamipress' ),
391 'label_cb' => 'cmb_tooltip_label_cb',
392 'type' => 'checkbox',
393 'classes' => 'gamipress-switch',
394 ),
395 $prefix . 'achievements_tab_title' => array(
396 'name' => __( 'Tab Title', 'gamipress' ),
397 'tooltip' => __( 'Text to show on the BuddyPress user profile.', 'gamipress' ),
398 'label_cb' => 'cmb_tooltip_label_cb',
399 'type' => 'text',
400 'default' => __( 'Achievements', 'gamipress' ),
401 ),
402 $prefix . 'achievements_tab_slug' => array(
403 'name' => __( 'Tab Slug (Optional)', 'gamipress' ),
404 'tooltip' => __( 'URL slug to use on the profile tab. Leave blank and slug will be a URL version of the tab title (eg: "My Tab Title" will have a slug like "my-tab-title").', 'gamipress' )
405 . '<br>' . __( '<strong>Important:</strong> If you set a tab title with special characters then provide a slug with URL friendly characters.', 'gamipress' ),
406 'label_cb' => 'cmb_tooltip_label_cb',
407 'type' => 'text',
408 ),
409 $prefix . 'tab_achievements_types' => array(
410 'name' => __( 'Achievement Types', 'gamipress' ),
411 'tooltip' => __( 'Achievement types you want to show on BuddyPress user profile achievements tab.', 'gamipress' )
412 . '<br>' . __( '<strong>Note:</strong> You can drag and drop this options to reorder them. The order you set will affect to the order they will get displayed on the profile.', 'gamipress' ),
413 'label_cb' => 'cmb_tooltip_label_cb',
414 'type' => 'multicheck',
415 'options_cb' => 'gamipress_bp_tab_achievements_types_option_cb',
416 ),
417 $prefix . 'members_achievements_template_title' => array(
418 'name' => __( 'Achievements Tab Display Options', 'gamipress' ),
419 'description' => __( 'Setup how achievements should look on the BuddyPress user profile tab.', 'gamipress' ),
420 'type' => 'title',
421 ),
422 $prefix . 'members_achievements_columns' => array(
423 'name' => __( 'Columns', 'gamipress' ),
424 'tooltip' => __( 'Columns to divide achievements.', 'gamipress' ),
425 'label_cb' => 'cmb_tooltip_label_cb',
426 'type' => 'select',
427 'options' => array(
428 '1' => __( '1 Column', 'gamipress' ),
429 '2' => __( '2 Columns', 'gamipress' ),
430 '3' => __( '3 Columns', 'gamipress' ),
431 '4' => __( '4 Columns', 'gamipress' ),
432 '5' => __( '5 Columns', 'gamipress' ),
433 '6' => __( '6 Columns', 'gamipress' ),
434 ),
435 'default' => '1'
436 ),
437 $prefix . 'members_achievements_limit' => array(
438 'name' => __( 'Limit', 'gamipress' ),
439 'tooltip' => __( 'Number of achievements to display.', 'gamipress' ),
440 'label_cb' => 'cmb_tooltip_label_cb',
441 'type' => 'text',
442 'default' => 10,
443 ),
444 $prefix . 'members_achievements_orderby' => array(
445 'name' => __( 'Order By', 'gamipress' ),
446 'tooltip' => __( 'Parameter to use for sorting.', 'gamipress' ),
447 'label_cb' => 'cmb_tooltip_label_cb',
448 'type' => 'select',
449 'options' => array(
450 'menu_order' => __( 'Menu Order', 'gamipress' ),
451 'ID' => __( 'Achievement ID', 'gamipress' ),
452 'title' => __( 'Achievement Title', 'gamipress' ),
453 'date' => __( 'Published Date', 'gamipress' ),
454 'modified' => __( 'Last Modified Date', 'gamipress' ),
455 'author' => __( 'Achievement Author', 'gamipress' ),
456 'rand' => __( 'Random', 'gamipress' ),
457 ),
458 'default' => 'menu_order',
459 ),
460 $prefix . 'members_achievements_order' => array(
461 'name' => __( 'Order', 'gamipress' ),
462 'tooltip' => __( 'Sort order.', 'gamipress' ),
463 'label_cb' => 'cmb_tooltip_label_cb',
464 'type' => 'select',
465 'options' => array( 'ASC' => __( 'Ascending', 'gamipress' ), 'DESC' => __( 'Descending', 'gamipress' ) ),
466 'default' => 'ASC',
467 ),
468
469 // Rank Types
470
471 $prefix . 'ranks_tab' => array(
472 'name' => __( 'Enable Profile Ranks Tab', 'gamipress' ),
473 'tooltip' => __( 'Show the user ranks on a profile tab.', 'gamipress' ),
474 'label_cb' => 'cmb_tooltip_label_cb',
475 'type' => 'checkbox',
476 'classes' => 'gamipress-switch',
477 ),
478 $prefix . 'ranks_tab_title' => array(
479 'name' => __( 'Tab Title', 'gamipress' ),
480 'tooltip' => __( 'Text to show on the BuddyPress user profile.', 'gamipress' ),
481 'label_cb' => 'cmb_tooltip_label_cb',
482 'type' => 'text',
483 'default' => __( 'Ranks', 'gamipress' ),
484 ),
485 $prefix . 'ranks_tab_slug' => array(
486 'name' => __( 'Tab Slug (Optional)', 'gamipress' ),
487 'tooltip' => __( 'URL slug to use on the profile tab. Leave blank and slug will be a URL version of the tab title (eg: "My Tab Title" will have a slug like "my-tab-title").', 'gamipress' )
488 . '<br>' . __( '<strong>Important:</strong> If you set a tab title with special characters then provide a slug with URL friendly characters.', 'gamipress' ),
489 'label_cb' => 'cmb_tooltip_label_cb',
490 'type' => 'text',
491 ),
492 $prefix . 'tab_ranks_types' => array(
493 'name' => __( 'Rank Types', 'gamipress' ),
494 'tooltip' => __( 'Rank types you want to show on BuddyPress user profile ranks tab.', 'gamipress' )
495 . '<br>' . __( '<strong>Note:</strong> You can drag and drop this options to reorder them. The order you set will affect to the order they will get displayed on the profile.', 'gamipress' ),
496 'label_cb' => 'cmb_tooltip_label_cb',
497 'type' => 'multicheck',
498 'options_cb' => 'gamipress_bp_tab_ranks_types_option_cb',
499 ),
500 $prefix . 'tab_ranks_types_hide' => array(
501 'name' => __( 'Hide If No Earnings', 'gamipress' ),
502 'tooltip' => __( 'Hide the rank types where user has not earned anything. Applied to users in the default rank.', 'gamipress' ),
503 'label_cb' => 'cmb_tooltip_label_cb',
504 'type' => 'checkbox',
505 'classes' => 'gamipress-switch',
506 ),
507 $prefix . 'members_ranks_template_title' => array(
508 'name' => __( 'Ranks Tab Display Options', 'gamipress' ),
509 'description' => __( 'Setup how ranks should look on the BuddyPress user profile tab.', 'gamipress' ),
510 'type' => 'title',
511 ),
512 $prefix . 'members_ranks_columns' => array(
513 'name' => __( 'Columns', 'gamipress' ),
514 'tooltip' => __( 'Columns to divide ranks.', 'gamipress' ),
515 'label_cb' => 'cmb_tooltip_label_cb',
516 'type' => 'select',
517 'options' => array(
518 '1' => __( '1 Column', 'gamipress' ),
519 '2' => __( '2 Columns', 'gamipress' ),
520 '3' => __( '3 Columns', 'gamipress' ),
521 '4' => __( '4 Columns', 'gamipress' ),
522 '5' => __( '5 Columns', 'gamipress' ),
523 '6' => __( '6 Columns', 'gamipress' ),
524 ),
525 'default' => '1'
526 ),
527 $prefix . 'members_ranks_orderby' => array(
528 'name' => __( 'Order By', 'gamipress' ),
529 'tooltip' => __( 'Parameter to use for sorting.', 'gamipress' ),
530 'label_cb' => 'cmb_tooltip_label_cb',
531 'type' => 'select',
532 'options' => array(
533 'priority' => __( 'Priority', 'gamipress' ),
534 'ID' => __( 'Rank ID', 'gamipress' ),
535 'title' => __( 'Rank Title', 'gamipress' ),
536 'date' => __( 'Published Date', 'gamipress' ),
537 'modified' => __( 'Last Modified Date', 'gamipress' ),
538 'rand' => __( 'Random', 'gamipress' ),
539 ),
540 'default' => 'priority',
541 ),
542 $prefix . 'members_ranks_order' => array(
543 'name' => __( 'Order', 'gamipress' ),
544 'tooltip' => __( 'Sort order.', 'gamipress' ),
545 'label_cb' => 'cmb_tooltip_label_cb',
546 'type' => 'select',
547 'options' => array( 'ASC' => __( 'Ascending', 'gamipress' ), 'DESC' => __( 'Descending', 'gamipress' ) ),
548 'default' => 'DESC',
549 ),
550
551 ), $achievement_fields, $rank_fields ) ),
552 'vertical_tabs' => true,
553 'tabs' => apply_filters( 'gamipress_bp_settings_tabs', array(
554 'points' => array(
555 'title' => __( 'Points', 'gamipress' ),
556 'icon' => 'dashicons-star-filled',
557 'fields' => array(
558 $prefix . 'points_tab',
559 $prefix . 'points_tab_title',
560 $prefix . 'points_tab_slug',
561 $prefix . 'tab_points_types',
562 $prefix . 'tab_points_types_hide',
563 )
564 ),
565 'achievements' => array(
566 'title' => __( 'Achievements', 'gamipress' ),
567 'icon' => 'dashicons-awards',
568 'fields' => array_merge( array(
569 $prefix . 'achievements_tab',
570 $prefix . 'achievements_tab_title',
571 $prefix . 'achievements_tab_slug',
572 $prefix . 'tab_achievements_types',
573 $prefix . 'members_achievements_template_title',
574 $prefix . 'members_achievements_columns',
575 $prefix . 'members_achievements_limit',
576 $prefix . 'members_achievements_orderby',
577 $prefix . 'members_achievements_order',
578 ), array_keys( $achievement_fields ) )
579 ),
580 'ranks' => array(
581 'title' => __( 'Ranks', 'gamipress' ),
582 'icon' => 'dashicons-rank',
583 'fields' => array_merge( array(
584 $prefix . 'ranks_tab',
585 $prefix . 'ranks_tab_title',
586 $prefix . 'ranks_tab_slug',
587 $prefix . 'tab_ranks_types',
588 $prefix . 'tab_ranks_types_hide',
589 $prefix . 'members_ranks_template_title',
590 $prefix . 'members_ranks_columns',
591 $prefix . 'members_ranks_orderby',
592 $prefix . 'members_ranks_order',
593 ), array_keys( $rank_fields ) )
594 )
595 ) )
596 );
597
598 return $meta_boxes;
599
600 }
601 add_filter( 'gamipress_settings_addons_meta_boxes', 'gamipress_bp_settings_meta_boxes' );
602
603 /**
604 * Block users settings meta boxes
605 *
606 * @since 1.0.0
607 *
608 * @param array $meta_boxes
609 *
610 * @return array
611 */
612 function gamipress_bp_block_users_settings_meta_boxes( $meta_boxes ) {
613
614 $prefix = 'bp_';
615
616 $meta_boxes['gamipress-bp-block-users-settings'] = array(
617 'title' => __( 'BuddyPress Block Users', 'gamipress' ),
618 'fields' => apply_filters( 'gamipress_bp_block_users_settings_fields', array(
619 $prefix . 'blocked_member_types' => array(
620 'name' => __( 'Blocked Profile Types', 'gamipress' ),
621 'tooltip' => __( 'Block users earnings by profile type. Users with those profile types will not be able to earn any GamiPress element.', 'gamipress' )
622 . '<br>' . sprintf(
623 __( '<strong>Note:</strong> To block users by role or block specific users, check the <a href="%s" target="_blank">GamiPress - Block Users</a> add-on.', 'gamipress' ),
624 'https://wordpress.org/plugins/gamipress-block-users/'
625 ),
626 'label_cb' => 'cmb_tooltip_label_cb',
627 'type' => 'advanced_select',
628 'multiple' => true,
629 'classes' => 'gamipress-selector',
630 'options_cb' => 'gamipress_bp_block_users_get_roles_options',
631 ),
632 ) )
633 );
634
635 return $meta_boxes;
636
637 }
638 add_filter( 'gamipress_settings_addons_meta_boxes', 'gamipress_bp_block_users_settings_meta_boxes' );
639
640 function gamipress_bp_block_users_get_roles_options() {
641
642 $options = array();
643
644 if( ! function_exists( 'bp_get_member_types' ) ) {
645 return $options;
646 }
647
648 $member_types = bp_get_member_types( array(), 'objects' );
649
650 foreach( $member_types as $member_type => $member_type_obj ) {
651 $options[$member_type] = $member_type_obj->labels['singular_name'];
652 }
653
654 return $options;
655
656 }
657
658 function gamipress_bp_members_points_types_option_cb() {
659 return gamipress_bp_points_types_option_cb( 'bp_members_points_types' );
660 }
661
662 function gamipress_bp_tab_points_types_option_cb() {
663 return gamipress_bp_points_types_option_cb( 'bp_tab_points_types' );
664 }
665
666 function gamipress_bp_points_types_option_cb( $key = '' ) {
667
668 $points_types_slugs = gamipress_get_points_types_slugs();
669
670 $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
671
672 $points_types_order = isset( $gamipress_settings[$key] ) ?
673 $gamipress_settings[$key] : $points_types_slugs;
674
675 if( ! is_array( $points_types_order ) ) {
676 $points_types_order = array();
677 }
678
679 $points_types = gamipress_get_points_types();
680
681 $options = array();
682
683 foreach( $points_types_order as $points_type_slug ) {
684
685 // Skip if points type not exists
686 if( ! isset( $points_types[$points_type_slug] ) ) {
687 continue;
688 }
689
690 $options[$points_type_slug] = '<input type="hidden" name="' . $key . '_order[]" value="' . $points_type_slug . '" />'
691 . $points_types[$points_type_slug]['plural_name'];
692 }
693
694 $unordered_points_types = array_diff( $points_types_slugs, $points_types_order );
695
696 // Append new achievement types
697 foreach( $unordered_points_types as $unordered_points_type ) {
698
699 // Skip if points type not exists
700 if( ! isset( $points_types[$unordered_points_type] ) ) {
701 continue;
702 }
703
704 $options[$unordered_points_type] = '<input type="hidden" name="' . $key . '_order[]" value="' . $unordered_points_type . '" />'
705 . $points_types[$unordered_points_type]['plural_name'];
706 }
707
708 return $options;
709
710 }
711
712 function gamipress_bp_members_achievements_types_option_cb() {
713 return gamipress_bp_achievements_types_option_cb( 'bp_members_achievements_types' );
714 }
715
716 function gamipress_bp_tab_achievements_types_option_cb() {
717 return gamipress_bp_achievements_types_option_cb( 'bp_tab_achievements_types' );
718 }
719
720 function gamipress_bp_achievements_types_option_cb( $key = '' ) {
721
722 $achievement_types_slugs = array_diff(
723 gamipress_get_achievement_types_slugs(),
724 gamipress_get_requirement_types_slugs()
725 );
726
727 $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
728
729 $achievement_types_order = isset( $gamipress_settings[$key . '_order'] ) ?
730 $gamipress_settings[$key . '_order'] : $achievement_types_slugs;
731
732 if( ! is_array( $achievement_types_order ) ) {
733 $achievement_types_order = array();
734 }
735
736 $achievement_types = gamipress_get_achievement_types();
737
738 $options = array();
739
740 foreach( $achievement_types_order as $achievement_type_slug ) {
741
742 // Skip if is a requirement type or not exists on $achievement_types
743 if( in_array( $achievement_type_slug, gamipress_get_requirement_types_slugs() ) || ! isset( $achievement_types[$achievement_type_slug] ) ) {
744 continue;
745 }
746
747 $options[$achievement_type_slug] = '<input type="hidden" name="' . $key . '_order[]" value="' . $achievement_type_slug . '" />'
748 . $achievement_types[$achievement_type_slug]['plural_name'];
749 }
750
751 $unordered_achievement_types = array_diff( $achievement_types_slugs, $achievement_types_order );
752
753 // Append new achievement types
754 foreach( $unordered_achievement_types as $unordered_achievement_type ) {
755
756 // Skip if achievement not exists
757 if( ! isset( $achievement_types[$unordered_achievement_type] ) ) {
758 continue;
759 }
760
761 $options[$unordered_achievement_type] = '<input type="hidden" name="' . $key . '_order[]" value="' . $unordered_achievement_type . '" />'
762 . $achievement_types[$unordered_achievement_type]['plural_name'];
763 }
764
765 return $options;
766
767 }
768
769 function gamipress_bp_members_ranks_types_option_cb() {
770 return gamipress_bp_ranks_types_option_cb( 'bp_members_ranks_types' );
771 }
772
773 function gamipress_bp_tab_ranks_types_option_cb() {
774 return gamipress_bp_ranks_types_option_cb( 'bp_tab_ranks_types' );
775 }
776
777 function gamipress_bp_ranks_types_option_cb( $key = '' ) {
778
779 $rank_types_slugs = gamipress_get_rank_types_slugs();
780
781 $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
782
783 $rank_types_order = isset( $gamipress_settings[$key . '_order'] ) ?
784 $gamipress_settings[$key . '_order'] : $rank_types_slugs;
785
786 if( ! is_array( $rank_types_order ) ) {
787 $rank_types_order = array();
788 }
789
790 $rank_types = gamipress_get_rank_types();
791
792 $options = array();
793
794 foreach( $rank_types_order as $rank_type_slug ) {
795
796 // Skip if rank not exists
797 if( ! isset( $rank_types[$rank_type_slug] ) ) {
798 continue;
799 }
800
801 $options[$rank_type_slug] = '<input type="hidden" name="' . $key . '_order[]" value="' . $rank_type_slug . '" />'
802 . $rank_types[$rank_type_slug]['plural_name'];
803
804 }
805
806 $unordered_rank_types = array_diff( $rank_types_slugs, $rank_types_order );
807
808 // Append new rank types
809 foreach( $unordered_rank_types as $unordered_rank_type ) {
810
811 // Skip if rank not exists
812 if( ! isset( $rank_types[$unordered_rank_type] ) ) {
813 continue;
814 }
815
816 $options[$unordered_rank_type] = '<input type="hidden" name="' . $key . '_order[]" value="' . $unordered_rank_type . '" />'
817 . $rank_types[$unordered_rank_type]['plural_name'];
818
819 }
820
821 return $options;
822
823 }
824
825 function gamipress_bp_save_gamipress_settings() {
826
827 if( ! isset( $_POST['submit-cmb'] ) ) {
828 return;
829 }
830
831 if( ! ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'gamipress_settings' ) ) {
832 return;
833 }
834
835 if( ! isset( $_POST['bp_members_points_types_order'] ) || ! isset( $_POST['bp_members_achievements_types_order'] ) || ! isset( $_POST['bp_members_ranks_types_order'] ) ) {
836 return;
837 }
838
839 if( ! isset( $_POST['bp_tab_points_types_order'] ) || ! isset( $_POST['bp_tab_achievements_types_order'] ) || ! isset( $_POST['bp_tab_ranks_types_order'] ) ) {
840 return;
841 }
842
843 // Setup GamiPress options
844 $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
845
846 // Setup new setting
847 $gamipress_settings['bp_members_points_types_order'] = $_POST['bp_members_points_types_order'];
848 $gamipress_settings['bp_members_achievements_types_order'] = $_POST['bp_members_achievements_types_order'];
849 $gamipress_settings['bp_members_ranks_types_order'] = $_POST['bp_members_ranks_types_order'];
850
851 $gamipress_settings['bp_tab_points_types_order'] = $_POST['bp_tab_points_types_order'];
852 $gamipress_settings['bp_tab_achievements_types_order'] = $_POST['bp_tab_achievements_types_order'];
853 $gamipress_settings['bp_tab_ranks_types_order'] = $_POST['bp_tab_ranks_types_order'];
854
855 // Update GamiPress settings
856 update_option( 'gamipress_settings', $gamipress_settings );
857
858 }
859 add_action( 'cmb2_save_options-page_fields', 'gamipress_bp_save_gamipress_settings' );
860
861 /**
862 * BuddyPress automatic updates
863 *
864 * @since 1.0.4
865 *
866 * @param array $automatic_updates_plugins
867 *
868 * @return array
869 */
870 function gamipress_bp_automatic_updates( $automatic_updates_plugins ) {
871
872 $automatic_updates_plugins['gamipress'] = __( 'BuddyPress integration', 'gamipress' );
873
874 return $automatic_updates_plugins;
875 }
876 add_filter( 'gamipress_automatic_updates_plugins', 'gamipress_bp_automatic_updates' );