Redirect to previous page after login?
This topic contains 4 replies, has 2 voices, and was last updated by Guust 6 years, 5 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
November 6, 2018 at 10:35 pm #452796
Hello!
I am hoping to set up a way to redirect a logged-out user back to the listing they came from after they log in, similar to how the claim listing button and add listing buttons work when a user is not logged in. This really only seems to be an issue in the “Leave a Review” link to the login page.
In the geodirectory translation file, I found this snippet: “You must be logged in to post a comment.” Should the “%s” be changed to something else to allow for the redirect?
Any help is appreciated! Thank you!
November 6, 2018 at 10:43 pm #452797If you use our UsersWP plugin, you will find a setting that will do exactly that: https://userswp.io/
https://userswp.io/docs/userswp-main-settings/#login
Thanks
November 7, 2018 at 9:08 pm #452940Thanks for the reply, Guust! What I am looking for is actually a redirect back to the previous listing after logging in, instead of a specific page.
Here is some code I’m using for blog post comments, that is giving me the functionality I’m looking for.
add_filter( 'comment_form_defaults', function( $fields ) { $fields['must_log_in'] = sprintf( __( '<p class="must-log-in">You must <a href="%s">login</a> to post a comment.</p>' ), geodir_login_url(array('redirect_to' => urlencode_deep(get_permalink()))) ); return $fields; });
Is there a way to do this with reviews? I found this inside of reviews.php within the plugin files; can this be modified similarly?
$args = apply_filters('geodir_review_form_args', array( 'title_reply' => __('Leave a Review', 'geodirectory'), 'label_submit' => __('Post Review', 'geodirectory'), 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . __('Review text', 'geodirectory') . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required></textarea></p>', 'must_log_in' => '<p class="must-log-in">' . sprintf(__('You must be <a href="%s">logged in</a> to post a comment.', 'geodirectory'), geodir_login_url()) . '</p>' )); comment_form($args);
Thanks again for the help!
November 7, 2018 at 9:12 pm #452941Thanks for the help, Guust! What I am actually hoping to accomplish is a redirect back to the listing, rather than to a specific page. Here is some code I’m using for the blog post comments, which gives me the functionality I’m looking for:
add_filter( 'comment_form_defaults', function( $fields ) { $fields['must_log_in'] = sprintf( __( '<p class="must-log-in">You must <a href="%s">login</a> to post a comment.</p>' ), geodir_login_url(array('redirect_to' => urlencode_deep(get_permalink()))) ); return $fields; });
Would you know if there is a way to do this similarly with reviews? I found the below code in the reviews.php, which seems to drive a url redirect as well, but behaves a bit differently than the code above. Would you know if there is a specific filter/hook I can use to modify it?
$args = apply_filters('geodir_review_form_args', array( 'title_reply' => __('Leave a Review', 'geodirectory'), 'label_submit' => __('Post Review', 'geodirectory'), 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . __('Review text', 'geodirectory') . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required></textarea></p>', 'must_log_in' => '<p class="must-log-in">' . sprintf(__('You must be <a href="%s">logged in</a> to post a comment.', 'geodirectory'), geodir_login_url()) . '</p>' )); comment_form($args);
Thanks again for the help!
November 7, 2018 at 10:15 pm #452943That is what UsersWP does, try it:
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket