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/forums/includes/admin.php +371 -0 7.9.3 → 8.0.5 View file →
@@ -1,0 +1,371 @@
1 +<?php
2 +/**
3 + * Admin
4 + *
5 + * @package GamiPress\bbPress\Admin
6 + * @since 1.0.1
7 + */
8 +// Exit if accessed directly
9 +if( !defined( 'ABSPATH' ) ) exit;
10 +
11 +require_once GAMIPRESS_BBP_DIR . 'includes/admin/recount-activity.php';
12 +
13 +/**
14 + * Shortcut function to get plugin options
15 + *
16 + * @since 1.0.4
17 + *
18 + * @param string $option_name
19 + * @param bool $default
20 + *
21 + * @return mixed
22 + */
23 +function gamipress_bbp_get_option( $option_name, $default = false ) {
24 +
25 + $prefix = 'bbp_';
26 +
27 + return gamipress_get_option( $prefix . $option_name, $default );
28 +
29 +}
30 +
31 +/**
32 + * Plugin Settings meta boxes
33 + *
34 + * @since 1.0.4
35 + *
36 + * @param $meta_boxes
37 + *
38 + * @return mixed
39 + */
40 +function gamipress_bbp_settings_meta_boxes( $meta_boxes ) {
41 +
42 + $prefix = 'bbp_';
43 +
44 + $meta_boxes['gamipress-bbp-settings'] = array(
45 + 'title' => __( 'BuddyBoss Forums', 'gamipress' ),
46 + 'fields' => apply_filters( 'gamipress_bbp_settings_fields', array(
47 +
48 + // Points Types
49 +
50 + $prefix . 'points_types' => array(
51 + 'name' => __( 'User Points Types', 'gamipress' ),
52 + 'tooltip' => __( 'Points types you want to show on user reply details.', 'gamipress' )
53 + . '<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 reply details.', 'gamipress' ),
54 + 'label_cb' => 'cmb_tooltip_label_cb',
55 + 'type' => 'multicheck',
56 + 'options_cb' => 'gamipress_bbp_points_types_option_cb',
57 + ),
58 + $prefix . 'points_types_hide' => array(
59 + 'name' => __( 'Hide If No Earnings', 'gamipress' ),
60 + 'tooltip' => __( 'Hide the points types where user has not earned anything. Applied to users with a balance of 0 points.', 'gamipress' ),
61 + 'label_cb' => 'cmb_tooltip_label_cb',
62 + 'type' => 'checkbox',
63 + 'classes' => 'gamipress-switch',
64 + ),
65 + $prefix . 'points_types_display_title' => array(
66 + 'name' => __( 'Display Options', 'gamipress' ),
67 + 'desc' => __( 'Setup how points types should look on user reply details.', 'gamipress' ),
68 + 'type' => 'title',
69 + ),
70 + $prefix . 'points_types_thumbnail' => array(
71 + 'name' => __( 'Show Thumbnail', 'gamipress' ),
72 + 'tooltip' => __( 'Show the points type featured image.', 'gamipress' ),
73 + 'label_cb' => 'cmb_tooltip_label_cb',
74 + 'type' => 'checkbox',
75 + 'classes' => 'gamipress-switch',
76 + ),
77 + $prefix . 'points_types_thumbnail_size' => array(
78 + 'name' => __( 'Thumbnail Size', 'gamipress' ),
79 + 'tooltip' => __( 'Set the thumbnail size (in pixels).', 'gamipress' ),
80 + 'label_cb' => 'cmb_tooltip_label_cb',
81 + 'type' => 'text',
82 + 'default' => '25',
83 + ),
84 + $prefix . 'points_types_label' => array(
85 + 'name' => __( 'Show Label', 'gamipress' ),
86 + 'tooltip' => __( 'Show the points type singular or plural label.', 'gamipress' ),
87 + 'label_cb' => 'cmb_tooltip_label_cb',
88 + 'type' => 'checkbox',
89 + 'classes' => 'gamipress-switch',
90 + ),
91 +
92 + // Achievement Types
93 +
94 + $prefix . 'achievement_types' => array(
95 + 'name' => __( 'User Profile Achievement Types', 'gamipress' ),
96 + 'tooltip' => __( 'Choose the achievement types you want to show on user reply details.', 'gamipress' )
97 + . '<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 reply details.', 'gamipress' ),
98 + 'label_cb' => 'cmb_tooltip_label_cb',
99 + 'type' => 'multicheck',
100 + 'options_cb' => 'gamipress_bbp_achievement_types_option_cb',
101 + ),
102 + $prefix . 'achievement_types_display_title' => array(
103 + 'name' => __( 'Display Options', 'gamipress' ),
104 + 'desc' => __( 'Setup how achievements should look on user reply details.', 'gamipress' ),
105 + 'type' => 'title',
106 + ),
107 + $prefix . 'achievement_types_thumbnail' => array(
108 + 'name' => __( 'Show Thumbnail', 'gamipress' ),
109 + 'tooltip' => __( 'Show the achievement featured image.', 'gamipress' ),
110 + 'label_cb' => 'cmb_tooltip_label_cb',
111 + 'type' => 'checkbox',
112 + 'classes' => 'gamipress-switch',
113 + ),
114 + $prefix . 'achievement_types_thumbnail_size' => array(
115 + 'name' => __( 'Thumbnail Size', 'gamipress' ),
116 + 'tooltip' => __( 'Set the thumbnail size (in pixels).', 'gamipress' ),
117 + 'label_cb' => 'cmb_tooltip_label_cb',
118 + 'type' => 'text',
119 + 'default' => '25',
120 + ),
121 + $prefix . 'achievement_types_title' => array(
122 + 'name' => __( 'Show Title', 'gamipress' ),
123 + 'tooltip' => __( 'Show the achievements title.', 'gamipress' ),
124 + 'label_cb' => 'cmb_tooltip_label_cb',
125 + 'type' => 'checkbox',
126 + 'classes' => 'gamipress-switch',
127 + ),
128 + $prefix . 'achievement_types_link' => array(
129 + 'name' => __( 'Show Link', 'gamipress' ),
130 + 'tooltip' => __( 'Add a link to the achievement page.', 'gamipress' ),
131 + 'label_cb' => 'cmb_tooltip_label_cb',
132 + 'type' => 'checkbox',
133 + 'classes' => 'gamipress-switch',
134 + ),
135 + $prefix . 'achievement_types_label' => array(
136 + 'name' => __( 'Show Label', 'gamipress' ),
137 + 'tooltip' => __( 'Show the achievement type label.', 'gamipress' ),
138 + 'label_cb' => 'cmb_tooltip_label_cb',
139 + 'type' => 'checkbox',
140 + 'classes' => 'gamipress-switch',
141 + ),
142 + $prefix . 'achievements_limit' => array(
143 + 'name' => __( 'Number of achievements to show', 'gamipress' ),
144 + 'tooltip' => __( 'Setup the number of achievements to show. Leave blank if you want to show all user earned achievement', 'gamipress' ),
145 + 'label_cb' => 'cmb_tooltip_label_cb',
146 + 'type' => 'text',
147 + ),
148 +
149 + // Rank Types
150 +
151 + $prefix . 'rank_types' => array(
152 + 'name' => __( 'User Profile Rank Types', 'gamipress' ),
153 + 'tooltip' => __( 'Choose the rank types you want to show on user reply details.', 'gamipress' )
154 + . '<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 reply details.', 'gamipress' ),
155 + 'label_cb' => 'cmb_tooltip_label_cb',
156 + 'type' => 'multicheck',
157 + 'options_cb' => 'gamipress_bbp_rank_types_option_cb',
158 + ),
159 + $prefix . 'rank_types_hide' => array(
160 + 'name' => __( 'Hide If No Earnings', 'gamipress' ),
161 + 'tooltip' => __( 'Hide the rank types where user has not earned anything. Applied to users in the default rank.', 'gamipress' ),
162 + 'label_cb' => 'cmb_tooltip_label_cb',
163 + 'type' => 'checkbox',
164 + 'classes' => 'gamipress-switch',
165 + ),
166 + $prefix . 'rank_types_display_title' => array(
167 + 'name' => __( 'Display Options', 'gamipress' ),
168 + 'desc' => __( 'Setup how ranks should look on user reply details.', 'gamipress' ),
169 + 'type' => 'title',
170 + ),
171 + $prefix . 'rank_types_thumbnail' => array(
172 + 'name' => __( 'Show Thumbnail', 'gamipress' ),
173 + 'tooltip' => __( 'Show the rank featured image.', 'gamipress' ),
174 + 'label_cb' => 'cmb_tooltip_label_cb',
175 + 'type' => 'checkbox',
176 + 'classes' => 'gamipress-switch',
177 + ),
178 + $prefix . 'rank_types_thumbnail_size' => array(
179 + 'name' => __( 'Thumbnail Size', 'gamipress' ),
180 + 'tooltip' => __( 'Set the thumbnail size (in pixels).', 'gamipress' ),
181 + 'label_cb' => 'cmb_tooltip_label_cb',
182 + 'type' => 'text',
183 + 'default' => '25',
184 + ),
185 + $prefix . 'rank_types_title' => array(
186 + 'name' => __( 'Show Title', 'gamipress' ),
187 + 'tooltip' => __( 'Show the ranks title.', 'gamipress' ),
188 + 'label_cb' => 'cmb_tooltip_label_cb',
189 + 'type' => 'checkbox',
190 + 'classes' => 'gamipress-switch',
191 + ),
192 + $prefix . 'rank_types_link' => array(
193 + 'name' => __( 'Show Link', 'gamipress' ),
194 + 'tooltip' => __( 'Add a link to the rank page.', 'gamipress' ),
195 + 'label_cb' => 'cmb_tooltip_label_cb',
196 + 'type' => 'checkbox',
197 + 'classes' => 'gamipress-switch',
198 + ),
199 + $prefix . 'rank_types_label' => array(
200 + 'name' => __( 'Show Label', 'gamipress' ),
201 + 'tooltip' => __( 'Show the rank type label.', 'gamipress' ),
202 + 'label_cb' => 'cmb_tooltip_label_cb',
203 + 'type' => 'checkbox',
204 + 'classes' => 'gamipress-switch',
205 + ),
206 + ) ),
207 + 'vertical_tabs' => true,
208 + 'tabs' => apply_filters( 'gamipress_bbp_settings_tabs', array(
209 + 'points' => array(
210 + 'title' => __( 'Points', 'gamipress' ),
211 + 'icon' => 'dashicons-star-filled',
212 + 'fields' => array(
213 + $prefix . 'points_types',
214 + $prefix . 'points_types_hide',
215 + $prefix . 'points_types_display_title',
216 + $prefix . 'points_types_thumbnail',
217 + $prefix . 'points_types_thumbnail_size',
218 + $prefix . 'points_types_label',
219 + )
220 + ),
221 + 'achievements' => array(
222 + 'title' => __( 'Achievements', 'gamipress' ),
223 + 'icon' => 'dashicons-awards',
224 + 'fields' => array(
225 + $prefix . 'achievement_types',
226 + $prefix . 'achievement_types_display_title',
227 + $prefix . 'achievement_types_thumbnail',
228 + $prefix . 'achievement_types_thumbnail_size',
229 + $prefix . 'achievement_types_title',
230 + $prefix . 'achievement_types_link',
231 + $prefix . 'achievement_types_label',
232 + $prefix . 'achievements_limit',
233 + )
234 + ),
235 + 'ranks' => array(
236 + 'title' => __( 'Ranks', 'gamipress' ),
237 + 'icon' => 'dashicons-rank',
238 + 'fields' => array(
239 + $prefix . 'rank_types',
240 + $prefix . 'rank_types_hide',
241 + $prefix . 'rank_types_display_title',
242 + $prefix . 'rank_types_thumbnail',
243 + $prefix . 'rank_types_thumbnail_size',
244 + $prefix . 'rank_types_title',
245 + $prefix . 'rank_types_link',
246 + $prefix . 'rank_types_label',
247 + )
248 + ),
249 + ) )
250 + );
251 +
252 + return $meta_boxes;
253 +
254 +}
255 +add_filter( 'gamipress_settings_addons_meta_boxes', 'gamipress_bbp_settings_meta_boxes' );
256 +
257 +function gamipress_bbp_points_types_option_cb() {
258 +
259 + $points_types_slugs = gamipress_get_points_types_slugs();
260 + $points_types = gamipress_get_points_types();
261 +
262 + return gamipress_bbp_order_options( 'bbp_points_types_order', $points_types_slugs, $points_types );
263 +
264 +}
265 +
266 +function gamipress_bbp_achievement_types_option_cb() {
267 +
268 + $achievement_types_slugs = array_diff(
269 + gamipress_get_achievement_types_slugs(),
270 + gamipress_get_requirement_types_slugs()
271 + );
272 + $achievement_types = gamipress_get_achievement_types();
273 +
274 + return gamipress_bbp_order_options( 'bbp_achievement_types_order', $achievement_types_slugs, $achievement_types );
275 +
276 +}
277 +
278 +function gamipress_bbp_rank_types_option_cb() {
279 +
280 + $rank_types_slugs = gamipress_get_rank_types_slugs();
281 + $rank_types = gamipress_get_rank_types();
282 +
283 + return gamipress_bbp_order_options( 'bbp_rank_types_order', $rank_types_slugs, $rank_types );
284 +
285 +}
286 +
287 +/**
288 + * Common function to handle options generation
289 + *
290 + * @param string $setting_key
291 + * @param array $items
292 + * @param array $types
293 + *
294 + * @return array
295 + */
296 +function gamipress_bbp_order_options( $setting_key, $items, $types ) {
297 +
298 + $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
299 +
300 + $items_order = isset( $gamipress_settings[$setting_key] ) ?
301 + $gamipress_settings[$setting_key] : $items;
302 +
303 + $options = array();
304 +
305 + foreach( $items_order as $item_order ) {
306 +
307 + $options[$item_order] = '<input type="hidden" name="' . esc_attr( $setting_key ) . '[]" value="' . esc_attr( $item_order ) . '" />'
308 + . $types[$item_order]['plural_name'];
309 + }
310 +
311 + $unordered_items = array_diff( $items, $items_order );
312 +
313 + // Append new rank types
314 + foreach( $unordered_items as $unordered_item ) {
315 + $options[$unordered_item] = '<input type="hidden" name="' . esc_attr( $setting_key ) . '[]" value="' . esc_attr( $unordered_item ) . '" />'
316 + . $types[$unordered_item]['plural_name'];
317 + }
318 +
319 + return $options;
320 +
321 +}
322 +
323 +function gamipress_bbp_save_gamipress_settings() {
324 +
325 + if( ! isset( $_POST['submit-cmb'] ) )
326 + return;
327 +
328 + if( ! ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'gamipress_settings' ) )
329 + return;
330 +
331 + if( ! isset( $_POST['bbp_points_types_order'] ) && ! isset( $_POST['bbp_achievement_types_order'] ) && ! isset( $_POST['bbp_rank_types_order'] ) )
332 + return;
333 +
334 + // Setup GamiPress options
335 + $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
336 +
337 + // Setup new setting
338 + if ( isset( $_POST['bbp_points_types_order'] ) ) {
339 + $gamipress_settings['bbp_points_types_order'] = gamipress_bbp_sanitize_text_array( $_POST['bbp_points_types_order'] );
340 + }
341 +
342 + if ( isset( $_POST['bbp_achievement_types_order'] ) ) {
343 + $gamipress_settings['bbp_achievement_types_order'] = gamipress_bbp_sanitize_text_array( $_POST['bbp_achievement_types_order'] );
344 + }
345 +
346 + if ( isset( $_POST['bbp_rank_types_order'] ) ) {
347 + $gamipress_settings['bbp_rank_types_order'] = gamipress_bbp_sanitize_text_array( $_POST['bbp_rank_types_order'] );
348 + }
349 +
350 + // Update GamiPress settings
351 + update_option( 'gamipress_settings', $gamipress_settings );
352 +
353 +}
354 +add_action( 'cmb2_save_options-page_fields', 'gamipress_bbp_save_gamipress_settings' );
355 +
356 +/**
357 + * Sanitize an array of text elements
358 + *
359 + * @since 1.0.0
360 + *
361 + * @param array $items
362 + * @return array
363 + */
364 +function gamipress_bbp_sanitize_text_array( $items ) {
365 +
366 + foreach( $items as $i => $item )
367 + $items[$i] = sanitize_text_field( $item );
368 +
369 + return $items;
370 +
371 +}