Example #1
0
 /**
  * Stores a notice using WP set_transient()
  *
  * Generates a unique key for the transient name based on the user ID (registered users) or IP (visitors)
  *
  * @param int $expiration (optional) Time until expiration in seconds, default 0
  * @return bool False if value was not set and true if value was set.
  */
 private static function set_transient($expiration = 0)
 {
     if (is_user_logged_in()) {
         $result = set_transient(self::$transient_key . '-' . get_current_user_id(), self::$notices, $expiration);
     } else {
         $result = appthemes_set_visitor_transient(self::$transient_key, self::$notices, $expiration);
     }
     return $result;
 }
Example #2
0
 /**
  * Stores a notice using WP set_transient()
  *
  * Generates a unique key for the transient name based on the user ID (registered users) or IP (visitors)
  *
  * @param int $expiration (optional) Time until expiration in seconds, default 0
  * @return bool False if value was not set and true if value was set.
  */
 private static function set_transient($expiration = 0)
 {
     // skip if the notices object is empty
     if (!self::$notices->get_error_code()) {
         return false;
     }
     if (is_user_logged_in()) {
         $result = set_transient(self::$transient_key . '-' . get_current_user_id(), self::$notices, $expiration);
     } else {
         $result = appthemes_set_visitor_transient(self::$transient_key, self::$notices, $expiration);
     }
     return $result;
 }
Example #3
0
function appthemes_require_login($args = array())
{
    if (is_user_logged_in()) {
        return;
    }
    $page_url = scbUtil::get_current_url();
    $args = wp_parse_args($args, array('login_text' => __('You must first login.', APP_TD), 'login_register_text' => __('You must first login or <a href="%s">register</a>.', APP_TD)));
    if (get_option('users_can_register')) {
        $register_url = appthemes_get_registration_url();
        $register_url = add_query_arg('redirect_to', $page_url, $register_url);
        $message = sprintf($args['login_register_text'], $register_url);
    } else {
        $message = $args['login_text'];
    }
    appthemes_set_visitor_transient('login_notice', array('error', $message), 300);
    appthemes_auth_redirect_login();
    exit;
}