Skip to content

Add functionality 'redirect after login' to LearnPress settings #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions inc/admin/settings/class-lp-settings-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public function get_settings( $section = '', $tab = '' ) {
'type' => 'pages-dropdown',
'desc' => __( 'The page where user will be redirected to after logging out.', 'learnpress' )
),
array(
'title' => __( 'Login redirect', 'learnpress' ),
'id' => 'login_redirect_page_id',
'default' => '',
'type' => 'pages-dropdown',
'desc' => __( 'The page where user will be redirected to after logging in.', 'learnpress' )
),
array(
'title' => __( 'Currency', 'learnpress' ),
'type' => 'heading',
Expand Down
30 changes: 24 additions & 6 deletions inc/user/lp-user-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ function learn_press_get_temp_users() {
global $wpdb;
$query = $wpdb->prepare( "
SELECT ID
FROM {$wpdb->users} u
FROM {$wpdb->users} u
INNER JOIN {$wpdb->usermeta} um ON u.ID = um.user_id AND um.meta_key = %s AND um.meta_value = %s
LEFT JOIN {$wpdb->usermeta} um2 ON u.ID = um2.user_id AND um2.meta_key = %s
", '_lp_temp_user', 'yes', '_lp_expiration' );
Expand Down Expand Up @@ -913,13 +913,13 @@ function learn_press_user_update_user_info() {
}
exit();
}
#
#
# END OF UPLOAD TEMP PROFILE PICTURE
# - - - - - - - - - - - - - - - - - - - -

# - - - - - - - - - - - - - - - - - - - -
# CREATE PROFILE PICTURE & THUMBNAIL
#
#
if ( isset( $_POST['sub_action'] ) && 'crop_avatar' === $_POST['sub_action'] && isset( $_POST['avatar_filename'] ) ) {
$avatar_filename = filter_input( INPUT_POST, 'avatar_filename', FILTER_SANITIZE_STRING );
$avatar_filepath = $upload_dir . DIRECTORY_SEPARATOR . $avatar_filename;
Expand Down Expand Up @@ -1009,14 +1009,14 @@ function learn_press_user_update_user_info() {
}
exit();
}
#
#
# CREATE PROFILE PICTURE & THUMBNAIL
# - - - - - - - - - - - - - - - - - - - -


# - - - - - - - - - - - - - - - - - - - -
# UPDATE USER INFO
#
#
$return = array();
$update_data = array(
'ID' => $user_id,
Expand Down Expand Up @@ -1294,6 +1294,24 @@ function _learn_press_redirect_logout_redirect() {

add_action( 'wp_logout', '_learn_press_redirect_logout_redirect' );

function _learn_press_redirect_login_redirect() {
$redirect_to = LP_Request::get_string( 'redirect_to' );
$admin_url = admin_url();
$pos = strpos( $redirect_to, $admin_url );

if ( $pos !== false ) {
return;
}

if ( ( $page_id = LP()->settings->get( 'login_redirect_page_id' ) ) && get_post( $page_id ) ) {
$page_url = get_page_link( $page_id );
wp_redirect( $page_url );
exit();
}
}

add_action( 'wp_login', '_learn_press_redirect_login_redirect' );

function learn_press_get_profile_endpoints() {
$endpoints = (array) LP()->settings->get( 'profile_endpoints' );
if ( $tabs = LP_Profile::instance()->get_tabs() ) {
Expand Down Expand Up @@ -1758,7 +1776,7 @@ function learn_press_remove_user_items( $user_id, $item_id, $course_id, $include
$query = $wpdb->prepare( "
DELETE
FROM {$wpdb->learnpress_user_items}
WHERE user_id = %d
WHERE user_id = %d
AND ( item_id IN(" . join( ',', $format ) . ")
$where )
", $args );
Expand Down