Don’t convert HTML chars
-
I tested Clink and it seems to be working generally very well. Just one thing seems to be working incorrectly: some characters like the ampersand (&) are encoded in the URLs.
The target URL we have: https://example.com/?product=shoe&color=yellow
What we see in the address bar after Clink redirection: https://example.com/?product=shoe& #038;color=yellow (minus the space)
This happens with both types of redirections, with and without the timer. However, this does not happen if the user clicks the link on the redirection page or if admin clicks the link on the link list at
wp-admin/edit.php?post_type=clink
.The cause of the problem is that the URLs are stored in the database in the _postmeta table in an encoded format, which works correctly when echoing the link in HTML, like the two clickable links mentioned above, but it does not work properly when blindly redirected to.
Fix
Edit https://plugins.trac.www.ads-software.com/browser/clink/trunk/clink-template.php and replace current line 13, which is
$clink_url = get_post_meta($post_id, 'clink_url', true);
with
$clink_url_for_html = get_post_meta($post_id, 'clink_url', true); $clink_url_for_redirection = str_replace('&', '&', $clink_url_for_html);
(Notice the variable names making it clear which should be used and where.)
and then replace every current occurrence of $clink_url with $clink_url_for_html, except on lines
57, 108 and 127 with $clink_url_for_redirection. Also declare $clink_url_for_redirection as global inside clink_page_generator(), after line 31.This fix does not decode the single quote (‘) encoded in the URLs, but can be easily extended to do so if necessary by adding another str_replace() call.
Code cleanup
Lines 85 and 110 in https://plugins.trac.www.ads-software.com/browser/clink/trunk/clink-template.php are redundant and can be deleted to make the code easier to read and work with.
- The topic ‘Don’t convert HTML chars’ is closed to new replies.