require_files(); /** * Add the necessary action hooks. */ $this->add_actions(); } /** * Require the necessary files. * * @since 0.1.0 * * @return void */ private function require_files() { /** * The helper functions. */ require( plugin_dir_path( __FILE__ ) . 'functions.php' ); } /** * Add the necessary action hooks. * * @since 0.1.0 * * @return void */ private function add_actions() { // Load the text domain for i18n. add_action( 'init', array( $this, 'load_textdomain' ) ); // If checked in the settings, load the default and custom styles. if ( get_option( '_av_styling', 1 ) == 1 ) { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); add_action( 'wp_head', array( $this, 'custom_styles' ) ); } // Maybe display the overlay. add_action( 'wp_footer', array( $this, 'verify_overlay' ) ); // Maybe hide the content of a restricted content type. add_action( 'the_content', array( $this, 'restrict_content' ) ); // Verify the visitor's input. add_action( 'template_redirect', array( $this, 'verify' ) ); // If checked in the settings, add to the registration form. if ( av_confirmation_required() ) { add_action( 'register_form', 'av_register_form' ); add_action( 'register_post', 'av_register_check', 10, 3 ); } } /** * Load the text domain. * * Based on the bbPress implementation. * * @since 0.1.0 * * @return The textdomain or false on failure. */ public function load_textdomain() { $locale = get_locale(); $locale = apply_filters( 'plugin_locale', $locale, 'age-verify' ); $mofile = sprintf( 'age-verify-%s.mo', $locale ); $mofile_local = plugin_dir_path( dirname( __FILE__ ) ) . 'languages/' . $mofile; $mofile_global = WP_LANG_DIR . '/age-verify/' . $mofile; if ( file_exists( $mofile_local ) ) return load_textdomain( 'age-verify', $mofile_local ); if ( file_exists( $mofile_global ) ) return load_textdomain( 'age-verify', $mofile_global ); load_plugin_textdomain( 'age-verify' ); return false; } /** * Enqueue the styles. * * @since 0.1.0 * * @return void */ public function enqueue_styles() { wp_enqueue_style( 'av-styles', plugin_dir_url( __FILE__ ) . 'assets/styles.css' ); } /** * Print the custom colors, as defined in the admin. * * @since 0.1.0 * * @return void */ public function custom_styles() { ?>

' . esc_html( av_get_the_desc() ). '

'; ?>
' . __( 'Please verify your age', 'age-verify' ) . '.' ), esc_html( av_get_minimum_age() ), esc_url( get_permalink( get_the_ID() ) ) ); } /** * Verify the visitor if the form was submitted. * * @since 0.1.0 * * @return void */ public function verify() { if ( ! isset( $_POST['av-nonce'] ) || ! wp_verify_nonce( $_POST['av-nonce'], 'verify-age' ) ) return; $redirect_url = remove_query_arg( array( 'age-verified', 'verify-error' ), wp_get_referer() ); $is_verified = false; $error = 1; // Catch-all in case something goes wrong $input_type = av_get_input_type(); switch ( $input_type ) { case 'checkbox' : if ( isset( $_POST['av_verify_confirm'] ) && (int) $_POST['av_verify_confirm'] == 1 ) $is_verified = true; else $error = 2; // Didn't check the box break; default : if ( checkdate( (int) $_POST['av_verify_m'], (int) $_POST['av_verify_d'], (int) $_POST['av_verify_y'] ) ) : $age = av_get_visitor_age( $_POST['av_verify_y'], $_POST['av_verify_m'], $_POST['av_verify_d'] ); if ( $age >= av_get_minimum_age() ) $is_verified = true; else $error = 3; // Not old enough else : $error = 4; // Invalid date endif; break; } $is_verified = apply_filters( 'av_passed_verify', $is_verified ); if ( $is_verified == true ) : do_action( 'av_was_verified' ); if ( isset( $_POST['av_verify_remember'] ) ) $cookie_duration = time() + ( av_get_cookie_duration() * 60 ); else $cookie_duration = 0; setcookie( 'age-verified', 1, $cookie_duration, COOKIEPATH, COOKIE_DOMAIN, false ); wp_redirect( esc_url_raw( $redirect_url ) . '?age-verified=' . wp_create_nonce( 'age-verified' ) ); exit; else : do_action( 'av_was_not_verified' ); wp_redirect( esc_url_raw( add_query_arg( 'verify-error', $error, $redirect_url ) ) ); exit; endif; } }