BuddyDev

Search

Replies

  • Participant
    Level: Initiated
    Posts: 2
    Gert on #11290

    Modifying the php file worked.

    Is there a way to redirect site.com/register to site.com with javascript overlay that shows the register page?

    add_action('init', 'redirect_register_login')
    function redirect_register_login(){
      global $pagenow;
      $action = (isset($_GET['action'])) ? $_GET['action'] : '';
      
      //doesn't work
      
    if( in_array($pagenow, array('wp-login.php', 'wp-admin.php', 'wp-register.php')) && ( ! $action || ( $action && ! in_array($action, array('logout', 'lostpassword', 'rp', 'resetpass'))))) {
        wp_redirect(get_bloginfo('url'));
      }
      
    // is_page('register') also doesn't work
    
    }

    Any ideas? (I realize that if javascript is disabled in the browser users won’t be able to login or register)

  • Participant
    Level: Initiated
    Posts: 2
    Gert on #11070

    Thanks for the suggestions Brajesh

    I’ve added a checkbox on the register page and added code below to register it in db. (Also modified Ajax to have the field as required)

    add_action( 'user_register', 'tos_registration_save', 10, 1 );
    function tos_registration_save( $user_id ) {
        if ( isset( $_POST['terms_of_service'] ) ){
            $terms_of_service = filter_input(INPUT_GET, 'terms_of_service', FILTER_VALIDATE_BOOLEAN );
                update_user_meta($user_id, 'terms_of_service', $_POST['terms_of_service']);
        }
    }
    add_action( 'show_user_profile', 'show_terms_field' );
    add_action( 'edit_user_profile', 'show_terms_field' );
    function show_terms_field( $user ) { ?>
    	<table class="form-table">
    
    		<tr>
    			<th><label for="terms">Terms of service & privacy policy:</label></th>
    
    			<td>
                                <span><?php echo esc_attr(get_the_author_meta( 'terms_of_service', $user->ID )) ? 'Agreed' : '' ; ?></span>
    			</td>
    		</tr>
    
    	</table>
    <?php }

    However, over time tos may change so I would need to ask registered members to agree to the new tos if they want to continue using the site or just have a banner that they can click away to notify them. Building further on this seems a messy way to me.

    Any suggestions?