Redirecting Wordpress's Login/Register page to a custom login/registration page
For this you need to redirect login/registration page to your custom pages.
So, Write this code in your functions.php
file Under your activated theme folder. Pass your custom page path as a Argument.
add_action('init','possibly_redirect');
function possibly_redirect(){
global $pagenow;
if( 'wp-login.php' == $pagenow ) {
wp_redirect('http://google.com/');
exit();
}
}
Redirecting after login and registration ONLY IF coming from a product page
why don't you just add a query arg to the link on product pages?
edit:
okay, so without going into too much detail as I'm tired and somewhat inebriated and can't be trusted around semicolons right now:
I would use https://developer.wordpress.org/reference/functions/wp_login_url/ to set up the hrefs for my login links. You'll notice that the function comes with:
a: an optional argument for passing the url that the user should be referred to after login
and b: a filter hook called 'login_url' that you can use to hijack the process and apply your own logic in.
also wordpress comes with a function conveniently called 'add_query_arg' which does exactly what it says on the tin. (https://developer.wordpress.org/reference/functions/add_query_arg/)
so if i were to set up some php that would return that string on a product page I'd do something like this:
$refer_to_url = get_permalink(get_the_ID()); //get current post/page permalink
$refer_to_url = add_query_arg('is_product_page', true, $refer_to_url); //add arguments to that url.
$this_login_url = wp_login_url($refer_to_url);
then I'd probably try and set up a filter that would change the referring url to e.g. the user's account page if is_product_page is not true.
https://developer.wordpress.org/reference/functions/add_filter/
you may also have to register the queryvar using
add_filter( 'query_vars', function ( $qvars ) {
$qvars[] = 'is_product_page';
return $qvars;
});
otherwise wordpress might refuse to process the query var.
hope that helps.
How to pass redirect_to from login to registration page in Wordpress
If you're looking to maintain the redirect_to url from the login to the registration and back to the login page, so the user can just enter their password once received by email, and still return to the original referrer this is the full solution.
function custom_register_url( $registration_url ) {
$redirect_to = $_GET["redirect_to"];
$eab_msg = $_GET["eab"];
if( $redirect_to != "" && $eab_msg != "" ) {
// change query name values to prevent default behaviour (redirect_to to uct_redirect)
$registration_url = sprintf( '<a href="%s&%s&%s">%s</a>', esc_url( wp_registration_url() ), "uct_redirect=" . urlencode($redirect_to), "uct_eab=" . urlencode($eab_msg), __( 'Register' ) );
}
return $registration_url;
}
add_filter( 'register', 'custom_register_url' );
function custom_registration_redirect($registration_redirect) {
$redirect_to = $_GET["uct_redirect"];
$eab_msg = $_GET["uct_eab"];
if( $redirect_to != "" && $eab_msg != "" ) {
// change query names back to original values (uct_redirect to redirect_to)
$registration_redirect = wp_login_url( $redirect_to ) . '&eab=' . $eab_msg;
}
return $registration_redirect;
}
add_filter( 'registration_redirect', 'custom_registration_redirect' );
Just drop it in functions.php. Hope this helps someone Cheers!
Link to registration page in Wordpress
The following will return the registration url:
<?php
echo site_url('/wp-login.php?action=register');
?>
UPDATE:
To get the registration url with a redirect to the current page use:
<?php
echo site_url('/wp-login.php?action=register&redirect_to=' . get_permalink());
?>
Wordpress - Separate Log in and Register forms in the same page
Yes, and pretty much as you've described here.
Set the 'name' attribute on each of your submit buttons - e.g.
<input type="submit" name="login" value="Login" class="mybtnclass" />
Then when parsing, check if that value is set
if(isset($_POST['login'])) :
// Do login
elseif(isset($_POST['register'])) :
// Do registration
elseif(isset($_POST['reset'])) :
// Do password reset
endif;
EDIT:
An alternative is to give all the buttons the same 'name' and then test the 'value' attribute to determine which was pressed e.g.
<input type="submit" name="submit" value="Login" class="mybtnclass" />
<input type="submit" name="submit" value="Register" class="mybtnclass" />
<input type="submit" name="submit" value="Reset Password" class="mybtnclass" />
<?php
if('Login'===$_POST['submit']) :
// Do login
elseif('Register'===$_POST['submit']) :
// Do register
elseif('Reset Password'===$_POST['submit']) :
// Do password reset
endif;
?>
Related Topics
How to Create a New Joomla User Account from Within a Script
Magento - Load Only Configurable Products
Reaching 100% Code Coverage with PHPunit
How to Maintain Session in Curl in PHP
PHP - Time Remaining Until Specific Time from Current Time of Page Load
Running Imagemagick on Xampp 1.8.3 with Windows 7
Php-Sort Array Based on Another Array
How to? Form Post to Multiple Locations
PHP Get Content of Http 400 Response
How to Send Notification to Android from PHP
Properly Calling the Database from Model in an MVC Application
Try Catch Cannot Work with Require_Once in PHP
How to Use C++ Binaries from PHP