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 / wpforo / includes / admin.php

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

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