Suppose you have some information you want to direct first time users to, such as a rules page, or a list of certain posts, etc. You would like to do that the first time they login as a new user. You can do that with the magic of the wpmem_login_filter.
This first example is basic and will redirect a user to a page you define (where indicated in the code snippet comments).
add_filter( 'wpmem_login_redirect', 'my_first_login_redirect', 10, 2 ); function my_first_login_redirect( $redirect_to, $user_id ) { // Set page to redirect the user to. // @uses https://codex.wordpress.org/Function_Reference/home_url $redirect_url = home_url( 'my-page' ); // See if the user has already logged in before // @uses https://codex.wordpress.org/Function_Reference/get_user_meta $first_login = get_user_meta( $user_id, 'first_login', true ); if ( ! $first_login ) { // Sets that the user has done their first login // @uses https://codex.wordpress.org/Function_Reference/update_user_meta update_user_meta( $user_id, 'first_login', 'true' ); // Set redirect based on user's first login $redirect_to = $redirect_url; } return $redirect_to; }
The following example shows how to direct the user to the change password page if it is the first time they have logged in. (This assumes that you have a [wpmem_profile] page and that you have set the location of that page in the plugin’s settings for User Profile Page.)
add_filter( 'wpmem_login_redirect', 'password_change_login_redirect', 10, 2 ); function password_change_login_redirect( $redirect_to, $user_id ) { // Check for the presence of a flag if the user has logged in before. $first_login = wpmem_get_user_meta( $user_id, 'first_login' ); // If the user has never logged in, do this: if ( ! $first_login ) { // Set that the user has logged in the first time. update_user_meta( $user_id, 'first_login', 'true' ); // Return the user profile url for password change. return wpmem_profile_url( 'pwdchange' ); } return $redirect_to; }