PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.5
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.5
8.0.5 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 All 47 releases
← All changes | integrations/buddyboss/includes/community/includes/admin.php +861 -0 7.9.9.4 → 8.0.5 View file →
@@ -1,0 +1,861 @@
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' => __( 'BuddyBoss', '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' => __( 'Check the 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' => __( 'Choose the 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' => __( 'Check the 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' => __( 'Check the 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 in 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' => __( 'BuddyBoss 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 BuddyBoss 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' => __( 'Choose the points types you want to show on BuddyBoss 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 BuddyBoss 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' => __( 'Choose the achievement types you want to show on BuddyBoss 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 + 'tooltip' => __( 'Setup how achievements should look on the BuddyBoss user profile tab.', 'gamipress' ),
420 + 'label_cb' => 'cmb_tooltip_label_cb',
421 + 'type' => 'title',
422 + ),
423 + $prefix . 'members_achievements_columns' => array(
424 + 'name' => __( 'Columns', 'gamipress' ),
425 + 'tooltip' => __( 'Columns to divide achievements.', 'gamipress' ),
426 + 'label_cb' => 'cmb_tooltip_label_cb',
427 + 'type' => 'select',
428 + 'options' => array(
429 + '1' => __( '1 Column', 'gamipress' ),
430 + '2' => __( '2 Columns', 'gamipress' ),
431 + '3' => __( '3 Columns', 'gamipress' ),
432 + '4' => __( '4 Columns', 'gamipress' ),
433 + '5' => __( '5 Columns', 'gamipress' ),
434 + '6' => __( '6 Columns', 'gamipress' ),
435 + ),
436 + 'default' => '1'
437 + ),
438 + $prefix . 'members_achievements_limit' => array(
439 + 'name' => __( 'Limit', 'gamipress' ),
440 + 'tooltip' => __( 'Number of achievements to display.', 'gamipress' ),
441 + 'label_cb' => 'cmb_tooltip_label_cb',
442 + 'type' => 'text',
443 + 'default' => 10,
444 + ),
445 + $prefix . 'members_achievements_orderby' => array(
446 + 'name' => __( 'Order By', 'gamipress' ),
447 + 'tooltip' => __( 'Parameter to use for sorting.', 'gamipress' ),
448 + 'label_cb' => 'cmb_tooltip_label_cb',
449 + 'type' => 'select',
450 + 'options' => array(
451 + 'menu_order' => __( 'Menu Order', 'gamipress' ),
452 + 'ID' => __( 'Achievement ID', 'gamipress' ),
453 + 'title' => __( 'Achievement Title', 'gamipress' ),
454 + 'date' => __( 'Published Date', 'gamipress' ),
455 + 'modified' => __( 'Last Modified Date', 'gamipress' ),
456 + 'author' => __( 'Achievement Author', 'gamipress' ),
457 + 'rand' => __( 'Random', 'gamipress' ),
458 + ),
459 + 'default' => 'menu_order',
460 + ),
461 + $prefix . 'members_achievements_order' => array(
462 + 'name' => __( 'Order', 'gamipress' ),
463 + 'tooltip' => __( 'Sort order.', 'gamipress' ),
464 + 'label_cb' => 'cmb_tooltip_label_cb',
465 + 'type' => 'select',
466 + 'options' => array( 'ASC' => __( 'Ascending', 'gamipress' ), 'DESC' => __( 'Descending', 'gamipress' ) ),
467 + 'default' => 'ASC',
468 + ),
469 +
470 + // Rank Types
471 +
472 + $prefix . 'ranks_tab' => array(
473 + 'name' => __( 'Enable Profile Ranks Tab', 'gamipress' ),
474 + 'tooltip' => __( 'Show the user ranks on a profile tab.', 'gamipress' ),
475 + 'label_cb' => 'cmb_tooltip_label_cb',
476 + 'type' => 'checkbox',
477 + 'classes' => 'gamipress-switch',
478 + ),
479 + $prefix . 'ranks_tab_title' => array(
480 + 'name' => __( 'Tab Title', 'gamipress' ),
481 + 'tooltip' => __( 'Text to show on the BuddyBoss user profile.', 'gamipress' ),
482 + 'label_cb' => 'cmb_tooltip_label_cb',
483 + 'type' => 'text',
484 + 'default' => __( 'Ranks', 'gamipress' ),
485 + ),
486 + $prefix . 'ranks_tab_slug' => array(
487 + 'name' => __( 'Tab Slug (Optional)', 'gamipress' ),
488 + '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' )
489 + . '<br>' . __( '<strong>Important:</strong> If you set a tab title with special characters then provide a slug with URL friendly characters.', 'gamipress' ),
490 + 'label_cb' => 'cmb_tooltip_label_cb',
491 + 'type' => 'text',
492 + ),
493 + $prefix . 'tab_ranks_types' => array(
494 + 'name' => __( 'Rank Types', 'gamipress' ),
495 + 'tooltip' => __( 'Choose the rank types you want to show on BuddyBoss user profile ranks tab.', 'gamipress' )
496 + . '<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' ),
497 + 'label_cb' => 'cmb_tooltip_label_cb',
498 + 'type' => 'multicheck',
499 + 'options_cb' => 'gamipress_bp_tab_ranks_types_option_cb',
500 + ),
501 + $prefix . 'tab_ranks_types_hide' => array(
502 + 'name' => __( 'Hide If No Earnings', 'gamipress' ),
503 + 'tooltip' => __( 'Hide the rank types where user has not earned anything. Applied to users in the default rank.', 'gamipress' ),
504 + 'label_cb' => 'cmb_tooltip_label_cb',
505 + 'type' => 'checkbox',
506 + 'classes' => 'gamipress-switch',
507 + ),
508 + $prefix . 'members_ranks_template_title' => array(
509 + 'name' => __( 'Ranks Tab Display Options', 'gamipress' ),
510 + 'tooltip' => __( 'Setup how ranks should look on the BuddyBoss user profile tab.', 'gamipress' ),
511 + 'label_cb' => 'cmb_tooltip_label_cb',
512 + 'type' => 'title',
513 + ),
514 + $prefix . 'members_ranks_columns' => array(
515 + 'name' => __( 'Columns', 'gamipress' ),
516 + 'tooltip' => __( 'Columns to divide ranks.', 'gamipress' ),
517 + 'label_cb' => 'cmb_tooltip_label_cb',
518 + 'type' => 'select',
519 + 'options' => array(
520 + '1' => __( '1 Column', 'gamipress' ),
521 + '2' => __( '2 Columns', 'gamipress' ),
522 + '3' => __( '3 Columns', 'gamipress' ),
523 + '4' => __( '4 Columns', 'gamipress' ),
524 + '5' => __( '5 Columns', 'gamipress' ),
525 + '6' => __( '6 Columns', 'gamipress' ),
526 + ),
527 + 'default' => '1'
528 + ),
529 + $prefix . 'members_ranks_orderby' => array(
530 + 'name' => __( 'Order By', 'gamipress' ),
531 + 'tooltip' => __( 'Parameter to use for sorting.', 'gamipress' ),
532 + 'label_cb' => 'cmb_tooltip_label_cb',
533 + 'type' => 'select',
534 + 'options' => array(
535 + 'priority' => __( 'Priority', 'gamipress' ),
536 + 'ID' => __( 'Rank ID', 'gamipress' ),
537 + 'title' => __( 'Rank Title', 'gamipress' ),
538 + 'date' => __( 'Published Date', 'gamipress' ),
539 + 'modified' => __( 'Last Modified Date', 'gamipress' ),
540 + 'rand' => __( 'Random', 'gamipress' ),
541 + ),
542 + 'default' => 'priority',
543 + ),
544 + $prefix . 'members_ranks_order' => array(
545 + 'name' => __( 'Order', 'gamipress' ),
546 + 'tooltip' => __( 'Sort order.', 'gamipress' ),
547 + 'label_cb' => 'cmb_tooltip_label_cb',
548 + 'type' => 'select',
549 + 'options' => array( 'ASC' => __( 'Ascending', 'gamipress' ), 'DESC' => __( 'Descending', 'gamipress' ) ),
550 + 'default' => 'DESC',
551 + ),
552 +
553 + ), $achievement_fields, $rank_fields ) ),
554 + 'vertical_tabs' => true,
555 + 'tabs' => apply_filters( 'gamipress_bp_settings_tabs', array(
556 + 'points' => array(
557 + 'title' => __( 'Points', 'gamipress' ),
558 + 'icon' => 'dashicons-star-filled',
559 + 'fields' => array(
560 + $prefix . 'points_tab',
561 + $prefix . 'points_tab_title',
562 + $prefix . 'points_tab_slug',
563 + $prefix . 'tab_points_types',
564 + $prefix . 'tab_points_types_hide',
565 + )
566 + ),
567 + 'achievements' => array(
568 + 'title' => __( 'Achievements', 'gamipress' ),
569 + 'icon' => 'dashicons-awards',
570 + 'fields' => array_merge( array(
571 + $prefix . 'achievements_tab',
572 + $prefix . 'achievements_tab_title',
573 + $prefix . 'achievements_tab_slug',
574 + $prefix . 'tab_achievements_types',
575 + $prefix . 'members_achievements_template_title',
576 + $prefix . 'members_achievements_columns',
577 + $prefix . 'members_achievements_limit',
578 + $prefix . 'members_achievements_orderby',
579 + $prefix . 'members_achievements_order',
580 + ), array_keys( $achievement_fields ) )
581 + ),
582 + 'ranks' => array(
583 + 'title' => __( 'Ranks', 'gamipress' ),
584 + 'icon' => 'dashicons-rank',
585 + 'fields' => array_merge( array(
586 + $prefix . 'ranks_tab',
587 + $prefix . 'ranks_tab_title',
588 + $prefix . 'ranks_tab_slug',
589 + $prefix . 'tab_ranks_types',
590 + $prefix . 'tab_ranks_types_hide',
591 + $prefix . 'members_ranks_template_title',
592 + $prefix . 'members_ranks_columns',
593 + $prefix . 'members_ranks_orderby',
594 + $prefix . 'members_ranks_order',
595 + ), array_keys( $rank_fields ) )
596 + )
597 + ) )
598 + );
599 +
600 + return $meta_boxes;
601 +
602 +}
603 +add_filter( 'gamipress_settings_addons_meta_boxes', 'gamipress_bp_settings_meta_boxes' );
604 +
605 +/**
606 + * Block users settings meta boxes
607 + *
608 + * @since 1.0.0
609 + *
610 + * @param array $meta_boxes
611 + *
612 + * @return array
613 + */
614 +function gamipress_bp_block_users_settings_meta_boxes( $meta_boxes ) {
615 +
616 + $prefix = 'bp_';
617 +
618 + $meta_boxes['gamipress-bp-block-users-settings'] = array(
619 + 'title' => __( 'BuddyBoss Block Users', 'gamipress' ),
620 + 'fields' => apply_filters( 'gamipress_bp_block_users_settings_fields', array(
621 + $prefix . 'blocked_member_types' => array(
622 + 'name' => __( 'Blocked Profile Types', 'gamipress' ),
623 + 'tooltip' => __( 'Block users earnings by profile type. Users with those profile types will not be able to earn any GamiPress element.', 'gamipress' )
624 + . '<br>' . sprintf(
625 + __( '<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' ),
626 + 'https://wordpress.org/plugins/gamipress-block-users/'
627 + ),
628 + 'label_cb' => 'cmb_tooltip_label_cb',
629 + 'type' => 'advanced_select',
630 + 'multiple' => true,
631 + 'classes' => 'gamipress-selector',
632 + 'options_cb' => 'gamipress_bp_block_users_get_roles_options',
633 + ),
634 + ) )
635 + );
636 +
637 + return $meta_boxes;
638 +
639 +}
640 +add_filter( 'gamipress_settings_addons_meta_boxes', 'gamipress_bp_block_users_settings_meta_boxes' );
641 +
642 +function gamipress_bp_block_users_get_roles_options() {
643 +
644 + $options = array();
645 +
646 + if( ! function_exists( 'bp_get_member_types' ) ) {
647 + return $options;
648 + }
649 +
650 + $member_types = bp_get_member_types( array(), 'objects' );
651 +
652 + foreach( $member_types as $member_type => $member_type_obj ) {
653 + $options[$member_type] = $member_type_obj->labels['singular_name'];
654 + }
655 +
656 + return $options;
657 +
658 +}
659 +
660 +function gamipress_bp_members_points_types_option_cb() {
661 + return gamipress_bp_points_types_option_cb( 'bp_members_points_types' );
662 +}
663 +
664 +function gamipress_bp_tab_points_types_option_cb() {
665 + return gamipress_bp_points_types_option_cb( 'bp_tab_points_types' );
666 +}
667 +
668 +function gamipress_bp_points_types_option_cb( $key = '' ) {
669 +
670 + $points_types_slugs = gamipress_get_points_types_slugs();
671 +
672 + $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
673 +
674 + $points_types_order = isset( $gamipress_settings[$key] ) ?
675 + $gamipress_settings[$key] : $points_types_slugs;
676 +
677 + if( ! is_array( $points_types_order ) ) {
678 + $points_types_order = array();
679 + }
680 +
681 + $points_types = gamipress_get_points_types();
682 +
683 + $options = array();
684 +
685 + foreach( $points_types_order as $points_type_slug ) {
686 +
687 + // Skip if points type not exists
688 + if( ! isset( $points_types[$points_type_slug] ) ) {
689 + continue;
690 + }
691 +
692 + $options[$points_type_slug] = '<input type="hidden" name="' . $key . '_order[]" value="' . $points_type_slug . '" />'
693 + . $points_types[$points_type_slug]['plural_name'];
694 + }
695 +
696 + $unordered_points_types = array_diff( $points_types_slugs, $points_types_order );
697 +
698 + // Append new achievement types
699 + foreach( $unordered_points_types as $unordered_points_type ) {
700 +
701 + // Skip if points type not exists
702 + if( ! isset( $points_types[$unordered_points_type] ) ) {
703 + continue;
704 + }
705 +
706 + $options[$unordered_points_type] = '<input type="hidden" name="' . $key . '_order[]" value="' . $unordered_points_type . '" />'
707 + . $points_types[$unordered_points_type]['plural_name'];
708 + }
709 +
710 + return $options;
711 +
712 +}
713 +
714 +function gamipress_bp_members_achievements_types_option_cb() {
715 + return gamipress_bp_achievements_types_option_cb( 'bp_members_achievements_types' );
716 +}
717 +
718 +function gamipress_bp_tab_achievements_types_option_cb() {
719 + return gamipress_bp_achievements_types_option_cb( 'bp_tab_achievements_types' );
720 +}
721 +
722 +function gamipress_bp_achievements_types_option_cb( $key = '' ) {
723 +
724 + $achievement_types_slugs = array_diff(
725 + gamipress_get_achievement_types_slugs(),
726 + gamipress_get_requirement_types_slugs()
727 + );
728 +
729 + $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
730 +
731 + $achievement_types_order = isset( $gamipress_settings[$key . '_order'] ) ?
732 + $gamipress_settings[$key . '_order'] : $achievement_types_slugs;
733 +
734 + if( ! is_array( $achievement_types_order ) ) {
735 + $achievement_types_order = array();
736 + }
737 +
738 + $achievement_types = gamipress_get_achievement_types();
739 +
740 + $options = array();
741 +
742 + foreach( $achievement_types_order as $achievement_type_slug ) {
743 +
744 + // Skip if is a requirement type or not exists on $achievement_types
745 + if( in_array( $achievement_type_slug, gamipress_get_requirement_types_slugs() ) || ! isset( $achievement_types[$achievement_type_slug] ) ) {
746 + continue;
747 + }
748 +
749 + $options[$achievement_type_slug] = '<input type="hidden" name="' . $key . '_order[]" value="' . $achievement_type_slug . '" />'
750 + . $achievement_types[$achievement_type_slug]['plural_name'];
751 + }
752 +
753 + $unordered_achievement_types = array_diff( $achievement_types_slugs, $achievement_types_order );
754 +
755 + // Append new achievement types
756 + foreach( $unordered_achievement_types as $unordered_achievement_type ) {
757 +
758 + // Skip if achievement not exists
759 + if( ! isset( $achievement_types[$unordered_achievement_type] ) ) {
760 + continue;
761 + }
762 +
763 + $options[$unordered_achievement_type] = '<input type="hidden" name="' . $key . '_order[]" value="' . $unordered_achievement_type . '" />'
764 + . $achievement_types[$unordered_achievement_type]['plural_name'];
765 + }
766 +
767 + return $options;
768 +
769 +}
770 +
771 +function gamipress_bp_members_ranks_types_option_cb() {
772 + return gamipress_bp_ranks_types_option_cb( 'bp_members_ranks_types' );
773 +}
774 +
775 +function gamipress_bp_tab_ranks_types_option_cb() {
776 + return gamipress_bp_ranks_types_option_cb( 'bp_tab_ranks_types' );
777 +}
778 +
779 +function gamipress_bp_ranks_types_option_cb( $key = '' ) {
780 +
781 + $rank_types_slugs = gamipress_get_rank_types_slugs();
782 +
783 + $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
784 +
785 + $rank_types_order = isset( $gamipress_settings[$key . '_order'] ) ?
786 + $gamipress_settings[$key . '_order'] : $rank_types_slugs;
787 +
788 + if( ! is_array( $rank_types_order ) ) {
789 + $rank_types_order = array();
790 + }
791 +
792 + $rank_types = gamipress_get_rank_types();
793 +
794 + $options = array();
795 +
796 + foreach( $rank_types_order as $rank_type_slug ) {
797 +
798 + // Skip if rank not exists
799 + if( ! isset( $rank_types[$rank_type_slug] ) ) {
800 + continue;
801 + }
802 +
803 + $options[$rank_type_slug] = '<input type="hidden" name="' . $key . '_order[]" value="' . $rank_type_slug . '" />'
804 + . $rank_types[$rank_type_slug]['plural_name'];
805 +
806 + }
807 +
808 + $unordered_rank_types = array_diff( $rank_types_slugs, $rank_types_order );
809 +
810 + // Append new rank types
811 + foreach( $unordered_rank_types as $unordered_rank_type ) {
812 +
813 + // Skip if rank not exists
814 + if( ! isset( $rank_types[$unordered_rank_type] ) ) {
815 + continue;
816 + }
817 +
818 + $options[$unordered_rank_type] = '<input type="hidden" name="' . $key . '_order[]" value="' . $unordered_rank_type . '" />'
819 + . $rank_types[$unordered_rank_type]['plural_name'];
820 +
821 + }
822 +
823 + return $options;
824 +
825 +}
826 +
827 +function gamipress_bp_save_gamipress_settings() {
828 +
829 + if( ! isset( $_POST['submit-cmb'] ) ) {
830 + return;
831 + }
832 +
833 + if( ! ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'gamipress_settings' ) ) {
834 + return;
835 + }
836 +
837 + if( ! isset( $_POST['bp_members_points_types_order'] ) || ! isset( $_POST['bp_members_achievements_types_order'] ) || ! isset( $_POST['bp_members_ranks_types_order'] ) ) {
838 + return;
839 + }
840 +
841 + if( ! isset( $_POST['bp_tab_points_types_order'] ) || ! isset( $_POST['bp_tab_achievements_types_order'] ) || ! isset( $_POST['bp_tab_ranks_types_order'] ) ) {
842 + return;
843 + }
844 +
845 + // Setup GamiPress options
846 + $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
847 +
848 + // Setup new setting
849 + $gamipress_settings['bp_members_points_types_order'] = $_POST['bp_members_points_types_order'];
850 + $gamipress_settings['bp_members_achievements_types_order'] = $_POST['bp_members_achievements_types_order'];
851 + $gamipress_settings['bp_members_ranks_types_order'] = $_POST['bp_members_ranks_types_order'];
852 +
853 + $gamipress_settings['bp_tab_points_types_order'] = $_POST['bp_tab_points_types_order'];
854 + $gamipress_settings['bp_tab_achievements_types_order'] = $_POST['bp_tab_achievements_types_order'];
855 + $gamipress_settings['bp_tab_ranks_types_order'] = $_POST['bp_tab_ranks_types_order'];
856 +
857 + // Update GamiPress settings
858 + update_option( 'gamipress_settings', $gamipress_settings );
859 +
860 +}
861 +add_action( 'cmb2_save_options-page_fields', 'gamipress_bp_save_gamipress_settings' );