Hi,
I'm looking for a solution to add a email parameter in my WP URL.
Something like: www.mysite.com/[email protected]
--
We can publish the User information (email) on any page with Get UserData
http://codex.wordpress.org/Function_Reference/get_userdata
& linking with something like:
add_rewrite_tag( '%email%', '([^/]+)');
http://codex.wordpress.org/Rewrite_API/add_rewrite_rule
But I'm just guessing, any ideas?
Many thanks,
Jonathan
timDesain Nanang answers:
jQuery Method
try:
put this code in the <strong>functions.php</strong> under your theme folder
add_action('wp_footer', 'timdesain_var_footer');
function timdesain_var_footer(){
global $user_ID;
if(is_user_logged_in()){
$user_info = get_userdata($user_ID);
$user_email = $user_info->user_email;
?>
<script type="text/javascript">
jQuery(document).ready(function(){
var mail = 'email=<?php echo sanitize_email($user_email); ?>';
jQuery('a').attr('href', function() {
if(!/email/i.test(this)){
return this.href + '?' + mail;
}
});
});
</script>
<?php
}
}
add_action('init', 'timdesain_var_init');
function timdesain_var_init(){
//get the email here
if(is_user_logged_in()){
$email = isset($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '';
//echo $email;
}
}
<strong>update: </strong>
This code can be used in all pages that based on wordpress.
Jonathan Surinx comments:
Waw that did the trick immediately! Amazing, many thanks :)
Last question: would I be able to use this for only one page of the webstite or complicate?
smc answers:
what you want to accomplish , can you explain please.
smc comments:
you can use following function to add param to url
http://codex.wordpress.org/Function_Reference/add_query_arg
Jonathan Surinx comments:
Oh right : I need this just to be able to catch this email in another program (just to avoid the user to register 2 times, once on WP and once on my own program).
Thanks for you reply, would this add_query_arg work with adding an email from a registered user?
smc comments:
you have to pass the email and the url to the function I told you .. let me know if not works for you..
Romel Apuya answers:
Hi,
have you read this?
[[LINK href="http://www.webopius.com/content/137/using-custom-url-parameters-in-wordpress"]]http://www.webopius.com/content/137/using-custom-url-parameters-in-wordpress[[/LINK]]
Jonathan Surinx comments:
Not yet thanks !
This plugin also already exist... http://wordpress.org/plugins/url-params/
Will look into it.