Wordpress rewrite with php - php

Is possible change this url
www.12345.com/?s=&cp_state=city
to this?
www.12345.com/city
Already try with htaccess but in wordpress it doesen't work
Hi have this code. Is possible change it to have a url like this www.12345.com/city?
add_action('template_redirect', 'search_url_rewrite_rule');
function search_url_rewrite_rule() {
global $wp_rewrite;
if ( is_search() && isset( $_GET['s'] ) ) {
$s = str_replace( array( ' ', '%20' ), '+', get_query_var( 's' ) );
wp_redirect( home_url( $wp_rewrite->search_base . '/' . remove_accents ( $s ) ) );
exit();
}
}
add_action('init','change_search_permalinks');
function change_search_permalinks( ) {
global $wp_rewrite;
$wp_rewrite->search_base = 'search';
}
Thank you in advance

In php level it is not good idea
You can use url shortlink in admin area of wordpress.

Related

login authentication control on button for PHP

Need to set a login control on a button for my wp website. Button's code appears to be like this:
$enable_redirect = get_field('redirect_to_offer') ? get_field('redirect_to_offer') : array('');
echo'' . fw_ssd_get_option('show-code-text') . '';
}
My goal is to check if the user who clicks on that button is logged in or not with:
if ( function_exists('um_profile_id') && !um_profile_id() && get_field('registered_members_only') ) {
wp_redirect(home_url('login/'));
exit;
}
But I couldn't figure out where should I put the controller code. F1 please.
Since your button URL is external, changing the button URL from the beginning seems to be a better option (as discussed on the comments):
$enable_redirect = get_field( 'redirect_to_offer' ) ? get_field('redirect_to_offer') : array( '' );
if ( function_exists( 'um_profile_id' ) && ! um_profile_id() && get_field( 'registered_members_only' ) ) {
$button_url = home_url( 'login/' );
} else {
$button_url = get_field( 'url' );
}
echo sprintf( '%4$s'
esc_url( $button_url ),
esc_attr( get_field( 'coupon_code' ) ),
esc_attr( $enable_redirect[0] ),
fw_ssd_get_option( 'show-code-text' )
);
The login status defines the final button URL.
Note: I used placeholder replacement with sprintf() in other to make it easier to read.

Cannot find where a redirect is specified

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.

Changing WordPress search URL

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?

Fixing/hardening add_query_arg() usage in WP function

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?

dont understand where this action takes in form action wordpress

i am new to wordpress and trying to modify theme. but i am not able to track form action.
<form action="<?php echo appthemes_get_registration_url( 'login_post' ); ?>" method="post" class="login-form register-form custom" name="registerform" id="login-form">
where these action takes ? how data is stored ?
this is the function.php where i get following function code .
function appthemes_get_registration_url( $context = 'display' ) {
if ( current_theme_supports( 'app-login' ) && ( $page_id = APP_Registration::get_id() ) ) {
$url = get_permalink( $page_id );
} else {
$url = site_url( 'wp-login.php?action=register' );
}
if ( ! empty( $_REQUEST['redirect_to'] ) ) {
$url = add_query_arg( 'redirect_to', urlencode( $_REQUEST['redirect_to'] ), $url );
}
return esc_url( $url, null, $context );
}
can anyone help me with this issue?
i am stuck here.
According to the function being used
$url = get_permalink( $page_id );
The above code will get the link of the current custom login page which the theme uses.
Or else it will go to the default WordPress register page
$url = site_url( 'wp-login.php?action=register' );
There is a redirect field in the theme after the registration is over, which makes the user to go to the required page. If it is empty, then it can be skipped or else it is returned to the redirect URL specified.
if ( ! empty( $_REQUEST['redirect_to'] ) ) {
$url = add_query_arg( 'redirect_to', urlencode( $_REQUEST['redirect_to'] ), $url );
}
The data of your registration is stored in a table called users which you can access through PHPmyAdmin

Categories