/**
  * Hide the content if it is age restricted.
  *
  * @since 0.2.0
  *
  * @param  string $content The object content.
  * @return string $content The object content or an age-restricted message if needed.
  */
 public function restrict_content($content)
 {
     if (!av_only_content_restricted()) {
         return $content;
     }
     if (is_singular()) {
         return $content;
     }
     if (!av_content_is_restricted()) {
         return $content;
     }
     return sprintf(apply_filters('av_restricted_content_message', __('You must be %1s years old to view this content.', 'age-verify') . ' <a href="%2s">' . __('Please verify your age', 'age-verify') . '</a>.'), esc_html(av_get_minimum_age()), esc_url(get_permalink(get_the_ID())));
 }
Example #2
0
/**
 * This is the very important function that determines if a given visitor
 * needs to be verified before viewing the site. You can filter this if you like.
 *
 * @since 0.1
 * @return bool
 */
function av_needs_verification()
{
    // Assume the visitor needs to be verified
    $return = true;
    // If the site is restricted on a per-content basis, let 'em through
    if (av_only_content_restricted()) {
        $return = false;
        // If the content being viewed is restricted, throw up the form
        if (is_singular() && av_content_is_restricted()) {
            $return = true;
        }
    }
    // Check that the form was at least submitted. This lets visitors through that have cookies disabled.
    $nonce = isset($_REQUEST['age-verified']) ? $_REQUEST['age-verified'] : '';
    if (wp_verify_nonce($nonce, 'age-verified')) {
        $return = false;
    }
    // If logged in users are exempt, and the visitor is logged in, let 'em through
    if (get_option('_av_always_verify', 'guests') == 'guests' && is_user_logged_in()) {
        $return = false;
    }
    // Or, if there is a valid cookie let 'em through
    if (isset($_COOKIE['age-verified'])) {
        $return = false;
    }
    return (bool) apply_filters('av_needs_verification', $return);
}