Skip to content
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

Tweak - Redirect url as slug in login and my account shortcode #599

Merged
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
16 changes: 16 additions & 0 deletions includes/class-ur-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,20 @@ private static function render_form( $form_id ) {
)
);
}
/**
* Check the redirection url is valid url or slug.
*
* @param string $redirect_url redirection url.
*/
public static function check_is_valid_redirect_url( $redirect_url ) {
if ( filter_var( $redirect_url, FILTER_VALIDATE_URL ) === false ) {
$all_page_slug = ur_get_all_page_slugs();
if ( in_array( $redirect_url, $all_page_slug, true ) ) {
$redirect_url = site_url( $redirect_url );
} else {
$redirect_url = home_url();
}
}
return $redirect_url;
}
}
21 changes: 21 additions & 0 deletions includes/functions-ur-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -3925,6 +3925,27 @@ function user_registration_conditional_user_meta_filter( $valid_form_data, $user
add_filter( 'user_registration_before_user_meta_update', 'user_registration_conditional_user_meta_filter', 10, 3 );
add_filter( 'user_registration_before_save_profile_details', 'user_registration_conditional_user_meta_filter', 10, 3 );

if ( ! function_exists( 'ur_get_all_page_slugs' ) ) {
/**
* Get all the page slugs.
*/
function ur_get_all_page_slugs() {
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
);

$pages = get_pages( $args );

$slugs = array();

foreach ( $pages as $page ) {
$slugs[] = $page->post_name;
}

return $slugs;
}


if ( ! function_exists( 'ur_add_links_to_top_nav' ) ) {
/**
Expand Down
1 change: 1 addition & 0 deletions includes/shortcodes/class-ur-shortcode-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static function output( $atts ) {
global $wp, $post;

$redirect_url = isset( $atts['redirect_url'] ) ? trim( $atts['redirect_url'] ) : '';
$redirect_url = UR_Shortcodes::check_is_valid_redirect_url( $redirect_url );

if ( ! is_user_logged_in() ) {
// After password reset, add confirmation message.
Expand Down
4 changes: 3 additions & 1 deletion includes/shortcodes/class-ur-shortcode-my-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public static function output( $atts ) {

if ( ! is_user_logged_in() ) {

$redirect_url = isset( $atts['redirect_url'] ) ? esc_url( trim( $atts['redirect_url'] ) ) : '';
$redirect_url = isset( $atts['redirect_url'] ) ? trim( $atts['redirect_url'] ) : '';
$redirect_url = UR_Shortcodes::check_is_valid_redirect_url( $redirect_url );
$redirect_url = esc_url( $redirect_url );
$redirect_url = ( isset( $_GET['redirect_to'] ) && empty( $redirect_url ) ) ? esc_url( wp_unslash( $_GET['redirect_to'] ) ) : $redirect_url; // @codingStandardsIgnoreLine
$form_id = isset( $atts['form_id'] ) ? absint( $atts['form_id'] ) : 0;
$message = apply_filters( 'user_registration_my_account_message', '' );
Expand Down
Loading