options = array( 'login' => get_option('ag_login'), 'register' => get_option('ag_register'), 'fail_text' => get_option('ag_fail'), 'remember_me' => get_option('ag_remember'), 'message' => get_option('ag_termm'), 'terms_page' => get_option('ag_url'), 'comments' => get_option('ag_comments'), 'lightbox' => get_option('ag_lightbox'), 'colors' => get_option('ag_colors') ); return true; } function update_options() { if(isset($_POST['ag_hidden']) && $_POST['ag_hidden'] == 'Y') { isset($_POST['ag_fail']) ? update_option('ag_fail', stripslashes($_POST['ag_fail'])) : update_option('ag_fail', ''); isset($_POST['ag_termm']) ? update_option('ag_termm', $_POST['ag_termm']) : update_option('ag_termm', ''); isset($_POST['ag_url']) ? update_option('ag_url', $_POST['ag_url']) : update_option('ag_url', ''); isset($_POST['ag_hidden']) ? update_option('ag_colors', array('text-color' => $_POST['ag_text_color'], 'bg-color' => $_POST['ag_bg_color'])) : update_option('ag_colors', array('text-color' => '#333', 'bg-color' => '#fafafa')); isset($_POST['ag_login']) ? update_option('ag_login', $_POST['ag_login']) : update_option('ag_login', ''); isset($_POST['ag_register']) ? update_option('ag_register', $_POST['ag_register']) : update_option('ag_register', ''); isset($_POST['ag_comments']) ? update_option('ag_comments', $_POST['ag_comments']) : update_option('ag_comments', ''); isset($_POST['ag_lightbox']) ? update_option('ag_lightbox', $_POST['ag_lightbox']) : update_option('ag_lightbox', ''); isset($_POST['ag_remember']) ? update_option('ag_remember', $_POST['ag_remember']) : update_option('ag_remember', ''); } $this->options = array( 'login' => get_option('ag_login'), 'register' => get_option('ag_register'), 'fail_text' => get_option('ag_fail'), 'remember_me' => get_option('ag_remember'), 'message' => get_option('ag_termm'), 'terms_page' => get_option('ag_url'), 'comments' => get_option('ag_comments'), 'lightbox' => get_option('ag_lightbox'), 'colors' => get_option('ag_colors') ); } function init() { // Localization load_plugin_textdomain('agreeable', false, basename( dirname( __FILE__ ) ) . '/languages' ); if (is_multisite()) { add_action( 'signup_extra_fields', array($this, 'ag_register_terms_accept'), 10, 3); add_action( 'signup_blogform', array($this, 'ag_register_terms_accept'), 10, 3); } $this->update_options(); } function ag_admin() { /* Plugin Stylesheet */ wp_enqueue_style( 'agreeable-css', plugins_url('css/admin.css', __FILE__), '', '1.3.5', 'screen'); } function ag_front() { /* Only load lightbox code on the frontend, where we need it */ if ( $this->is_login_page() ) { wp_enqueue_script('jquery'); } wp_enqueue_script( 'magnific', plugins_url('js/magnific.js', __FILE__),'', '', true); wp_enqueue_script( 'agreeable-js', plugins_url('js/agreeable.js', __FILE__), '', '', true); wp_enqueue_style( 'magnific', plugins_url('css/magnific.css', __FILE__)); wp_enqueue_style( 'agreeable-css', plugins_url('css/front.css', __FILE__)); } function registration_validation() { $errors = new WP_error(); if(isset($_REQUEST['ag_type']) && $_REQUEST['ag_type'] == 'register' && $this->options['register'] == 1) { if ( isset( $_REQUEST['ag_login_accept'] ) && $_REQUEST['ag_login_accept'] == 1) { return $errors; } else { $errors->add('ag_login_accept', $this->options['fail_text']); return $errors; } } else { return $errors; } } function ag_authenticate_user_acc($user) { if(isset($_REQUEST['ag_type']) && $_REQUEST['ag_type'] == "login" && $this->options['login'] == 1 || isset($_REQUEST['ag_type']) && $_REQUEST['ag_type'] == 'register' && $this->options['register'] == 1) { // See if the checkbox #ag_login_accept was checked if ( isset( $_REQUEST['ag_login_accept'] ) && $_REQUEST['ag_login_accept'] == 1) { // Checkbox on, allow login, set the cookie if necessary if ( !isset( $_COOKIE['agreeable_terms'] ) && $this->options['remember_me'] == 1 ) { setcookie( 'agreeable_terms', 'yes', strtotime('+30 days'), COOKIEPATH, COOKIE_DOMAIN, false ); } do_action('agreeable_validate_user', $user, $_REQUEST['ag_type']); unset($_SESSION['ag_errors']); return $user; } else { if($this->is_buddypress_registration()) { global $bp; $bp->signup->errors['ag_login_accept'] = $this->options['fail_text']; return; } $errors = new WP_Error(); $errors->add('ag_login_accept', $this->options['fail_text']); /* Incase it's a form that doesn't respect WordPress' error system */ $_SESSION['ag_errors'] = $this->options['fail_text']; if(is_multisite() && $this->is_multisite_register() && !$this->is_login_page()) { $result = $user; $result['errors'] = $errors; return $result; } return $errors; } } else { return $user; } } function is_woocommerce_page () { if( function_exists( "is_woocommerce" )){ $woocommerce_keys = array ( "woocommerce_shop_page_id" , "woocommerce_checkout_page_id" , "woocommerce_myaccount_page_id" ); foreach ( $woocommerce_keys as $wc_page_id ) { if ( get_the_ID () == get_option ( $wc_page_id , 0 ) ) { return true ; } } } return false; } function is_buddypress_registration() { if(function_exists('bp_current_component')) { /* Lets make sure we're on the right page- Ie the buddypress register page */ $bp_pages = get_option('bp-pages'); $bp_page = get_post($bp_pages['register']); global $wp_query; $current_page = isset($wp_query->query_vars['name']) ? $wp_query->query_vars['name'] : ''; return $bp_page->post_name == $current_page ? true : false; } } function ag_validate_comment($comment) { if($this->options['comments'] == 1) { // See if the checkbox #ag_login_accept was checked if ( isset( $_REQUEST['ag_login_accept'] ) && $_REQUEST['ag_login_accept'] == 1 ) { // Checkbox on, allow comment //do_action('agreeable_validate_user', $user, $_REQUEST['ag_type']); return $comment; } else { // Did NOT check the box, do not allow comment $error = new WP_Error(); $error->add('did_not_accept', $this->options['fail_text']); wp_die( __($this->options['fail_text']) ); return $error; } } else { return $comment; } } function ag_display_terms_form($type, $errors = '') { global $bp; if(isset($this->options['terms_page'])) { $terms = get_post($this->options['terms_page']); $terms_content = '

'.$terms->post_title.'

'.apply_filters('the_content', $terms->post_content); } /* Add an element to the login form, which must be checked */ $term_link = get_post_permalink($terms); $class = ''; if($this->options['lightbox'] == 1) { $class = 'ag-open-popup-link'; $term_link = '#ag-terms'; if($this->options['colors']) { echo ''; } } /* Get our errors incase we need to display */ $errors = new WP_Error; if(isset($_SESSION['ag_errors']) && $errors->get_error_message( 'ag_login_accept' ) == '') { $error = $_SESSION['ag_errors']; unset($_SESSION['ag_errors']); } if ( isset($error) && !$this->is_login_page()) { echo '

'.$error.'

'; } /* Are we remembering logins? Lets check. */ $remember = ''; if ( isset($_COOKIE['agreeable_terms'] ) && $this->options['remember_me'] == 1 ) { $remember = ' checked '; } if(!$this->is_woocommerce_page()) { echo '
'; if($this->is_buddypress_registration()){do_action( 'bp_ag_login_accept_errors' );} echo ''; echo '
'; echo $term_link == '#ag-terms' ? '
'.$terms_content.'
' : ''; echo $type == 'comments' ? '
':''; } } function ag_login_terms_accept($errors){ if($this->options['login'] == 1) { $this->ag_display_terms_form('login', $errors); } } function ag_comment_terms_accept(){ if($this->options['comments'] == 1) { $this->ag_display_terms_form('comments'); } } function ag_register_terms_accept($errors) { if($this->options['register'] == 1) { $this->ag_display_terms_form('register', $errors); if(class_exists('ThemeMyLogin')) { echo ''; } } return; } function ag_widget_terms_accept() { if($this->options['login'] == 1) { $this->ag_display_terms_form('login'); } echo ''; } function agreeable_options() { add_options_page('agreeable', 'Agreeable', 'manage_options', 'terms-options', array($this, 'agoptions')); } function agoptions() { include_once('includes/settings.php'); } /* Plugin cross promotion area */ function cross_promotions($plugin) { include('kp_cross_promote.php'); } function is_login_page() { return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')); } function is_multisite_register() { return in_array($GLOBALS['pagenow'], array('wp-signup.php')); } } $agreeable = new Agreeable();