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/bbpress/includes/admin.php +389 -0 7.8.8 → 8.0.5 View file →
@@ -1,0 +1,389 @@
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' => __( 'bbPress', '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' => __( 'Show the points type featured image.', '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' => __( '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 + 'tooltip' => __( 'Setup how achievements should look on user reply details.', 'gamipress' ),
105 + 'label_cb' => 'cmb_tooltip_label_cb',
106 + 'type' => 'title',
107 + ),
108 + $prefix . 'achievement_types_thumbnail' => array(
109 + 'name' => __( 'Show Thumbnail', 'gamipress' ),
110 + 'tooltip' => __( 'Show the achievement featured image.', 'gamipress' ),
111 + 'label_cb' => 'cmb_tooltip_label_cb',
112 + 'type' => 'checkbox',
113 + 'classes' => 'gamipress-switch',
114 + ),
115 + $prefix . 'achievement_types_thumbnail_size' => array(
116 + 'name' => __( 'Thumbnail Size', 'gamipress' ),
117 + 'tooltip' => __( 'Set the thumbnail size (in pixels).', 'gamipress' ),
118 + 'label_cb' => 'cmb_tooltip_label_cb',
119 + 'type' => 'text',
120 + 'default' => '25',
121 + ),
122 + $prefix . 'achievement_types_title' => array(
123 + 'name' => __( 'Show Title', 'gamipress' ),
124 + 'tooltip' => __( 'Show the achievements title.', 'gamipress' ),
125 + 'label_cb' => 'cmb_tooltip_label_cb',
126 + 'type' => 'checkbox',
127 + 'classes' => 'gamipress-switch',
128 + ),
129 + $prefix . 'achievement_types_link' => array(
130 + 'name' => __( 'Show Link', 'gamipress' ),
131 + 'tooltip' => __( 'Add a link to the achievement page.', 'gamipress' ),
132 + 'label_cb' => 'cmb_tooltip_label_cb',
133 + 'type' => 'checkbox',
134 + 'classes' => 'gamipress-switch',
135 + ),
136 + $prefix . 'achievement_types_label' => array(
137 + 'name' => __( 'Show Label', 'gamipress' ),
138 + 'tooltip' => __( 'Show the achievement type label.', 'gamipress' ),
139 + 'label_cb' => 'cmb_tooltip_label_cb',
140 + 'type' => 'checkbox',
141 + 'classes' => 'gamipress-switch',
142 + ),
143 + $prefix . 'achievements_limit' => array(
144 + 'name' => __( 'Number of achievements to show', 'gamipress' ),
145 + 'tooltip' => __( 'Setup the number of achievements to show. Leave blank if you want to show all user earned achievement', 'gamipress' ),
146 + 'label_cb' => 'cmb_tooltip_label_cb',
147 + 'type' => 'text',
148 + ),
149 +
150 + // Rank Types
151 +
152 + $prefix . 'rank_types' => array(
153 + 'name' => __( 'User Profile Rank Types', 'gamipress' ),
154 + 'tooltip' => __( 'Rank types you want to show on user reply details.', 'gamipress' )
155 + . '<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' ),
156 + 'label_cb' => 'cmb_tooltip_label_cb',
157 + 'type' => 'multicheck',
158 + 'options_cb' => 'gamipress_bbp_rank_types_option_cb',
159 + ),
160 + $prefix . 'rank_types_hide' => array(
161 + 'name' => __( 'Hide If No Earnings', 'gamipress' ),
162 + 'tooltip' => __( 'Hide the rank types where user has not earned anything. Applied to users in the default rank.', 'gamipress' ),
163 + 'label_cb' => 'cmb_tooltip_label_cb',
164 + 'type' => 'checkbox',
165 + 'classes' => 'gamipress-switch',
166 + ),
167 + $prefix . 'rank_types_display_title' => array(
168 + 'name' => __( 'Display Options', 'gamipress' ),
169 + 'desc' => __( 'Setup how ranks should look on user reply details.', 'gamipress' ),
170 + 'type' => 'title',
171 + ),
172 + $prefix . 'rank_types_thumbnail' => array(
173 + 'name' => __( 'Show Thumbnail', 'gamipress' ),
174 + 'tooltip' => __( 'Show the rank featured image.', 'gamipress' ),
175 + 'label_cb' => 'cmb_tooltip_label_cb',
176 + 'type' => 'checkbox',
177 + 'classes' => 'gamipress-switch',
178 + ),
179 + $prefix . 'rank_types_thumbnail_size' => array(
180 + 'name' => __( 'Thumbnail Size', 'gamipress' ),
181 + 'tooltip' => __( 'Set the thumbnail size (in pixels).', 'gamipress' ),
182 + 'label_cb' => 'cmb_tooltip_label_cb',
183 + 'type' => 'text',
184 + 'default' => '25',
185 + ),
186 + $prefix . 'rank_types_title' => array(
187 + 'name' => __( 'Show Title', 'gamipress' ),
188 + 'tooltip' => __( 'Show the ranks title.', 'gamipress' ),
189 + 'label_cb' => 'cmb_tooltip_label_cb',
190 + 'type' => 'checkbox',
191 + 'classes' => 'gamipress-switch',
192 + ),
193 + $prefix . 'rank_types_link' => array(
194 + 'name' => __( 'Show Link', 'gamipress' ),
195 + 'tooltip' => __( 'Add a link to the rank page.', 'gamipress' ),
196 + 'label_cb' => 'cmb_tooltip_label_cb',
197 + 'type' => 'checkbox',
198 + 'classes' => 'gamipress-switch',
199 + ),
200 + $prefix . 'rank_types_label' => array(
201 + 'name' => __( 'Show Label', 'gamipress' ),
202 + 'tooltip' => __( 'Show the rank type label.', 'gamipress' ),
203 + 'label_cb' => 'cmb_tooltip_label_cb',
204 + 'type' => 'checkbox',
205 + 'classes' => 'gamipress-switch',
206 + ),
207 + ) ),
208 + 'vertical_tabs' => true,
209 + 'tabs' => apply_filters( 'gamipress_bbp_settings_tabs', array(
210 + 'points' => array(
211 + 'title' => __( 'Points', 'gamipress' ),
212 + 'icon' => 'dashicons-star-filled',
213 + 'fields' => array(
214 + $prefix . 'points_types',
215 + $prefix . 'points_types_hide',
216 + $prefix . 'points_types_display_title',
217 + $prefix . 'points_types_thumbnail',
218 + $prefix . 'points_types_thumbnail_size',
219 + $prefix . 'points_types_label',
220 + )
221 + ),
222 + 'achievements' => array(
223 + 'title' => __( 'Achievements', 'gamipress' ),
224 + 'icon' => 'dashicons-awards',
225 + 'fields' => array(
226 + $prefix . 'achievement_types',
227 + $prefix . 'achievement_types_display_title',
228 + $prefix . 'achievement_types_thumbnail',
229 + $prefix . 'achievement_types_thumbnail_size',
230 + $prefix . 'achievement_types_title',
231 + $prefix . 'achievement_types_link',
232 + $prefix . 'achievement_types_label',
233 + $prefix . 'achievements_limit',
234 + )
235 + ),
236 + 'ranks' => array(
237 + 'title' => __( 'Ranks', 'gamipress' ),
238 + 'icon' => 'dashicons-rank',
239 + 'fields' => array(
240 + $prefix . 'rank_types',
241 + $prefix . 'rank_types_hide',
242 + $prefix . 'rank_types_display_title',
243 + $prefix . 'rank_types_thumbnail',
244 + $prefix . 'rank_types_thumbnail_size',
245 + $prefix . 'rank_types_title',
246 + $prefix . 'rank_types_link',
247 + $prefix . 'rank_types_label',
248 + )
249 + ),
250 + ) )
251 + );
252 +
253 + return $meta_boxes;
254 +
255 +}
256 +add_filter( 'gamipress_settings_addons_meta_boxes', 'gamipress_bbp_settings_meta_boxes' );
257 +
258 +function gamipress_bbp_points_types_option_cb() {
259 +
260 + $points_types_slugs = gamipress_get_points_types_slugs();
261 + $points_types = gamipress_get_points_types();
262 +
263 + return gamipress_bbp_order_options( 'bbp_points_types_order', $points_types_slugs, $points_types );
264 +
265 +}
266 +
267 +function gamipress_bbp_achievement_types_option_cb() {
268 +
269 + $achievement_types_slugs = array_diff(
270 + gamipress_get_achievement_types_slugs(),
271 + gamipress_get_requirement_types_slugs()
272 + );
273 + $achievement_types = gamipress_get_achievement_types();
274 +
275 + return gamipress_bbp_order_options( 'bbp_achievement_types_order', $achievement_types_slugs, $achievement_types );
276 +
277 +}
278 +
279 +function gamipress_bbp_rank_types_option_cb() {
280 +
281 + $rank_types_slugs = gamipress_get_rank_types_slugs();
282 + $rank_types = gamipress_get_rank_types();
283 +
284 + return gamipress_bbp_order_options( 'bbp_rank_types_order', $rank_types_slugs, $rank_types );
285 +
286 +}
287 +
288 +/**
289 + * Common function to handle options generation
290 + *
291 + * @param string $setting_key
292 + * @param array $items
293 + * @param array $types
294 + *
295 + * @return array
296 + */
297 +function gamipress_bbp_order_options( $setting_key, $items, $types ) {
298 +
299 + $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
300 +
301 + $items_order = isset( $gamipress_settings[$setting_key] ) ?
302 + $gamipress_settings[$setting_key] : $items;
303 +
304 + $options = array();
305 +
306 + foreach( $items_order as $item_order ) {
307 +
308 + $options[$item_order] = '<input type="hidden" name="' . esc_attr( $setting_key ) . '[]" value="' . esc_attr( $item_order ) . '" />'
309 + . $types[$item_order]['plural_name'];
310 + }
311 +
312 + $unordered_items = array_diff( $items, $items_order );
313 +
314 + // Append new rank types
315 + foreach( $unordered_items as $unordered_item ) {
316 + $options[$unordered_item] = '<input type="hidden" name="' . esc_attr( $setting_key ) . '[]" value="' . esc_attr( $unordered_item ) . '" />'
317 + . $types[$unordered_item]['plural_name'];
318 + }
319 +
320 + return $options;
321 +
322 +}
323 +
324 +function gamipress_bbp_save_gamipress_settings() {
325 +
326 + if( ! isset( $_POST['submit-cmb'] ) )
327 + return;
328 +
329 + if( ! ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'gamipress_settings' ) )
330 + return;
331 +
332 + if( ! isset( $_POST['bbp_points_types_order'] ) && ! isset( $_POST['bbp_achievement_types_order'] ) && ! isset( $_POST['bbp_rank_types_order'] ) )
333 + return;
334 +
335 + // Setup GamiPress options
336 + $gamipress_settings = ( $exists = get_option( 'gamipress_settings' ) ) ? $exists : array();
337 +
338 + // Setup new setting
339 + if ( isset( $_POST['bbp_points_types_order'] ) ) {
340 + $gamipress_settings['bbp_points_types_order'] = gamipress_bbp_sanitize_text_array( $_POST['bbp_points_types_order'] );
341 + }
342 +
343 + if ( isset( $_POST['bbp_achievement_types_order'] ) ) {
344 + $gamipress_settings['bbp_achievement_types_order'] = gamipress_bbp_sanitize_text_array( $_POST['bbp_achievement_types_order'] );
345 + }
346 +
347 + if ( isset( $_POST['bbp_rank_types_order'] ) ) {
348 + $gamipress_settings['bbp_rank_types_order'] = gamipress_bbp_sanitize_text_array( $_POST['bbp_rank_types_order'] );
349 + }
350 +
351 + // Update GamiPress settings
352 + update_option( 'gamipress_settings', $gamipress_settings );
353 +
354 +}
355 +add_action( 'cmb2_save_options-page_fields', 'gamipress_bbp_save_gamipress_settings' );
356 +
357 +/**
358 + * Sanitize an array of text elements
359 + *
360 + * @since 1.0.0
361 + *
362 + * @param array $items
363 + * @return array
364 + */
365 +function gamipress_bbp_sanitize_text_array( $items ) {
366 +
367 + foreach( $items as $i => $item )
368 + $items[$i] = sanitize_text_field( $item );
369 +
370 + return $items;
371 +
372 +}
373 +
374 +/**
375 + * bbPress automatic updates
376 + *
377 + * @since 1.0.1
378 + *
379 + * @param array $automatic_updates_plugins
380 + *
381 + * @return array
382 + */
383 +function gamipress_bbp_automatic_updates( $automatic_updates_plugins ) {
384 +
385 + $automatic_updates_plugins['gamipress'] = __( 'bbPress integration', 'gamipress' );
386 +
387 + return $automatic_updates_plugins;
388 +}
389 +add_filter( 'gamipress_automatic_updates_plugins', 'gamipress_bbp_automatic_updates' );