I would like to replace the first character of $args in rewrite
I have the following:
return 302 https://domain/accounts/registration?_uid=1928&_tag=$request_uri&$args;
if $args are empty I just get a link that ends with a & which is not a big problem but if I have some $args I get something&?arg1 which is wrong since &? is considered as a continuation of the previous parameter.
How can I remove the first letter ( ? ) from $args ?
$request_uri already includes the optional ? and the query string. So your extra ? is coming from $request_uri and not from $args.
You could try using $uri&$args instead of $request_uri which will replace the embedded ? with a &.
For example:
return 302 https://domain/accounts/registration?_uid=1928&_tag=$uri&$args;
However, any percent-encoded characters in $request_uri are fully decoded by the time that $uri is constructed - which may or may not impact your application.
See this document for more.
Related
I am using a function.php code to convert all characters to uppercase when posting the "input" data for the Wordpress gravity forms plugin.
add_action('gform_pre_submission_1', 'capitalize_fields_1');
function capitalize_fields_1($form){
// add all the field IDs you want to capitalize, to this array
$fields_to_cap = array('input_1');
foreach ($fields_to_cap as $each) {
// for each field, convert the submitted value to uppercase and assign back to the POST variable
// the rgpost function strips slashes
$_POST[$each] = strtoupper(rgpost($each));
}
// return the form, even though we did not modify it
return $form;
}
However, I am using Turkish language and there is a character that is outside of UTF-8. The lowercase letter "i" becomes the letter "I" when converting. These two characters mean different things from each other. I want to convert the lowercase letter "i" into letter "I".
I found a php code for this process, but I could not adapt it to the function.php file.
function mb_strtoupper_tr($metin){
$metin=str_replace('i', 'İ', $metin);
Can anyone help me how to adapt this or implement a more efficient method?
add_action('gform_pre_submission_1', 'capitalize_fields_1');
function capitalize_fields_1($form){
// add all the field IDs you want to capitalize, to this array
$fields_to_cap = array('input_1');
foreach ($fields_to_cap as $each) {
// for each field, convert the submitted value to uppercase and assign back to the POST variable
// the rgpost function strips slashes
$_POST[$each] = strtoupper(str_replace('i', 'İ', rgpost($each)));
}
// return the form, even though we did not modify it
return $form;
}
I am try to use explode() on a string fetched from a database but it didn't work. I have tried explode('-',$string) but it's still not working.
Here is my string which I want to explode:
Expression of Interest – Join our Paint Team – North
If you look closely the hyphen from the string is not the same as the hyphen you use as your argument for the explode.
The hyphen in the string is the following – while the hyphen you pass as the argument for explode() is -. As you can see they don't match (the one in the string is longer than the one you try to compare it with). Because the characters don't match, the explode function is returning the whole string.
<?php
$string = "Expression of Interest – Join our Paint Team – North";
$strings = explode('–', $string);
var_dump($strings);
I have copied the hyphen from the text and used that as an argument for explode() and it works fine.
Might be $string is not string, you can use strval( $string ) to convert it to string i.e. explode('–', strval ( $string ) );
$eString = explode('–', strval ( $string ) );
// vardump($eString) - Now it is an array.
// echo $eString[0];
I have fix the issue by trying this
$post_job_title = htmlentities(get_the_title($posts));
$post_job_title = explode (" – ", $post_job_title);
Wordpress Redirects
My client has a WP website with a very bad permalinks structure and few hundreds "product" pages that they created as simple posts with bunch of HTML.
For example:
http://www.website.com/article/sony-tv-42-inch
http://www.website.com/article/iphone-5-2-black
http://www.website.com/article/samsung-dvd-player-12455
I am creating a new site from scratch and planning to use custom post types for Products section and organize URLS like:
http://www.website.com/product/sony/tv-42-inch
http://www.website.com/product/apple/iphone-5-black
http://www.website.com/product/samsung/dvd-player-12455
Since he doesnt want to lose any traffic or SEO ratings, i was wondering what would be the simplest solution for htaccess redirect for few hundred posts?
If he only had dozen of them, i could do it manually, but few hundreds...
Also, bare in mind that this is clean WP install with a theme built from scratch (i am working locally and most likely will be importing products via CSV file) so i cant just change the permalinks structure on production website.
Any help would be appreciated
It'd be fairly easy for you to re-write from
http://www.website.com/product/sony-tv-42-inch
to
http://www.website.com/product/sony-tv-42-inch
but that extra / is going to present a problem.
As mentioned by some others you certainly want a 301 for SEO purposes, so here is what I would do.
Step 1 - Get current URLS:
Get a list of all current post permalinks. This SQL query for MySQL by David George should do the trick.
SELECT wpp.post_title,
wpp.guid,
wpp.post_date,
CONCAT
(
wpo_su.option_value,
REPLACE
(
REPLACE
(
REPLACE
(
REPLACE
(
wpo.option_value,
'%year%',
date_format(wpp.post_date,'%Y')
),
'%monthnum%',
date_format(wpp.post_date, '%m')
),
'%day%',
date_format(wpp.post_date, '%d')
),
'%postname%',
wpp.post_name
)
) AS permalink
FROM wp_posts wpp
JOIN wp_options wpo
ON wpo.option_name = 'permalink_structure'
AND wpo.blog_id = 0
JOIN wp_options wpo_su
ON wpo_su.option_name = 'siteurl'
AND wpo_su.blog_id = wpo.blog_id
WHERE wpp.post_type = 'post'
AND wpp.post_status = 'publish'
ORDER BY wpp.post_date DESC
Step 2 - Save it for later:
Now that you have that list dump it into an Excel column for later.
Step 3 - Format it for PHP:
Take all the URLs and dump them into Notepad++ or equivalent. On windows hit cntrl+H to bring up the find/replace function. Make sure to select 'Search Mode' -> 'Extended'
For "Find What" you should put in \r\n and for 'Replace With' you should put in , and hit 'Replace All'.
You should now have a list of all your URLs separated only by a comma.
Step 4 - Create a PHP File:
Create a new PHP file and set:
<?php
$urlString = "http://www.urlsample1.com/article/sony-thing-and-stuff, http://www.urlsample1.com/article/warner-brothers-stuff";
//this will replace the word article with the word product
$newstring = str_replace("article", "product", $urlString);
//turns string into array
$myArray = explode(',', $newstring);
//loops through array to find first case of - and turn it to a /
for ($i = 0; $i < count($myArray); ++$i) {
$haystack = $myArray[$i];
$needle = "-";
$replace = "/";
$pos = strpos($haystack, $needle);
if ($pos !== false) {
$finalstring = substr_replace($haystack, $replace, $pos, strlen($needle));
}
//removes common url elements
$newShort = str_replace("http://www.urlsample1.com", "", $finalstring);
$oldShort = str_replace("http://www.urlsample1.com/product", "/article", $myArray[$i]);
//prints out the old and new url in .htaccess format
print("Redirect 301 " . $oldShort . " " . $newShort . "</br>");
};
?>
Step 5 - .Htaccess
Your output from above should look like:
Redirect 301 /product/sony-thing-and-stuff /product/sony/thing-and-stuff
Redirect 301 /product/warner-brothers-stuff /product/warner/brothers-stuff
and can be put into the .htaccess file.
Note: This method may become slow with Apache and isn't preferable but it is the quickest way I can think of to get your client up and running on the new situation.
For SEO, i suggest you use 301 - redirect in your .htaccess
You can use regexp for redirect.
Example:
RewriteEngine on
RewriteRule ^/users/(.*)$ http://www.example.com/profiles/$1 [R=301,L]
I have a buddypress site and I have edited the activity stream to include the activities I want to see however it's more logical to filter out the unwanted so future plugins don't have to be manually included I have tried != but does not work.
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ).'&action=bbp_reply_create,last_activity,gmw_location,activity_liked,rtmedia_update,new_avatar,updated_profile,joined_group,new_blog_post,bbp_topic_create,created_group' ) ) : ?>
And here is what I tried.
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ).'&action!=friendship_created,new_member' ) ) : ?>
But the attempt simply left the whole stream blank.
I've never used Buddypress, but from what I see you cannot simply use the != operator. You are placing the != in a string that is the input for a function named bp_ajax_querystring(). From the function's name, and the rest of the input, it looks like a set of GET parameters.
GET parameters only allow the setting of attributes (so != has no meaning). Instead, place the ! in front of the expression being evaluated by the if statement:
if ( !bp_has_activities( bp_ajax_querystring( 'activity' ).'&action=bbp_reply_create,last_activity,gmw_location,activity_liked,rtmedia_update,new_avatar,updated_profile,joined_group,new_blog_post,bbp_topic_create,created_group' )
I now have a full path for a file as a string like:
"/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/TRN_282C_HYD_MOD_1_Drive_Shaft_Rev000.xml"
However, now I need to take out only the folder path, so it will be the above string without the last back slash content like:
"/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/"
But it seems that the substring() function in xQuery only has substring(string,start,len) or substring(string,start), I am trying to figure out a way to specify the last occurence of the backslash, but no luck.
Could experts help? Thanks!
Try out the tokenize() function (for splitting a string into its component parts) and then re-assembling it, using everything but the last part.
let $full-path := "/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/TRN_282C_HYD_MOD_1_Drive_Shaft_Rev000.xml",
$segments := tokenize($full-path,"/")[position() ne last()]
return
concat(string-join($segments,'/'),'/')
For more details on these functions, check out their reference pages:
fn:tokenize()
fn:string-join()
fn:replace can do the job with a regular expression:
replace("/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/TRN_282C_HYD_MOD_1_Drive_Shaft_Rev000.xml",
"[^/]+$",
"")
This can be done even with a single XPath 2.0 (subset of XQuery) expression:
substring($fullPath,
1,
string-length($fullPath) - string-length(tokenize($fullPath, '/')[last()])
)
where $fullPath should be substituted with the actual string, such as:
"/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/TRN_282C_HYD_MOD_1_Drive_Shaft_Rev000.xml"
The following code tokenizes, removes the last token, replaces it with an empty string, and joins back.
string-join(
(
tokenize(
"/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/TRN_282C_HYD_MOD_1_Drive_Shaft_Rev000.xml",
"/"
)[position() ne last()],
""
),
"/"
)
It seems to return the desired result on try.zorba-xquery.com. Does this help?