Wordpress redirects visitors from certain url to their profiles - wordpress

I am searching for a way to redirect visitors coming from a certain url to their profiles in wordpress
Example if you are coming from example.com/test.html and going to example.com you will be directed to http://www.example.com/author/user/
Is that possible to be done? Thanks for help

something like
if($_SERVER['HTTP_REFERER']){
if($_SERVER['HTTP_REFERER'] == "your test url" && is_user_logged_in()){
$targetUrl = get_edit_user_link();
wp_redirect( $targetUrl );
exit;
}
}
Should do the trick - but escape the referer since its a common attack vector for web apps.
EDIT
If i am reading you question correctly, you want logged in users, to go to their profile page whenever they go to the gomepage?
in that case, you can create a function similar to
add_action('wp_head','wpmy_redirect_logged_in_users_away_from_home');
function wpmy_redirect_logged_in_users_away_from_home() {
if( is_user_logged_in() && ( is_home() || is_front_page() ) ) {
$targetUrl = get_edit_user_link();
wp_redirect( $targetUrl );
exit;
}
}

Related

Want to make a wordpress accessible to view only thorugh redirection from a particular page and cannot be viewed through its own page url

I want to create a function on my wordpress site that a particular page 'x' can be viewed or acessible only through redirection from a particular page 'y' and connot be viewed through its own url (only redirecton should be the way to view that page 'x')
I have tried this but no result what is wrong with it please check:
is_page(776) {
$referer = wp_get_referer(); if ( 'https://xnd.vtgcindia.online/' !== $referer ) { // User arrived from another source so send them away! wp_redirect( 'http://xnd.vtgcindia.onlne/' ); exit; }
}
(Note: Page "X" represent page to be viewed and Page "Y" represent page through which user get redirection or can visit. I use this for easy explanation of the situation)
Hope you answer and help!
is_page(776) {
$referer = wp_get_referer(); if ( 'https://xnd.vtgcindia.online/' !== $referer ) { // User arrived from another source so send them away! wp_redirect( 'http://xnd.vtgcindia.onlne/' ); exit; }
}

Woocommerce guest checkout not redirecting to order-received page

I have created a flow using a function that when someone try to make an order without login he/she is redirected to a custom login-register pages where they choose to either login/register or continue as a guest - see function code below, now when someone makes an order he/she gets redirected to custom login-register page instead of order-received page. What's wrong here?
function ace_redirect_pre_checkout() {
if ( class_exists( 'woocommerce' ))
$redirect_page_id = 104549;
if (!is_user_logged_in() && is_page(17)) {
wp_redirect(get_permalink($redirect_page_id));
} elseif (is_user_logged_in() && is_page($redirect_page_id)) {
wp_redirect(get_permalink(wc_get_page_id('checkout')));
}
}
add_action('template_redirect', 'ace_redirect_pre_checkout');

Remove wp-login completely

First of, I'm new to using Wordpress so please excuse me if I ask something really stupid.
I want to completely remove wp-login and the register function, I don't want users to be able to register and don't want to show the option on my blog.
I did some research on this and all i get are results that explain how to hide the wp-login or change the url, which is not what i want.
Is there a function within wordpress to completly remove this from my blog? Or do i have to remove these pages from my source code?
Any help would be appreciated.
Thank you.
Untick "Anyone Can Register" in "Settings" > "General" - I think that will take care of it. If you insist on taking the form down completely then this function would completely remove the login form, and yet still provide emergency access:
add_filter( 'wp_login_errors', 'my_login_lock_down', 90, 2 );
function my_login_lock_down( $errors, $redirect_to ){
// Get to the login form using: http://example.com/wp-login.php?secretform=secretcode
$secret_key = "secretform";
$secret_password = "secretcode";
if ( !isset( $_GET[ $secret_key ] ) || $_GET[ $secret_key ] != $secret_password ) {
login_header(__('Log In'), '', $errors);
echo "</div>";
do_action( 'login_footer' );
echo "</body></html>";
exit();
}
return $errors;
}

Redirect wordpress user to another page based on assigned role

Does anyone know a way (or plugin) that would allow me to automatically redirect users to another page, based on their assigned user role, if they try accessing the main /wp-admin page?
The tricky part is (I guess), is that I still need them to be able to access sub-admin pages (ie. mysite.com/wp-admin/edit.php) -- it would only redirect them if they tried going to the main/dashboard page, mysite.com/wp-admin
I've recently had the problem where I needed to redirect multiple pages. The following code will check the roles you want to redirect ($valid-roles) and if not valid redirect to a given URL... in this case its /access-denied/.
Note: The page ID's in the array list of pages to re-direct.
add_action( 'template_redirect', 'role_based_redirect' );
function role_based_redirect() {
if( is_page( array( 1488, 2413, 2379, 2265, 2396, 2370, 2366, 4600 ) ) ) { //check the list of "corporate" pages
$user = wp_get_current_user();
$valid_roles = [ 'administrator', 'corporate', 'editor' ];
$the_roles = array_intersect( $valid_roles, $user->roles );
// The current user does not have any of the 'valid' roles.
if ( empty( $the_roles ) ) {
wp_redirect( home_url( '/access-denied/' ) );
exit;
}
}
}
There are many ways you can set the URL redirect to a different link by role on your WordPress page, you may use a plugin or you can also build a plugin to customize it specifically on your own way follow this link for that instruction but I believe as a second and better option this plugin right here might be easy for you might help you as well.
Good luck

wordpress redirection loop in woocommerce products

Hi I am having a problem with my wordpress site after I changed my theme and redesigned the website and also deleting and reinstalling woocommerce ( I did not update because updating coused wp-admin to become blank-white and reinstalling made it all fine exept this following problem.)
all links to products in the shop page are to "/product(in hebrew)/product-name/"
and when i access the products in wp-admin and hit the "view product" page it goes to "/products(english)/product-name/"
the problem is when I click on a product from the shop front-end I get a redirection loop error. i need to fix this ASAP.
no sure how to fix this problem.
website: www.tikanti.co.il/חנות/
i found out a way to fix it...
just went to
setting > parmalinks > changed one of the options for woocommerce and it refreshed the whole thing to whatever I chose.
no more loop thank god!!!!!
to solve this you need to log into your cpanel and change the .htaccess permissions to 777 or 755
then go to wp-admin page then setting > parmalinks >
then change Common Settings to post name
this will solve the problem
You can set redirect according to user role.
//Redirect users to custom URL based on their role after login
function wp_woo_custom_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
$role = $user->roles[0];
$dashboard = admin_url();
$myaccount = get_permalink( wc_get_page_id( 'my-account' ) );
if( $role == 'administrator' ) {
//Redirect administrators to the dashboard
$admin_redirect = get_option('admin_redirect');
$redirect = $admin_redirect;
} elseif ( $role == 'shop-manager' ) {
//Redirect shop managers to the dashboard
$shop_manager_redirect = get_option('shop_manager_redirect');
$redirect = $shop_manager_redirect;
} elseif ( $role == 'customer' || $role == 'subscriber' ) {
//Redirect customers and subscribers to the "My Account" page
$customer_redirect = get_option('customer_redirect');
$redirect = $customer_redirect;
} else {
//Redirect any other role to the previous visited page or, if not available, to the home
$redirect = wp_get_referer() ? wp_get_referer() : home_url();
}
return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'wp_woo_custom_redirect', 10, 2 );
Given above the code for that redirection and I have developed a WooCommerce Login or Register Redirect plugin for entry level user or nor technical or no-programmer.

Resources