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

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

813 lines 25.2 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\Admin
6 * @author GamiPress <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 // Admin includes
13 require_once GAMIPRESS_DIR . 'includes/admin/contextual-help.php';
14 require_once GAMIPRESS_DIR . 'includes/admin/dashboard.php';
15 require_once GAMIPRESS_DIR . 'includes/admin/debug.php';
16 require_once GAMIPRESS_DIR . 'includes/admin/meta-boxes.php';
17 require_once GAMIPRESS_DIR . 'includes/admin/notices.php';
18 require_once GAMIPRESS_DIR . 'includes/admin/plugins.php';
19 require_once GAMIPRESS_DIR . 'includes/admin/achievements.php';
20 require_once GAMIPRESS_DIR . 'includes/admin/ranks.php';
21 require_once GAMIPRESS_DIR . 'includes/admin/requirements.php';
22 require_once GAMIPRESS_DIR . 'includes/admin/users.php';
23 require_once GAMIPRESS_DIR . 'includes/admin/upgrades.php';
24
25 // Admin pages
26 require_once GAMIPRESS_DIR . 'includes/admin/pages/dashboard.php';
27 //require_once GAMIPRESS_DIR . 'includes/admin/pages/support.php';
28 require_once GAMIPRESS_DIR . 'includes/admin/pages/badge-builder.php';
29 require_once GAMIPRESS_DIR . 'includes/admin/pages/tools.php';
30 require_once GAMIPRESS_DIR . 'includes/admin/pages/settings.php';
31 require_once GAMIPRESS_DIR . 'includes/admin/pages/licenses.php';
32 require_once GAMIPRESS_DIR . 'includes/admin/pages/assets.php';
33 require_once GAMIPRESS_DIR . 'includes/admin/pages/add-ons.php';
34 /**
35 * Add custom GamiPress body classes
36 *
37 * @since 1.3.9.5
38 *
39 * @param string $admin_body_classes
40 *
41 * @return string
42 */
43 function gamipress_admin_body_class( $admin_body_classes ) {
44
45 global $post_type;
46
47 // Add an extra class to meet that current post type is a gamipress post type
48 if(
49 in_array( $post_type, array( 'points-type', 'achievement-type', 'rank-type' ) )
50 || in_array( $post_type, gamipress_get_achievement_types_slugs() )
51 || in_array( $post_type, gamipress_get_rank_types_slugs() )
52 ) {
53 $admin_body_classes .= ' gamipress-post-type ';
54 }
55
56 return $admin_body_classes;
57
58 }
59 add_filter( 'admin_body_class', 'gamipress_admin_body_class' );
60
61 /**
62 * Add GamiPress menus
63 *
64 * @since 1.0.0
65 * @updated 1.4.0 Added multisite support
66 */
67 function gamipress_admin_menu() {
68
69 // Bail if GamiPress is active network wide and we are not in main site
70 if( gamipress_is_network_wide_active() && ! is_main_site() ) {
71 return;
72 }
73
74 // Set minimum role setting for menus
75 $minimum_role = gamipress_get_manager_capability();
76
77 // Achievement types
78 $achievement_types = gamipress_get_achievement_types();
79
80 // Achievements menu
81 if( ! empty( $achievement_types ) ) {
82 add_menu_page( __( 'Achievements', 'gamipress' ), __( 'Achievements', 'gamipress' ), $minimum_role, 'gamipress_achievements', 'gamipress_achievements', 'dashicons-awards', 53 );
83 }
84
85 // Rank types
86 $rank_types = gamipress_get_rank_types();
87
88 // Achievements menu
89 if( ! empty( $rank_types ) ) {
90 add_menu_page( __( 'Ranks', 'gamipress' ), __( 'Ranks', 'gamipress' ), $minimum_role, 'gamipress_ranks', 'gamipress_ranks', 'dashicons-rank', 54 );
91 }
92
93 // GamiPress menu
94 add_menu_page( 'GamiPress', 'GamiPress', $minimum_role, 'gamipress', '', 'dashicons-gamipress', 55 );
95 add_submenu_page( 'gamipress', __( 'Dashboard', 'gamipress' ), __( 'Dashboard', 'gamipress' ), $minimum_role, 'gamipress', 'gamipress_dashboard_page' );
96
97 }
98 add_action( 'admin_menu', 'gamipress_admin_menu' );
99
100 /**
101 * Moves the Dashboard submenu to the first menu
102 * For some reason, WordPress assigns the first submenu item the post types registered under this menu
103 *
104 * @since 1.0.0
105 *
106 * @param string $parent_file The parent file.
107 *
108 * @return string
109 */
110 function gamipress_admin_menu_fix( $parent_file ) {
111
112 global $submenu;
113
114
115 if( isset( $submenu['gamipress'] ) && is_array( $submenu['gamipress'] ) ) {
116
117 // Loop all the GamiPress submenus
118 foreach( $submenu['gamipress'] as $i => $menu ) {
119
120 // Check for the "Dashboard" menu to move it to first position
121 if( is_array( $menu ) && isset( $menu[3] ) && $menu[3] === __( 'Dashboard', 'gamipress' ) ) {
122 unset( $submenu['gamipress'][$i] );
123 array_unshift( $submenu['gamipress'], $menu );
124 break;
125 }
126
127 }
128
129 // Reorder licenses, badge builder, tools & settings
130 $badge_builder = $submenu['gamipress'][6];
131 $licenses = $submenu['gamipress'][7];
132 $tools = $submenu['gamipress'][8];
133 $settings = $submenu['gamipress'][9];
134
135 $submenu['gamipress'][6] = $badge_builder;
136 $submenu['gamipress'][7] = $tools;
137 $submenu['gamipress'][8] = $settings;
138 $submenu['gamipress'][9] = $licenses;
139 }
140
141 return $parent_file;
142
143 }
144 add_filter( 'parent_file', 'gamipress_admin_menu_fix' );
145
146 /**
147 * Add GamiPress submenus
148 *
149 * @since 1.0.0
150 */
151 function gamipress_admin_submenu() {
152
153 // Set minimum role setting for menus
154 $minimum_role = gamipress_get_manager_capability();
155
156 // Assets sub menu
157 add_submenu_page( 'gamipress', __( 'Badge Builder', 'gamipress' ), __( 'Badge Builder', 'gamipress' ), $minimum_role, 'gamipress_badge_builder', 'gamipress_badge_builder_page' );
158
159
160 }
161 add_action( 'admin_menu', 'gamipress_admin_submenu', 12 );
162
163 function gamipress_admin_addons_submenu() {
164 // Set minimum role setting for menus
165 $minimum_role = gamipress_get_manager_capability();
166
167 // Assets sub menu
168 add_submenu_page( 'gamipress', __( 'Assets', 'gamipress' ), __( 'Assets', 'gamipress' ), $minimum_role, 'gamipress_assets', 'gamipress_assets_page' );
169
170 // Add-ons sub menu
171 add_submenu_page( 'gamipress', __( 'Add-ons', 'gamipress' ), __( 'Add-ons', 'gamipress' ), $minimum_role, 'gamipress_add_ons', 'gamipress_add_ons_page' );
172 }
173 add_action( 'admin_menu', 'gamipress_admin_addons_submenu', 15 );
174
175 /**
176 * Helper function to get the try of the day
177 *
178 * @since 1.0.0
179 *
180 * @return array|false
181 */
182 function gamipress_get_try_option() {
183
184 $options = array();
185
186 if( ! class_exists( 'AutomatorWP' ) ) {
187 $options[] = array(
188 'label' => __( 'Try AutomatorWP!', 'gamipress' ),
189 'slug' => 'automatorwp'
190 );
191 }
192
193 if( ! class_exists( 'ShortLinksPro' ) ) {
194 $options[] = array(
195 'label' => __( 'Try ShortLinks Pro!', 'gamipress' ),
196 'slug' => 'shortlinkspro'
197 );
198 }
199
200 if( ! class_exists( 'BBForms' ) ) {
201 $options[] = array(
202 'label' => __( 'Try BBForms!', 'gamipress' ),
203 'slug' => 'bbforms'
204 );
205 }
206
207 $count = count( $options );
208
209 // Bail if no options found
210 if( $count === 0 ) return false;
211
212 $day = absint( gmdate( 'd' ) );
213 $index = $day % $count;
214
215 if( ! isset( $options[ $index ] ) ) {
216 $index = 0;
217 }
218
219 return $options[ $index ];
220
221 }
222
223 /**
224 * Add Try submenu
225 *
226 * @since 1.0.0
227 */
228 function gamipress_try_admin_submenu() {
229
230 $option = gamipress_get_try_option();
231
232 if( ! $option ) return;
233
234 // Set minimum role for menu
235 $minimum_role = gamipress_get_manager_capability();
236
237 $badge = '<span class="gamipress-admin-menu-badge">' . __( 'New', 'gamipress' ) . '</span>';
238
239 add_submenu_page( 'gamipress', $option['label'], $option['label'] . $badge, $minimum_role, 'https://wordpress.org/plugins/' . $option['slug'] . '/', null );
240 }
241 add_action( 'admin_menu', 'gamipress_try_admin_submenu', 9999 );
242
243 /**
244 * Helper funtion to meet if should show the admin bar menu
245 *
246 * @since 2.0.3
247 */
248 function gamipress_show_admin_bar_menu() {
249
250 // Bail if GamiPress is active network wide and we are not in main site
251 if( gamipress_is_network_wide_active() && ! is_main_site() ) {
252 return false;
253 }
254
255 // Bail if current user can't manage GamiPress
256 if ( ! current_user_can( gamipress_get_manager_capability() ) ) {
257 return false;
258 }
259
260 // Bail if admin bar menu disabled
261 if( (bool) gamipress_get_option( 'disable_admin_bar_menu', false ) ) {
262 return false;
263 }
264
265 return true;
266
267 }
268
269 /**
270 * Add GamiPress admin bar menu
271 *
272 * @since 1.5.1
273 *
274 * @param WP_Admin_Bar $wp_admin_bar
275 */
276 function gamipress_admin_bar_menu( $wp_admin_bar ) {
277
278 // Bail if admin bar menu disabled
279 if( ! gamipress_show_admin_bar_menu() ) {
280 return;
281 }
282
283 // GamiPress
284 $wp_admin_bar->add_node( array(
285 'id' => 'gamipress',
286 'title' => '<span class="ab-icon"></span>' . 'GamiPress',
287 'href' => admin_url( 'admin.php?page=gamipress' ),
288 'meta' => array( 'class' => 'gamipress' ),
289 ) );
290
291 // Dashboard Group
292 $wp_admin_bar->add_group( array(
293 'id' => 'gamipress-dashboard-group',
294 'parent' => 'gamipress',
295 ) );
296
297 // Dashboard
298 $wp_admin_bar->add_node( array(
299 'id' => 'gamipress-dashboard',
300 'title' => __( 'Dashboard', 'gamipress' ),
301 'parent' => 'gamipress-dashboard-group',
302 'href' => admin_url( 'admin.php?page=gamipress' )
303 ) );
304
305 // Check registered points types
306 $points_types = gamipress_get_points_types();
307
308 // - Points Types
309 $wp_admin_bar->add_node( array(
310 'id' => 'points-types',
311 'title' => __( 'Points Types', 'gamipress' ),
312 'parent' => ( ! empty( $points_types ) ? 'points-group' : 'gamipress' ),
313 'href' => admin_url( 'edit.php?post_type=points-type' )
314 ) );
315
316 if( ! empty( $points_types ) ) {
317
318 // Points Group
319 $wp_admin_bar->add_group( array(
320 'id' => 'points-group',
321 'parent' => 'gamipress',
322 ) );
323
324 foreach( $points_types as $points_type => $data ) {
325
326 // - - Achievements
327 $wp_admin_bar->add_node( array(
328 'id' => 'points-' . $points_type,
329 'title' => $data['plural_name'],
330 'parent' => 'points-types',
331 'href' => get_edit_post_link( $data['ID'] )
332 ) );
333
334 }
335
336 }
337
338 // Check registered achievement types
339 $achievement_types = gamipress_get_achievement_types();
340
341 // - Achievement Types
342 $wp_admin_bar->add_node( array(
343 'id' => 'achievement-types',
344 'title' => __( 'Achievement Types', 'gamipress' ),
345 'parent' => ( ! empty( $achievement_types ) ? 'achievements-group' : 'gamipress' ),
346 'href' => admin_url( 'edit.php?post_type=achievement-type' )
347 ) );
348
349 if( ! empty( $achievement_types ) ) {
350
351 // Achievements Group
352 $wp_admin_bar->add_group( array(
353 'id' => 'achievements-group',
354 'parent' => 'gamipress',
355 ) );
356
357 foreach( $achievement_types as $achievement_type => $data ) {
358
359 // - - Achievements
360 $wp_admin_bar->add_node( array(
361 'id' => 'achievement-' . $achievement_type,
362 'title' => $data['plural_name'],
363 'parent' => 'achievement-types',
364 'href' => admin_url( 'edit.php?post_type=' . $achievement_type )
365 ) );
366
367 }
368
369 }
370
371 // Check registered rank types
372 $rank_types = gamipress_get_rank_types();
373
374 // - Rank Types
375 $wp_admin_bar->add_node( array(
376 'id' => 'rank-types',
377 'title' => __( 'Rank Types', 'gamipress' ),
378 'parent' => ( ! empty( $rank_types ) ? 'ranks-group' : 'gamipress' ),
379 'href' => admin_url( 'edit.php?post_type=rank-type' )
380 ) );
381
382 if( ! empty( $rank_types ) ) {
383
384 // Achievements Group
385 $wp_admin_bar->add_group( array(
386 'id' => 'ranks-group',
387 'parent' => 'gamipress',
388 ) );
389
390 foreach( $rank_types as $rank_type => $data ) {
391
392 // - - Achievements
393 $wp_admin_bar->add_node( array(
394 'id' => 'rank-' . $rank_type,
395 'title' => $data['plural_name'],
396 'parent' => 'rank-types',
397 'href' => admin_url( 'edit.php?post_type=' . $rank_type )
398 ) );
399
400 }
401
402 }
403
404 }
405 add_action( 'admin_bar_menu', 'gamipress_admin_bar_menu', 100 );
406
407 /**
408 * Add GamiPress admin bar custom tables menu
409 *
410 * @since 1.5.4
411 */
412 function gamipress_admin_bar_custom_tables_menu( $wp_admin_bar ) {
413
414 // Bail if admin bar menu disabled
415 if( ! gamipress_show_admin_bar_menu() ) {
416 return;
417 }
418
419 // User Earnings
420 $wp_admin_bar->add_node( array(
421 'id' => 'gamipress-user-earnings',
422 'title' => __( 'User Earnings', 'gamipress' ),
423 'parent' => 'gamipress',
424 'href' => admin_url( 'admin.php?page=gamipress_user_earnings' )
425 ) );
426
427 // Logs
428 $wp_admin_bar->add_node( array(
429 'id' => 'gamipress-logs',
430 'title' => __( 'Logs', 'gamipress' ),
431 'parent' => 'gamipress',
432 'href' => admin_url( 'admin.php?page=gamipress_logs' )
433 ) );
434
435 }
436 add_action( 'admin_bar_menu', 'gamipress_admin_bar_custom_tables_menu', 150 );
437
438 /**
439 * Add GamiPress admin bar menu
440 *
441 * @since 1.5.1
442 *
443 * @param object $wp_admin_bar The WordPress toolbar object
444 */
445 function gamipress_admin_bar_submenu( $wp_admin_bar ) {
446
447 // Bail if admin bar menu disabled
448 if( ! gamipress_show_admin_bar_menu() ) {
449 return;
450 }
451
452 // Badge Builder
453 $wp_admin_bar->add_node( array(
454 'id' => 'gamipress-badge-builder',
455 'title' => __( 'Badge Builder', 'gamipress' ),
456 'parent' => 'gamipress',
457 'href' => admin_url( 'admin.php?page=gamipress_badge_builder' )
458 ) );
459
460 // Tools
461 $wp_admin_bar->add_node( array(
462 'id' => 'gamipress-tools',
463 'title' => __( 'Tools', 'gamipress' ),
464 'parent' => 'gamipress',
465 'href' => admin_url( 'admin.php?page=gamipress_tools' )
466 ) );
467
468 // Settings
469 $wp_admin_bar->add_node( array(
470 'id' => 'gamipress-settings',
471 'title' => __( 'Settings', 'gamipress' ),
472 'parent' => 'gamipress',
473 'href' => admin_url( 'admin.php?page=gamipress_settings' )
474 ) );
475
476 // Licenses
477 $wp_admin_bar->add_node( array(
478 'id' => 'gamipress-licenses',
479 'title' => __( 'Licenses', 'gamipress' ),
480 'parent' => 'gamipress',
481 'href' => admin_url( 'admin.php?page=gamipress_licenses' )
482 ) );
483
484 // Assets
485 $wp_admin_bar->add_node( array(
486 'id' => 'gamipress-assets',
487 'title' => __( 'Assets', 'gamipress' ),
488 'parent' => 'gamipress',
489 'href' => admin_url( 'admin.php?page=gamipress_assets' )
490 ) );
491
492 // Add-ons
493 $wp_admin_bar->add_node( array(
494 'id' => 'gamipress-add-ons',
495 'title' => __( 'Add-ons', 'gamipress' ),
496 'parent' => 'gamipress',
497 'href' => admin_url( 'admin.php?page=gamipress_add_ons' )
498 ) );
499
500 }
501 add_action( 'admin_bar_menu', 'gamipress_admin_bar_submenu', 999 );
502
503 /**
504 * Add Try admin bar submenu
505 *
506 * @since 1.0.0
507 *
508 * @param object $wp_admin_bar The WordPress toolbar object
509 */
510 function gamipress_try_admin_bar_submenu( $wp_admin_bar ) {
511
512 // Bail if current user can't manage
513 if ( ! current_user_can( gamipress_get_manager_capability() ) ) {
514 return;
515 }
516
517 // Bail if admin bar menu disabled
518 if( (bool) gamipress_get_option( 'disable_admin_bar_menu', false ) ) {
519 return;
520 }
521
522 $option = gamipress_get_try_option();
523
524 if( ! $option ) return;
525
526 $badge = '<span class="gamipress-admin-menu-badge">' . __( 'New', 'gamipress' ) . '</span>';
527
528 // Try AutomatorWP
529 $wp_admin_bar->add_node( array(
530 'id' => 'gamipress-try',
531 'title' => $option['label'] . $badge,
532 'parent' => 'gamipress',
533 'href' => 'https://wordpress.org/plugins/' . $option['slug'] . '/'
534 ) );
535
536 }
537 add_action( 'admin_bar_menu', 'gamipress_try_admin_bar_submenu', 999 );
538
539 /**
540 * Register our custom columns
541 *
542 * @since 1.0.6
543 * @updated 1.3.9.5 Added the thumbnail column
544 *
545 * @param $posts_columns
546 * @param $post_type
547 *
548 * @return mixed
549 */
550 function gamipress_posts_columns( $posts_columns, $post_type ) {
551
552 if( ! in_array( $post_type, array( 'points-type', 'achievement-type', 'rank-type' ) ) ) {
553 return $posts_columns;
554 }
555
556 // Switch Title to Singular Name
557 $posts_columns['title'] = __( 'Singular Name', 'gamipress' );
558
559 // Prepend the thumbnail column
560 $chunks = array_chunk( $posts_columns, 1, true );
561 $chunks[0]['thumbnail'] = __( 'Image', 'gamipress' );
562
563 $posts_columns = call_user_func_array( 'array_merge', $chunks );
564
565 // Try to place our column before date column
566 $pos = array_search( 'date', array_keys( $posts_columns ) );
567
568 if ( ! is_int( $pos ) ) {
569 $pos = 1;
570 }
571
572 // Place our column in our desired position
573 $chunks = array_chunk( $posts_columns, $pos, true );
574 $chunks[0]['plural_name'] = __( 'Plural Name', 'gamipress' );
575 $chunks[0]['post_name'] = __( 'Slug', 'gamipress' );
576
577 if( $post_type === 'achievement-type' ) {
578 $chunks[0]['posts_count'] = __( 'Achievements', 'gamipress' );
579 } else if( $post_type === 'rank-type' ) {
580 $chunks[0]['posts_count'] = __( 'Ranks', 'gamipress' );
581 }
582
583 return call_user_func_array( 'array_merge', $chunks );
584 }
585 add_filter( 'manage_posts_columns', 'gamipress_posts_columns', 10, 2 );
586
587 /**
588 * Output for our custom columns
589 *
590 * @since 1.0.6
591 * @updated 1.3.9.5 Added the thumbnail column output
592 *
593 * @param $column_name
594 * @param $post_id
595 */
596 function gamipress_posts_custom_columns( $column_name, $post_id ) {
597
598 global $wpdb;
599
600 if( ! in_array( gamipress_get_post_type( $post_id ), array( 'points-type', 'achievement-type', 'rank-type' ) ) ) {
601 return;
602 }
603
604 switch( $column_name ) {
605 case 'thumbnail':
606 $can_edit_post = current_user_can( 'edit_post', $post_id );
607
608 if( $can_edit_post ) {
609 printf(
610 '<a href="%s" aria-label="%s">%s</a>',
611 get_edit_post_link( $post_id ),
612 /* translators: %s: post title */
613 esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), get_post_field( 'post_title', $post_id ) ) ),
614 gamipress_get_the_post_thumbnail( $post_id, array( 32, 32 ) )
615 );
616 } else {
617 echo gamipress_get_the_post_thumbnail( $post_id, array( 32, 32 ) );
618 }
619
620 break;
621 case 'plural_name':
622 echo esc_html( gamipress_get_post_meta( $post_id, '_gamipress_plural_name' ) );
623 break;
624 case 'post_name':
625 echo esc_html( gamipress_get_post_field( 'post_name', $post_id ) );
626 break;
627 case 'posts_count':
628 $posts = GamiPress()->db->posts;
629 $post_type = gamipress_get_post_field( 'post_name', $post_id );
630
631 $count = absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$posts} WHERE post_type = %s", $post_type ) ) );
632 $url = admin_url( 'edit.php?post_type=' . $post_type );
633
634 echo '<a href="' . esc_attr( $url ) . '">' . esc_html( $count ) . '</a>';
635 break;
636 }
637 }
638 add_action( 'manage_posts_custom_column', 'gamipress_posts_custom_columns', 10, 2 );
639
640 /**
641 * On delete our post, remove relationships
642 *
643 * @since 1.1.5
644 *
645 * @param integer $post_id
646 */
647 function gamipress_on_delete_post( $post_id ) {
648 global $wpdb;
649
650 $post_type = gamipress_get_post_type( $post_id );
651
652 $is_achievement = gamipress_is_achievement( $post_id );
653 $is_rank = gamipress_is_rank( $post_id );
654
655 $delete_user_earnings = ( in_array( $post_type, gamipress_get_requirement_types_slugs() ) );
656
657 if( $post_type === 'achievement-type' || $post_type === 'rank-type' ) {
658 // Remove all achievements of this achievement type or if is a rank type, remove all ranks of this rank type
659
660 $dependent_type = get_post_field( 'post_name', $post_id );
661
662 $posts = GamiPress()->db->posts;
663
664 $dependents = $wpdb->get_results( $wpdb->prepare( "SELECT p.ID FROM {$posts} AS p WHERE p.post_type = %s", $dependent_type ) );
665
666 foreach( $dependents as $dependent ) {
667 // Remove the achievement or rank of this type
668 wp_delete_post( $dependent->ID );
669 }
670 } else if( $post_type === 'points-type' ) {
671
672 // Get assigned points awards
673 $points_awards = gamipress_get_points_type_points_awards( $post_id, 'any' );
674
675 if( $points_awards ) {
676
677 foreach( $points_awards as $points_award ) {
678 // Remove the points award
679 wp_delete_post( $points_award->ID );
680 }
681
682 }
683
684 // Get assigned points deducts
685 $points_deducts = gamipress_get_points_type_points_deducts( $post_id, 'any' );
686
687 if( $points_deducts ) {
688
689 foreach( $points_deducts as $points_deduct ) {
690 // Remove the points deduct
691 wp_delete_post( $points_deduct->ID );
692 }
693
694 }
695
696 } else if( $is_achievement || $is_rank ) {
697 // Remove steps/rank requirements assigned
698
699 // Force to delete user earnings
700 $delete_user_earnings = true;
701
702 if( $is_rank ) {
703 $requirement_type = 'rank-requirement';
704 } else if ( $is_achievement ) {
705 $requirement_type = 'step';
706 }
707
708 if( ! isset( $requirement_type ) ) {
709 return;
710 }
711
712 // Get assigned requirements
713 $assigned_requirements = gamipress_get_assigned_requirements( $post_id, $requirement_type, 'any' );
714
715 if( $assigned_requirements ) {
716
717 foreach( $assigned_requirements as $requirement ) {
718 // Remove the requirement
719 wp_delete_post( $requirement->ID );
720 }
721
722 }
723 }
724
725 // Delete assigned user earnings
726 if( $delete_user_earnings ) {
727
728 $user_earnings = GamiPress()->db->user_earnings;
729 $user_earnings_meta = GamiPress()->db->user_earnings_meta;
730
731 // Delete all user's earnings
732 $wpdb->query( "DELETE ue FROM {$user_earnings} AS ue WHERE ue.post_id = {$post_id}" );
733 // Delete orphaned user earnings metas
734 $wpdb->query( "DELETE uem FROM {$user_earnings_meta} uem LEFT JOIN {$user_earnings} ue ON ue.user_earning_id = uem.user_earning_id WHERE ue.user_earning_id IS NULL" );
735 }
736
737 }
738 add_action( 'delete_post', 'gamipress_on_delete_post' );
739
740 /**
741 * Processes all GamiPress actions sent via POST and GET by looking for the 'gamipress-action' request and running do_action() to call the function
742 *
743 * @since 1.1.5
744 */
745 function gamipress_process_actions() {
746
747 // $_REQUEST
748 if ( isset( $_REQUEST['gamipress-action'] ) ) {
749 do_action( 'gamipress_action_request_' . $_REQUEST['gamipress-action'], $_REQUEST );
750 }
751
752 // $_POST
753 if ( isset( $_POST['gamipress-action'] ) ) {
754 do_action( 'gamipress_action_post_' . $_POST['gamipress-action'], $_POST );
755 }
756
757 // $_GET
758 if ( isset( $_GET['gamipress-action'] ) ) {
759 do_action( 'gamipress_action_get_' . $_GET['gamipress-action'], $_GET );
760 }
761
762 }
763 add_action( 'admin_init', 'gamipress_process_actions' );
764
765 /**
766 * Add custom footer text to the admin dashboard
767 *
768 * @since 1.3.8.1
769 *
770 * @param string $footer_text The existing footer text
771 *
772 * @return string
773 */
774 function gamipress_admin_footer_text( $footer_text ) {
775
776 global $typenow;
777
778 if (
779 $typenow === 'points-type'
780 || $typenow === 'achievement-type'
781 || $typenow === 'rank-type'
782 || in_array( $typenow, gamipress_get_achievement_types_slugs() )
783 || in_array( $typenow, gamipress_get_rank_types_slugs() )
784 || ( isset( $_GET['page'] ) && (
785 $_GET['page'] === 'gamipress_settings'
786 || $_GET['page'] === 'gamipress_logs'
787 || $_GET['page'] === 'edit_gamipress_logs'
788 || $_GET['page'] === 'gamipress_add_ons'
789 || $_GET['page'] === 'gamipress_assets'
790 || $_GET['page'] === 'gamipress_help_support'
791 || $_GET['page'] === 'gamipress_badge_builder'
792 || $_GET['page'] === 'gamipress_tools'
793 || $_GET['page'] === 'gamipress'
794 )
795 )
796 ) {
797
798 $gamipress_footer_text = sprintf( __( 'Thank you for using <a href="%1$s" target="_blank">GamiPress</a>! Please leave us a <a href="%2$s" target="_blank">%3$s</a> rating on WordPress.org', 'gamipress' ),
799 'https://gamipress.com',
800 'https://wordpress.org/support/plugin/gamipress/reviews/?rate=5#new-post',
801 '&#9733;&#9733;&#9733;&#9733;&#9733;'
802 );
803
804 return str_replace( '</span>', '', $footer_text ) . ' | ' . $gamipress_footer_text . '</span>';
805
806 } else {
807
808 return $footer_text;
809
810 }
811
812 }
813 add_filter( 'admin_footer_text', 'gamipress_admin_footer_text' );