Advertisement
designbymerovingi

Adjust users balance when deleting a log entry

Feb 28th, 2015
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. /**
  2.  * Log Entry Intercept
  3.  * Will deduct the points from a users account before the entry
  4.  * is deleted from the log.
  5.  * @version 1.1
  6.  */
  7. add_action( 'wp_ajax_mycred-delete-log-entry', 'mycred_pro_delete_entry_ajax', 0 );
  8. function mycred_pro_delete_entry_ajax() {
  9.  
  10.     // Security
  11.     check_ajax_referer( 'mycred-delete-log-entry', 'token' );
  12.  
  13.     global $wpdb, $mycred;
  14.  
  15.     if ( ! isset( $mycred->log_table ) )
  16.         $mycred = mycred();
  17.  
  18.     // Get the log entry
  19.     $entry = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$mycred->log_table} WHERE id = %d;", $_POST['row'] ) );
  20.  
  21.     if ( isset( $entry->id ) ) {
  22.  
  23.         $mycred = mycred( $entry->ctype );
  24.  
  25.         // Deduct if user gained points
  26.         if ( $entry->creds > 0 )
  27.             $entry->creds = 0 - $entry->creds;
  28.  
  29.         // Add if user lost points
  30.         else
  31.             $entry->creds = abs( $entry->creds );
  32.  
  33.         // Adjust the users balance
  34.         $mycred->update_users_balance( $entry->user_id, $entry->creds, $entry->ctype );
  35.  
  36.     }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement