mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
Custom redirects for login
This commit is contained in:
@@ -244,6 +244,8 @@ class UM_Admin_Metabox {
|
||||
add_meta_box('um-admin-form-register_customize', __('<i class="um-icon-cog-1"></i>Customize this form'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default');
|
||||
add_meta_box('um-admin-form-profile_customize', __('<i class="um-icon-cog-1"></i>Customize this form'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default');
|
||||
add_meta_box('um-admin-form-login_customize', __('<i class="um-icon-cog-1"></i>Customize this form'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default');
|
||||
|
||||
add_meta_box('um-admin-form-login_settings', __('<i class="um-icon-tools"></i>Settings'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default');
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<div class="um-admin-metabox">
|
||||
|
||||
<p><label for="_um_login_after_login"><?php _e('Redirection after Login','ultimatemember'); ?> <?php $this->tooltip('Change this If you want to override role redirection settings after login only.', 'e'); ?></label>
|
||||
<select name="_um_login_after_login" id="_um_login_after_login" class="umaf-selectjs um-adm-conditional" style="width: 100%" data-cond1="redirect_url" data-cond1-show="_um_login_after_login">
|
||||
|
||||
<option value="0" <?php selected('0', $ultimatemember->query->get_meta_value('_um_login_after_login', null, 0 ) ); ?>><?php _e('Default','ultimatemember'); ?></option>
|
||||
<option value="redirect_profile" <?php selected('redirect_profile', $ultimatemember->query->get_meta_value('_um_login_after_login', null, 0 ) ); ?>>Redirect to profile</option>
|
||||
<option value="redirect_url" <?php selected('redirect_url', $ultimatemember->query->get_meta_value('_um_login_after_login', null, 0 ) ); ?>>Redirect to URL</option>
|
||||
<option value="refresh" <?php selected('refresh', $ultimatemember->query->get_meta_value('_um_login_after_login', null, 0 ) ); ?>>Refresh active page</option>
|
||||
<option value="redirect_admin" <?php selected('redirect_admin', $ultimatemember->query->get_meta_value('_um_login_after_login', null, 0 ) ); ?>>Redirect to WordPress Admin</option>
|
||||
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p class="_um_login_after_login">
|
||||
<label for="_um_login_redirect_url"><?php _e('Set Custom Redirect URL','ultimatemember'); ?> <?php $this->tooltip('', 'e'); ?></label>
|
||||
<input type="text" value="<?php echo $ultimatemember->query->get_meta_value('_um_login_redirect_url', null, 'na'); ?>" name="_um_login_redirect_url" id="_um_login_redirect_url" />
|
||||
</p>
|
||||
|
||||
</div>
|
||||
@@ -10,6 +10,7 @@
|
||||
<option value="redirect_profile" <?php selected('redirect_profile', $ultimatemember->query->get_meta_value('_um_after_login') ); ?>>Redirect to profile</option>
|
||||
<option value="redirect_url" <?php selected('redirect_url', $ultimatemember->query->get_meta_value('_um_after_login') ); ?>>Redirect to URL</option>
|
||||
<option value="refresh" <?php selected('refresh', $ultimatemember->query->get_meta_value('_um_after_login') ); ?>>Refresh active page</option>
|
||||
<option value="redirect_admin" <?php selected('redirect_admin', $ultimatemember->query->get_meta_value('_um_after_login') ); ?>>Redirect to WordPress Admin</option>
|
||||
</select>
|
||||
|
||||
</span>
|
||||
|
||||
+6
-6
@@ -57,7 +57,7 @@ class UM_Access {
|
||||
$args = $this->get_meta();
|
||||
extract($args);
|
||||
|
||||
$redirect = null;
|
||||
$redirect_to = null;
|
||||
|
||||
if ( !isset( $accessible ) ) return;
|
||||
|
||||
@@ -69,24 +69,24 @@ class UM_Access {
|
||||
case 1:
|
||||
|
||||
if ( is_user_logged_in() )
|
||||
$redirect = $access_redirect2;
|
||||
$redirect_to = $access_redirect2;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
if ( !is_user_logged_in() )
|
||||
$redirect = $access_redirect;
|
||||
$redirect_to = $access_redirect;
|
||||
|
||||
if ( isset( $access_roles ) && !empty( $access_roles ) )
|
||||
if ( !in_array( um_user('role'), unserialize( $access_roles ) ) )
|
||||
$redirect = $access_redirect;
|
||||
$redirect_to = $access_redirect;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( $redirect ) {
|
||||
wp_redirect( $redirect );
|
||||
if ( $redirect_to ) {
|
||||
wp_redirect( $redirect_to );
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,10 @@
|
||||
function um_user_login($args){
|
||||
global $ultimatemember;
|
||||
extract( $args );
|
||||
|
||||
if ( is_user_logged_in() ) {
|
||||
wp_logout();
|
||||
}
|
||||
|
||||
$user_id = $ultimatemember->login->auth_id;
|
||||
|
||||
@@ -92,9 +96,19 @@
|
||||
|
||||
$ultimatemember->user->auto_login( $user_id );
|
||||
|
||||
// Priority redirect
|
||||
if ( isset( $args['redirect_to'] ) ) {
|
||||
exit( wp_redirect( $args['redirect_to'] ) );
|
||||
}
|
||||
|
||||
// Role redirect
|
||||
$after = um_user('after_login');
|
||||
switch( $after ) {
|
||||
|
||||
case 'redirect_admin':
|
||||
exit( wp_redirect( admin_url() ) );
|
||||
break;
|
||||
|
||||
case 'redirect_profile':
|
||||
exit( wp_redirect( um_user_profile_url() ) );
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/***
|
||||
*** @add a force redirect to from $_get
|
||||
***/
|
||||
add_action('um_after_form_fields', 'um_browser_url_redirect_to');
|
||||
function um_browser_url_redirect_to($args) {
|
||||
|
||||
global $ultimatemember;
|
||||
|
||||
if ( isset( $_REQUEST['redirect_to'] ) && !empty( $_REQUEST['redirect_to'] ) ) {
|
||||
|
||||
echo '<input type="hidden" name="redirect_to" id="redirect_to" value="'.$_REQUEST['redirect_to'].'" />';
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $args['after_login'] ) && !empty( $args['after_login'] ) ) {
|
||||
|
||||
switch( $args['after_login'] ) {
|
||||
|
||||
case 'redirect_admin':
|
||||
$url = admin_url();
|
||||
break;
|
||||
|
||||
case 'redirect_profile':
|
||||
$url = um_user_profile_url();
|
||||
break;
|
||||
|
||||
case 'redirect_url':
|
||||
$url = $args['redirect_url'];
|
||||
break;
|
||||
|
||||
case 'refresh':
|
||||
$url = $ultimatemember->permalinks->get_current_url();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
echo '<input type="hidden" name="redirect_to" id="redirect_to" value="' . $url . '" />';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*** @add a notice to form
|
||||
***/
|
||||
add_action('um_before_form', 'um_add_update_notice', 500 );
|
||||
function um_add_update_notice($args){
|
||||
global $ultimatemember;
|
||||
extract($args);
|
||||
if ( isset( $_REQUEST['updated'] ) && !empty( $_REQUEST['updated'] ) ) {
|
||||
|
||||
switch( $_REQUEST['updated'] ) {
|
||||
|
||||
case 'password_changed':
|
||||
$msg = __('You have successfully changed your password.','ultimatemember');
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $msg ) ) {
|
||||
|
||||
echo '<p class="um-notice success">' . $msg . '</p>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
/***
|
||||
*** @add a notice to form
|
||||
***/
|
||||
add_action('um_before_form', 'um_add_update_notice', 500 );
|
||||
function um_add_update_notice($args){
|
||||
global $ultimatemember;
|
||||
extract($args);
|
||||
if ( isset( $_REQUEST['updated'] ) && !empty( $_REQUEST['updated'] ) ) {
|
||||
|
||||
switch( $_REQUEST['updated'] ) {
|
||||
|
||||
case 'password_changed':
|
||||
$msg = __('You have successfully changed your password.','ultimatemember');
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $msg ) ) {
|
||||
|
||||
echo '<p class="um-notice success">' . $msg . '</p>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+5
-4
@@ -18,15 +18,16 @@ class UM_Logout {
|
||||
if ( is_user_logged_in() ) {
|
||||
|
||||
if ( isset($_REQUEST['redirect_to']) && $_REQUEST['redirect_to'] !== '' ) {
|
||||
$redirect = $_REQUEST['redirect_to'];
|
||||
$redirect_to = $_REQUEST['redirect_to'];
|
||||
} else if ( um_user('after_logout') == 'redirect_home' ) {
|
||||
$redirect = home_url();
|
||||
$redirect_to = home_url();
|
||||
} else {
|
||||
$redirect = um_user('logout_redirect_url');
|
||||
$redirect_to = um_user('logout_redirect_url');
|
||||
}
|
||||
|
||||
wp_logout();
|
||||
exit( wp_redirect( $redirect ) );
|
||||
|
||||
exit( wp_redirect( $redirect_to ) );
|
||||
|
||||
} else {
|
||||
exit( wp_redirect( home_url() ) );
|
||||
|
||||
+2
-1
@@ -182,7 +182,7 @@ class UM_Setup {
|
||||
'default_homepage' => 1,
|
||||
'status' => 'approved',
|
||||
'auto_approve_act' => 'redirect_profile',
|
||||
'after_login' => 'redirect_profile',
|
||||
'after_login' => 'redirect_admin',
|
||||
'after_logout' => 'redirect_home',
|
||||
);
|
||||
|
||||
@@ -196,6 +196,7 @@ class UM_Setup {
|
||||
'can_delete_roles' => 0,
|
||||
'can_make_private_profile' => 0,
|
||||
'can_access_private_profile' => 0,
|
||||
'after_login' => 'redirect_profile',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ class UM_API {
|
||||
require_once um_path . 'core/um-actions-user.php';
|
||||
require_once um_path . 'core/um-actions-save-profile.php';
|
||||
require_once um_path . 'core/um-actions-modal.php';
|
||||
require_once um_path . 'core/um-actions-notices.php';
|
||||
require_once um_path . 'core/um-actions-misc.php';
|
||||
|
||||
require_once um_path . 'core/um-filters-login.php';
|
||||
require_once um_path . 'core/um-filters-register.php';
|
||||
|
||||
Reference in New Issue
Block a user