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