* @copyright Copyright (c) 2012, Chase Wiseman * @link http://chasewiseman.com/plugins/age-verify/ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU * General Public License as published by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along with this program; if not, write * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // Don't access this directly, please if ( ! defined( 'ABSPATH' ) ) exit; /** * The main Age Verify class. * * @since 0.1 */ class Age_Verify { /** * Sets up everything. * * @since 0.1 * @access public */ public function __construct() { $this->setup_globals(); $this->includes(); $this->setup_actions(); } /** * Sets up the globals. * * @since 0.1 * @access private */ private function setup_globals() { // Directories and URLs $this->file = __FILE__; $this->basename = plugin_basename( $this->file ); $this->plugin_dir = plugin_dir_path( $this->file ); $this->plugin_url = plugin_dir_url ( $this->file ); $this->lang_dir = trailingslashit( $this->plugin_dir . 'languages' ); $this->admin_url = $this->plugin_url . 'admin'; $this->admin_dir = $this->plugin_dir . 'admin'; // Min age and cookie duration $this->minimum_age = get_option( '_av_minimum_age', '21' ); $this->cookie_duration = get_option( '_av_cookie_duration', '720' ); } /** * Require the necessary files * * @since 0.1 * @access private */ private function includes() { // This file defines all of the common functions require( $this->plugin_dir . 'functions.php' ); // If in the admin, this file sets up the admin functions if ( is_admin() ) : require( $this->admin_dir . '/admin.php' ); require( $this->admin_dir . '/settings.php' ); endif; } /** * Sets up the actions and filters. * * @since 0.1 * @access private */ private function setup_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' ) ); endif; // 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 ); endif; } /** * Load the text domain. Big thanks to bbPress for giving a great example of implementation. * * @since 0.1 * @access public */ public function load_textdomain() { $locale = get_locale(); $locale = apply_filters( 'plugin_locale', $locale, 'age_verify' ); $mofile = sprintf( 'age_verify-%s.mo', $locale ); $mofile_local = $this->lang_dir . $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 ); return false; } /** * Enqueue the styles. * * @since 0.1 * @access public */ public function enqueue_styles() { wp_enqueue_style( 'av-styles', $this->plugin_url . 'assets/styles.css' ); } /** * Print the custom colors, as defined in the admin. * * @since 0.1 * @access public */ public function custom_styles() { ?>