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__), '', '0.3.4', '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 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; return $result; } return $errors; } } else { return $user; } } function is_woocommerce_page () { if( function_exists( "is_woocommerce" ) && is_woocommerce()){ return true; } $woocommerce_keys = array ( "woocommerce_shop_page_id" , "woocommerce_terms_page_id" , "woocommerce_cart_page_id" , "woocommerce_checkout_page_id" , "woocommerce_pay_page_id" , "woocommerce_thanks_page_id" , "woocommerce_myaccount_page_id" , "woocommerce_edit_address_page_id" , "woocommerce_view_order_page_id" , "woocommerce_change_password_page_id" , "woocommerce_logout_page_id" , "woocommerce_lost_password_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'] == 'on' ) { // Checkbox on, allow comment return $comment; } else { // Did NOT check the box, do not allow login $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 = '
'.$error.'
'; } /* Are we remembering logins? Lets check. */ $remember = ''; if ( isset($_COOKIE['agreeable_terms'] ) && $this->options['remember_me'] == 1 ) { $remember = ' checked '; } echo '