Stambro

Download Monitor + Simple WordPress Membership Plugin

Dec 18th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2.  
  3. ### \download-monitor\src\DownloadHandler.php
  4.  
  5. ###
  6. ###    
  7. ###     BEFORE
  8. ###
  9. ###
  10.     public function check_members_only( $can_download, $download ) {
  11.  
  12.         // Check if download is a 'members only' download
  13.         if ( false !== $can_download && $download->is_members_only() ) {
  14.  
  15.             // Check if user is logged in
  16.             if ( ! is_user_logged_in() ) {
  17.                 $can_download = false;
  18.             } // Check if it's a multisite and if user is member of blog
  19.             else if ( is_multisite() && ! is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) {
  20.                 $can_download = false;
  21.             }
  22.  
  23.         }
  24.  
  25.         return $can_download;
  26.     }
  27.  
  28. ###
  29. ###
  30. ###     AFTER
  31. ###
  32. ###
  33.     public function check_members_only( $can_download, $download ) {
  34.  
  35.         // Check if download is a 'members only' download
  36.         if ( false !== $can_download && $download->is_members_only() ) {
  37.  
  38.             // Check if user is logged in
  39.             if ( ! is_user_logged_in() ) {
  40.                 $can_download = false;
  41.             } // Check if it's a multisite and if user is member of blog
  42.             else if ( is_multisite() && ! is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) {
  43.                 $can_download = false;
  44.             }
  45.             else if ( !current_user_can('editor') &&  !current_user_can('administrator') ) {
  46.                 global $wpdb;
  47.                 $current_user = wp_get_current_user();
  48.                 $table =  $wpdb->prefix . "swpm_members_tbl";
  49.                 $sql = "SELECT `account_state` FROM `{$table}` WHERE email = \"%s\";";
  50.                 $res = $wpdb->get_var( $wpdb->prepare( $sql,  $current_user->user_email ) );
  51.                 if ($res != "active") header("Location: /access-renewal/");
  52.             }
  53.         }
  54.  
  55.         return $can_download;
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment