If we set the language selection URL from the Polylang plugin URL modification at that time PayPal checkout button not working on the cart and checkout page on the website.
Please once check and let us know if you have any solution to this issue.
Thank you.!
add_filter('woocommerce_api_request_url', 'wt_woocommerce_api_request_url', 10, 3);
function wt_woocommerce_api_request_url($api_request_url, $request, $ssl) {
if ( is_null( $ssl ) ) {
$scheme = parse_url( home_url(), PHP_URL_SCHEME );
} elseif ( $ssl ) {
$scheme = 'https';
} else {
$scheme = 'http';
}
$lang = 'en';
if ( function_exists('pll_current_language') ) {
$lang = pll_current_language();
}
if ( strstr( get_option( 'permalink_structure' ), '/index.php/' ) ) {
$api_request_url = trailingslashit( home_url( $lang .'/index.php/wc-api/' . $request, $scheme ) );
} elseif ( get_option( 'permalink_structure' ) ) {
$api_request_url = trailingslashit( home_url( $lang .'/wc-api/' . $request, $scheme ) );
} else {
$api_request_url = add_query_arg( 'wc-api', $request, trailingslashit( home_url( '', $scheme ) ) );
}
return esc_url_raw( $api_request_url );
}
Related
I am working on my wordpress website and i am little stuck into one situation.... i want to redirect the users to a specific page after successful login but i dont know how to use the wordpress redirect hook
here below is my wordpress hook that i put in function file... code that i found online:-
/**
* WordPress function for redirecting users on login based on user role*/
function wpdocs_my_login_redirect( $url, $request, $user ) {
$urllinkin =
if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if ( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} elseif() {
$url = home_url( '/members-only/' );
}
}
return $url;
}
add_filter( 'login_redirect', 'wpdocs_my_login_redirect', 10, 3 );
currently i am using this code in anchor tag to redirect to sign in page and after sign in to specific page, the sign in is going fine but redirect is not working
<?php echo wp_login_url(get_permalink()); ?>"> this code give the url :- http://192.168.1.50/jobifylocal/my-profile/?redirect_to=http://192.168.1.50/jobifylocal/job/clinical-psychologist/
hey i edited the code as per my need.. you commented, but still it dosent redirect
function wpdocs_my_login_redirect( $url, $request, $user ) {
if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if ( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} elseif ( $user->has_cap( 'candidate' ) ) {
$variable_two = $_GET['redirect_to'];
if(!empty($variable_two)){
$url = $variable_two;
}
// $url = home_url( '/members-only/' );
}
}
return wp_redirect($url);
}
add_filter( 'login_redirect', 'wpdocs_my_login_redirect', 10, 3 );
$urllinkin = remove this from your code.
Further more here is the code for login redirect (Check official docs),
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return home_url();
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
For redirection, you can use wp_redirect default function too.
Here is your updated code,
function wpdocs_my_login_redirect( $url, $request, $user ) {
if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if ( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} else {
$url = home_url( '/members-only/' );
}
}
return $url;
}
add_filter( 'login_redirect', 'wpdocs_my_login_redirect', 10, 3 );
I've recently become the maintainer of a Wordpress site (I'm completely new to wordpress) and I'm having some difficulty determining where a redirect is specified.
I've checked the .htaccess file, and there's nothing specified in there. As far as I can tell, the rewrite rules aren't the cause.
I've tried deleting the page being redirected from and re-creating it, and the redirect still occurs.
My question is: where can you specify a redirect? I've run out of ideas of where to look.
one of my client want to custom url like
https://www.qsleap.com/gmat/resources as you know in wordpress evry request is catch by index.php . request filter catches the request and
call the page .
Read this code it may give you any idea.
function permalinks_customizer_request_before($query ){
$uri=$_SERVER['REQUEST_URI'];
$match= preg_match('/(gmat|gre|sat|lsat|cat)(\/resources\/tags\/)
(.*)\/(articles|videos|concept-notes|qna)/', $uri,$matches);
//$match=
preg_match('/(gmat|gre|sat|lsat|cat)/\resources/\tags/stanford-
gsb/\articles|videos|concept-notes)/?$', $uri,$matches);
if($match){
$url = parse_url( get_bloginfo( 'url' ) );
$url = isset( $url['path']) ? $url['path'] : '';
$request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
$request = ( ( $pos = strpos( $request, '?' ) ) ? substr( $request, 0, $pos ) : $request );
if ( ! $request )
return $query;
$original_url="?page_name=tags&exam=".$matches[1]."&post_tag=".$matches[3]."&post_type=".$matches[4];
if ( $original_url !== null ) {
$original_url = str_replace('//', '/', $original_url);
if ( ( $pos = strpos( $_SERVER['REQUEST_URI'], '?' ) ) !== false ) {
$queryVars = substr( $_SERVER['REQUEST_URI'], $pos + 1 );
$original_url .= ( strpos( $original_url, '?' ) === false ? '?' : '&') . $queryVars;
}
$oldRequestUri = $_SERVER['REQUEST_URI'];
$oldQueryString = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' );
$_SERVER['QUERY_STRING'] = ( ( $pos = strpos( $original_url, '?' ) ) !== false ? substr( $original_url, $pos + 1 ) : '' );
parse_str( $_SERVER['QUERY_STRING'], $queryArray );
$oldValues = array();
global $wp;
$wp->parse_request();
$query = $wp->query_vars;
if ( is_array( $queryArray ) ) {
foreach ( $queryArray as $key => $value ) {
$oldValues[$key] = $_REQUEST[$key];
$_REQUEST[$key] = $_GET[$key] = $value;
$query[$key]=$value;
}
}
$_SERVER['REQUEST_URI'] ='';
$_SERVER['QUERY_STRING']='';
}
}
return $query;
}
add_filter( 'request','permalinks_customizer_request_before',0);
function wp_url_rewrite_templates() {
if (get_query_var( 'page_name' ) && get_query_var( 'page_name'
)=='tags') {
add_filter( 'template_include', function() {
$template= dirname( __FILE__ ) . '/page-tags.php';
return $template;
});
}
}
add_action( 'template_redirect', 'wp_url_rewrite_templates' ,4 );
I think the easiest way for you to remove the redirects will be with this plugin.
https://redirection.me/
After you install it and activate it. From the Wordpress Admin
Tools > Redirection
You'll see a list of redirects, and add/remove any.
I've posted the code below. Whenever I logged in, the $username is not getting executing thus leaving blank.
function my_login_redirect( $redirect_to, $request, $user ) {
global $current_user;
$current_member = wp_get_current_user();
$username = $current_member->user_login;
$url = home_url( "/connections/$username/profile/edit/group/1/" );
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return esc_url( $url );
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
The global $currentuser is unavailable during this filter request as stated here
But the $user is available during the request from function parameters,
so simply these should work
function my_login_redirect( $redirect_to, $request, $user ) {
$username = $user->user_login;
$url = home_url( "/connections/$username/profile/edit/group/1/" );
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
if ( in_array( 'administrator', $user->roles ) ) {
return $redirect_to;
} else {
return esc_url( $url );
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
this is the code which I'm trying
function search_url_rewrite() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
global $opt; if($opt['rewrite_slug_search']){ $search_url = $opt['rewrite_slug_search'];
} else { $search_url = 'search'; }
wp_redirect( home_url( $search_url ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'search_url_rewrite' );
the $search_url is option from my theme settings panel but there is a problem with the slash when I type test in search box I get searchtest instead of search/test do you have any idea how to get a slash between?
According to this recent post by the WordPress team, we need to check on our theme files to see if it's using the add_query_arg() and remove_query_arg() functions. Having done a full search of our current theme, I can see a reference to add_query_arg() in this snippet in our pagination.php file:
Here is PHP Code as follows :
if ( !function_exists( 'get_multipage_link' ) ) :
function get_multipage_link( $page = 1 ) {
global $post, $wp_rewrite;
if ( 1 == $page ) {
$url = get_permalink();
} else {
if ( '' == get_option('permalink_structure') || in_array( $post->post_status, array( 'draft', 'pending') ) )
add_query_arg( 'page', $page, get_permalink() );
elseif ( 'page' == get_option( 'show_on_front' ) && get_option('page_on_front') == $post->ID )
$url = trailingslashit( get_permalink() ) . user_trailingslashit( $wp_rewrite->pagination_base . "/$page", 'single_paged' );
else
$url = trailingslashit( get_permalink() ) . user_trailingslashit( $page, 'single_paged' );
}
return $url;
}
endif;
Unfortunately, I'm a bit out of my depth here. Is that reference OK as it is referencing get_permalink() and not a URL? That's way I don't need to use the esc_url() that the blog posting recommends?