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 / privacy / erasers / user-earnings.php

user-earnings.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at includes/privacy/erasers/user-earnings.php

86 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * User Earnings Erasers
4 *
5 * @package GamiPress\Privacy\Erasers\User_Earnings
6 * @author GamiPress <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.5.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Register eraser for user user earnings.
14 *
15 * @since 1.5.0
16 *
17 * @param array $erasers
18 *
19 * @return array
20 */
21 function gamipress_privacy_register_user_earnings_erasers( $erasers ) {
22
23 $erasers[] = array(
24 'eraser_friendly_name' => __( 'User Earnings', 'gamipress' ),
25 'callback' => 'gamipress_privacy_user_earnings_eraser',
26 );
27
28 return $erasers;
29
30 }
31 add_filter( 'wp_privacy_personal_data_erasers', 'gamipress_privacy_register_user_earnings_erasers' );
32
33 /**
34 * Eraser for user user earnings.
35 *
36 * @since 1.5.0
37 *
38 * @param string $email_address
39 * @param int $page
40 *
41 * @return array
42 */
43 function gamipress_privacy_user_earnings_eraser( $email_address, $page = 1 ) {
44
45 global $wpdb;
46
47 // Setup query vars
48 $user_earnings = GamiPress()->db->user_earnings;
49
50 // Important: keep always SELECT *, %d is user ID, and limit/offset will added automatically
51 $query = "DELETE FROM {$user_earnings} WHERE user_id = %d";
52 $count_query = str_replace( "DELETE", "SELECT COUNT(*)", $query );
53
54 // Setup vars
55 $response = array(
56 'items_removed' => true,
57 'items_retained' => false,
58 'messages' => array(),
59 'done' => true
60 );
61
62 $user = get_user_by( 'email', $email_address );
63
64 if ( $user && $user->ID ) {
65
66 // Erase user earnings
67 $erased = $wpdb->query( $wpdb->prepare( $query, $user->ID ) );
68
69 if( $erased ) {
70
71 $messages[] = sprintf( __( 'Removed %d user earnings.', 'gamipress' ), $erased );
72
73 }
74
75 // Check remaining items
76 $items_count = absint( $wpdb->get_var( $wpdb->prepare( $count_query, $user->ID ) ) );
77
78 // Process done!
79 $response['done'] = (bool) ( $items_count === 0 );
80
81 }
82
83 // Return our erased items
84 return $response;
85
86 }