function memberaccess_has_coupon($coupon_id) { $cookies = MemberAccess_Coupons::get_member_coupons(); if (empty($cookies)) { return false; } if (!(int) $coupon_id) { $coupons = new WP_query(array('post_type' => 'acp-coupons', 'name' => sanitize_title_with_dashes($coupon_id))); if (!$coupons->have_posts()) { return false; } $coupons->the_post(); $coupon_id = get_the_ID(); wp_reset_query(); } foreach ($cookies as $name => $cookie) { if ($cookie[1] != $coupon_id) { continue; } $auth = get_post_meta($cookie[1], '_acp_coupon_auth_key') ? MemberAccess_Coupons::get_authorization_key($cookie[1], !empty($cookie[2]) ? $cookie[2] : null) : md5($name); if ($auth == $_COOKIE[$name]) { return true; } } return false; }
function memberaccess_coupon_shortcode($atts, $content = '') { $atts = shortcode_atts(array('id' => 0, 'product' => 0, 'redirect' => ''), $atts); $url = $atts['id'] ? get_permalink($atts['id']) : ''; if ($atts['product']) { $url = untrailingslashit($url) . '/product/' . $atts['product'] . ($url != untrailingslashit($url) ? '/' : ''); } $has_auth = false; if (get_post_meta($atts['id'], '_acp_coupon_auth_key', true)) { $url .= $has_auth = '?auth=' . MemberAccess_Coupons::get_authorization_key($atts['id'], $atts['product']); } if ($atts['redirect']) { $url .= ($has_auth ? '&' : '?') . 'redir=' . urlencode($atts['redirect']); } if ($content) { return sprintf('<a href="%s">%s</a>', $url, $content); } return $url; }