Ejemplo n.º 1
0
 static function check_access($exam, $post)
 {
     WatuPRO::$output_sent = false;
     // change this var from class method to avoid outputting the generic message
     if (!WatuPRO::can_access($exam)) {
         // not logged in error
         if (!is_user_logged_in()) {
             echo "<p><b>" . sprintf(__('You need to be registered and logged in to take this %s.', 'watupro'), __('quiz', 'watupro')) . " <a href='" . wp_login_url(get_permalink($post->ID)) . "'>" . __('Log in', 'watupro') . "</a>";
             if (get_option("users_can_register")) {
                 echo " " . __('or', 'watupro') . " <a href='" . wp_registration_url() . "'>" . __('Register', 'watupro') . "</a></b>";
             }
             echo "</p>";
         } else {
             // logged in but no rights to access
             if (!WatuPRO::$output_sent) {
                 echo "<p>" . __('You are not allowed to access this exam at the moment.', 'watupro') . "</p><!-- logged in but no rights to access-->";
             }
         }
         return false;
         // can_access returned false
     }
     return true;
 }
Ejemplo n.º 2
0
 static function can_access($exam)
 {
     // always access public exams
     if (!$exam->require_login) {
         return true;
     }
     if ($exam->require_login and !is_user_logged_in()) {
         return false;
     }
     // admin can always access
     if (current_user_can('manage_options') or current_user_can('watupro_manage_exams')) {
         if (empty($_POST['action']) and $exam->fee > 0) {
             echo "<b>" . __('Note: This quiz requires payment, but you are administrator and do not need to go through it.', 'watupro') . "</b>";
         }
         return true;
     }
     // USER GROUP CHECKS
     $allowed = WTPCategory::has_access($exam);
     if (!$allowed) {
         echo "<!-- not in allowed user group -->";
         return false;
     }
     // INTELLIGENCE MODULE RESTRICTIONS
     if (watupro_intel()) {
         if ($exam->fee > 0) {
             require_once WATUPRO_PATH . "/i/models/payment.php";
             if (!empty($_POST['stripe_pay'])) {
                 WatuPROPayment::Stripe();
             }
             // process Stripe payment if any
             if (!WatuPROPayment::valid_payment($exam)) {
                 self::$output_sent = WatuPROPayment::render($exam);
                 return false;
             }
         }
         require_once WATUPRO_PATH . "/i/models/dependency.php";
         if (!WatuPRODependency::check($exam)) {
             echo "<!-- WATUPROCOMMENT unsatisfied dependencies -->";
             return false;
         }
     }
     return true;
 }