PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

URL Shortener WP Filter (DIFF Attached)

s2Member Plugin. A Membership plugin for WordPress®.

URL Shortener WP Filter (DIFF Attached)

Postby lewayotte » January 14th, 2011, 11:12 pm

I've been getting a bunch of clients who sign up and "never" receive the registration email. Most of them find it in their SPAM folder after I tell them to look there. Some are just issues with their PayPal email account vs. the email account they now use.

But I wanted to cut down on the amount of times the registration email is automatically marked as SPAM, it's been an ongoing battle. I've even added SPF1 and domainkey records to my zone file. But still, I get a bunch of these support emails and it's wasting my time.

The best I can figure is that some spam filters just don't like the TinyURL url embedded in the emails. Plus if people can't find the email in their SPAM, I have to manually create the account (since there is no easy way to recreate the registration link).

Well, this morning I set to switch from TinyURL to my own URL Shortening service using YOURLS. The API is a little different but it took me less than 10 minutes to setup, the URL is the same as my site, I get to track all the URLs generated (so it is easier for me to get the user's registration link), and hopefully it'll cut down on my messages being seen as SPAM!

Basically I changed line 32 of s2member/includes/functions/register-access.inc.php from:
if ($shrink && ($tinyurl = ws_plugin__s2member_remote ("http://tinyurl.com/api-create.php?url=" . rawurlencode ($register_link))))

to:
if ($shrink && ($tinyurl = ws_plugin__s2member_remote ( apply_filters( 's2member_remote_shrink_url', "http://tinyurl.com/api-create.php?url=" ) . rawurlencode ($register_link))))

I have YOURLS installed in it's own subdirectory on my site, this is the code I added to my functions.php to hook into the new filter:

function yourls_shrink () {
return "http://leenk.me/reg/yourls-api.php?signature=XXXXXXXX&action=shorturl&format=simple&url=";
}
add_filter( 's2member_remote_shrink_url', 'yourls_shrink');

So now, instead of a TinyURL like this: http://tinyurl.com/XXXXXXX
I get a custom YOURLS like this: http://leenk.me/reg/XXXXXXX

I've never used Bit.ly before, but I imagine someone could simply change the URL to a bit.ly URL if they wanted to use that as the URL shortener... assuming they have a basic API like TinyURL and YOURLS.

This has been running all day without any trouble (yet).

Thoughts?
User avatar
lewayotte
Experienced User
Experienced User
 
Posts: 33
Joined: June 22, 2010
Location: Athens, GA

Re: URL Shortener WP Filter (DIFF Attached)

Postby lewayotte » January 14th, 2011, 11:18 pm

Apparently "The extension diff is not allowed." :)

Attached as a .txt
Attachments
register-access.inc.php.txt
Diff File
(1.46 KiB) Downloaded 11792 times
User avatar
lewayotte
Experienced User
Experienced User
 
Posts: 33
Joined: June 22, 2010
Location: Athens, GA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » January 15th, 2011, 1:59 pm

Nice.

I didn't know Yourls. I'll look more into it, always wanted something under my control for the URL shortening.

About the spam problem, it may also be caused by the IP of your server, especially if you're in a shared host. You could get your own IP, but even better would be to get a mail-server that already has a good track with email services and has a good inbox delivery record.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby lewayotte » January 15th, 2011, 3:11 pm

I'm actually on a static IP...

I have been thinking of piping my sent mail through my Google Aps account, I may get on that.

Thanks.

YOURLS was written by @ozh, he's pretty well known in the WordPress community. So far I'm really liking the app, I know of a number of my friends using it and I haven't heard anything bad yet. Give it a try! :)
User avatar
lewayotte
Experienced User
Experienced User
 
Posts: 33
Joined: June 22, 2010
Location: Athens, GA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » January 15th, 2011, 3:33 pm

Thanks! :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » March 1st, 2011, 6:46 pm

Lew, I'm now at the point where I want to implement the YOURLS shortening to the registration links and your instructions are helping me.

My problem is that editing register-access.inc.php like that will make me have to re-apply the edits after an s2Member update.

Is there any way to edit that code in a way that it'll keep working after an update?

Looking at the line you're quoting, I think that instead of having the TinyURL URL hardcoded in the function, it should be something more abstratct that'll allow using other services with ease.

Maybe having an s2member_url_shrink($url) function that we can edit easily and will change the behaviour in the different places where URLs are shrunk.

In that function we can have a variable for the shrinking service's URL part before the URL to shrink, like:

http://tinyurl.com/api-create.php?url=
http://leenk.me/reg/yourls-api.php?sign ... imple&url=

and any other shortening service.

Now, if you went and edited the register-access.inc.php, why didn't you just change the shortening service URL directly instead of using the apply_filter() function, etc.? Like this

Code: Select all
if ($shrink && ($tinyurl = ws_plugin__s2member_remote ('http://leenk.me/reg/yourls-api.php?signature=XXXXXXXX&action=shorturl&format=simple&url=' . rawurlencode ($register_link)))) 


Would that not work?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby lewayotte » March 1st, 2011, 7:09 pm

Hi,

My diff included has the apply_filter because if they include it in the source, it is a way of changing the shortening URL without changing the source... is that circular?

What I mean is, if they (PrimoThemes) included my diff into their code, then we'd just need to have my code in the functions.php file to overwrite that setting.

Lew
User avatar
lewayotte
Experienced User
Experienced User
 
Posts: 33
Joined: June 22, 2010
Location: Athens, GA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » March 1st, 2011, 7:13 pm

Got it.

I guess we're both asking for the same with a slightly different approach. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » March 1st, 2011, 7:59 pm

By the way, the file is not in the functions directory any more, now it's under classes and the line we've been quoting is now slightly different:

Code: Select all
if ($shrink && ($tinyurl = c_ws_plugin__s2member_utils_urls::remote ("http://tinyurl.com/api-create.php?url=" . rawurlencode ($register_link)))) 


This is most probably because of the speed optimizations in the latest releases.

Now, thinking about it further, it may not even be necessary to have a function to abstract the url shrinking service, a variable may be enough:

Code: Select all
if ($shrink && ($tinyurl = c_ws_plugin__s2member_utils_urls::remote ($shrink_service . rawurlencode ($register_link)))) 


With $shrink_service being easy to change into another one without touching s2Member's code.

But it may be even better to have the function after all, cause then you'd write less each time you need to shrink a URL and whatever improvement/change is done to that code, happens in a single place:

Code: Select all
if ($shrink && ($tinyurl = c_ws_plugin__s2member_utils_urls::shrink ($register_link))) 
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » March 2nd, 2011, 5:43 pm

I got s2Member to work with YOURLS now. I'm loving them. :)

Since I'll be using them for other links, not just registration ones, I didn't name the YOURLS directory "reg" or something similar, instead I'm using the keyword parameter when shortening the URL. Because I need to make the URLs unique, I also added time() to the keyword.

And because the domain name now is my own, I removed the anchor with the domain name that s2Member adds by default to TinyURLs.

Code: Select all
if ($shrink && ($tinyurl = c_ws_plugin__s2member_utils_urls::remote ('http://**********.com/go/yourls-api.php?signature=**********&action=shorturl&format=simple&keyword=register-' . time() . '&url=' . rawurlencode ($register_link))))
    return apply_filters ("ws_plugin__s2member_register_link_gen", $tinyurl, get_defined_vars ()); 


Which ouputs something like: http://**********.com/go/register-1299104688

I'd much rather use the ClickBank transaction receipt number, but don't know how to get it. In the IPN log it's named ctransreceipt. Any idea how I can get that into the URL?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Jason Caldwell » March 10th, 2011, 2:52 pm

Great work guys. Thank you for sharing.

Starting with s2Member v3.5.3 we'll add two additional Filters.

1. ws_plugin__s2member_register_link_gen_alternative ( Membership Access )
2. ws_plugin__s2member_sp_access_link_gen_alternative ( Specific Post/Page Access )

So starting with s2Member v3.5.3+, you can do something like this.

1. Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
( file name is not important )

2. Do something like this to your hacks file.
Code: Select all
<?php
add_filter 
("ws_plugin__s2member_register_link_gen_alternative", "my_link_shortener");
add_filter ("ws_plugin__s2member_sp_access_link_gen_alternative", "my_link_shortener");
function my_link_shortener ($long_link) /* Raw link ( the long version ). */
    {
        return /* Shorten this */ $long_link;
    }
?>
In a later release, I'll see if we can add some additional pre-integrated alternatives into the Dashboard for s2Member Pro. I'm a Google® fan myself. http://goo.gl/

( Google API docs: http://code.google.com/apis/urlshortene ... arted.html ) This is still in Labs though.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » March 10th, 2011, 3:15 pm

Great! That way we won't have to re-apply the hack after each s2Member update. :)

Is there any way I can get the ClickBank transaction receipt number in the s2hacks.php file for this?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby lewayotte » March 10th, 2011, 6:11 pm

Thanks Jason!
User avatar
lewayotte
Experienced User
Experienced User
 
Posts: 33
Joined: June 22, 2010
Location: Athens, GA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Jason Caldwell » March 11th, 2011, 5:53 am

clavaque wrote:Great! That way we won't have to re-apply the hack after each s2Member update. :)

Is there any way I can get the ClickBank transaction receipt number in the s2hacks.php file for this?

Although s2Member Pro initially deals with ClickBank IPNs through a dedicated handler, these ClickBank IPNs are reformulated internally by s2Member Pro, and the ClickBank Receipt # ultimately comes through s2Member's core PayPal processor as the $_POST["txn_id"] variable.

So if you really need to, you can use some of the Hooks/Filters made available inside: /s2member/includes/classes/paypal-notify-in.inc.php. You're looking for $paypal["txn_id"] in that file.

To answer your question. Here is how I would do it in the context of these Filters.
Code: Select all
<?php
add_filter 
("ws_plugin__s2member_register_link_gen_alternative", "my_link_shortener");
add_filter ("ws_plugin__s2member_sp_access_link_gen_alternative", "my_link_shortener");
function my_link_shortener ($long_link) /* Raw link ( the long version ). */
    {
        if($_GET["s2member_paypal_proxy"] === "clickbank" && $_POST["txn_id"])
            { $clickbank_receipt_number = $_POST["txn_id"]; }
            
        return 
/* Shorten this */ $long_link;
    }
?>
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » March 11th, 2011, 12:44 pm

Awesome! Thank you! :D
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » August 8th, 2011, 2:15 am

After all this time I finally came back to this hack. Here's what I have:

Code: Select all
// Shorten registration link.
add_filter('ws_plugin__s2member_register_link_gen_alternative', 's2_alt_shorten_link');
function s2_alt_shorten_link($link)
{
    if ($_GET['s2member_paypal_proxy'] === 'clickbank')
    {
        return c_ws_plugin__s2member_utils_urls::remote('http://example.com/go/yourls-api.php?signature=xxxxxxxx&action=shorturl&format=simple&keyword=register-' . $_POST['txn_id'] . '&url=' . rawurlencode($link));
    }
}
 


Is it safe to assume that after a ClickBank purchase $_POST['txn_id'] will always be set and with the receipt code?

This would create URLs like http://example.com/go/register-8KR7BXRE. Knowing the ClickBank receipt code, it will be easy to give the user his registration URL again if he lost it.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Jason Caldwell » August 10th, 2011, 12:55 pm

Is it safe to assume that after a ClickBank purchase $_POST['txn_id'] will always be set and with the receipt code?
Yes, in the current release it is safe to assume this. I'd still check for it though, just in case something changes in a future release, it will help to safeguard your custom routine a bit.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » August 10th, 2011, 12:59 pm

Got it, thanks for confirming it. What do you recommend using as a fallback in case that's not set? Is there some other string I could use as an ID for that particular transaction or buyer in the short URL?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Jason Caldwell » August 10th, 2011, 3:16 pm

These could be used as backups, if/when they're available:
$_POST['subscr_id'] or $_POST['payer_email']
Short of that, you could generate your own with uniqid().
http://php.net/manual/en/function.uniqid.php
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » August 10th, 2011, 4:21 pm

Ah, thanks a lot for the uniqid() function, I've used time() in the past, but I'm trying to use something that will let me guess the user's URL in the future, so something I can get from his payment receipt would be best.

Are $_POST['subscr_id'] or $_POST['payer_email'] only available if $_POST['txn_id'] is, or could it be that txn_id is not there but one of subscr_id is?

I'm guessing that payer_email would be the most reliable one, is that correct? If so, I could md5($_POST['payer_email']) or some other one that outputs less characters (do you know one?).
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Jason Caldwell » August 10th, 2011, 4:41 pm

At this time, if $_POST["txn_id"] is not available, the Hook you've attached to would not even be called upon. So it's safe to use $_POST["txn_id"], and/or $_POST["payer_email"]. For safety's sake though, I would go ahead and check to be sure $_POST["txn_id"] is !empty(). Again, just to be safe. I don't foresee anything preventing that from working in future releases, but it never hurts to check.

Other unique identifiers might include the User's IP address, which is held inside $_POST["option_selection2"]
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » August 10th, 2011, 4:48 pm

Got it. Thanks!

I'll just go through the variables until finding one that exists and if nothing is avaialble, will default to uniqid or time.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » August 10th, 2011, 6:08 pm

Maybe something like this:

Code: Select all
// Shorten registration link.
add_filter('ws_plugin__s2member_register_link_gen_alternative', 's2_alt_shorten_link');
function s2_alt_shorten_link($link)
{
    if ($_GET['s2member_paypal_proxy'] === 'clickbank')
    {
        $id = !empty($_POST['txn_id']) ?
            $_POST['txn_id']
        : !empty(
$_POST['payer_email']) ?
            
md5($_POST['payer_email'])
        : !empty($_POST['subscr_id']) ?
            $_POST['subscr_id']
        : time();

        return c_ws_plugin__s2member_utils_urls::remote('http://example.com/go/yourls-api.php?signature=xxxxxxxx&action=shorturl&format=simple&keyword=register-' . $id . '&url=' . rawurlencode($link));
    }
}
 
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: URL Shortener WP Filter (DIFF Attached)

Postby Jason Caldwell » August 10th, 2011, 6:23 pm

Cool. Just a quick observation.
Code: Select all
$id = !empty($_POST['txn_id']) ?
            $_POST['txn_id']
        : !empty($_POST['payer_email']) ?
            md5($_POST['payer_email'])
        : !empty($_POST['subscr_id']) ?
            $_POST['subscr_id']
        : time(); 

It is recommended that you avoid "stacking" ternary expressions. PHP's behaviour when using more than one ternary operator within a single statement is non-obvious. See details here: http://php.net/manual/en/language.opera ... arison.php

While the article above discourages this, you will find that I DO this even so. However, when I do this, I always wrap the second and/or third ternary expressions inside brackets () so that I get the actual return value of that sub-ternary expression, for lack of a better term. In cases where I'm checking for more than two or three conditions, I may expand it out of a ternary expression and into a switch or if/else.

The behavior of ternary expressions is NOT desirable in PHP, in this regard; especially since it conflicts with the way they are handled in JavaScript. Your code would be fine in JavaScript.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: URL Shortener WP Filter (DIFF Attached)

Postby Cristián Lávaque » August 10th, 2011, 6:53 pm

Oh, ok. Thanks for the heads up. Like this then:

Code: Select all
// Shorten registration link.
add_filter('ws_plugin__s2member_register_link_gen_alternative''s2_alt_shorten_link');
function 
s2_alt_shorten_link($link)
{
    if (
$_GET['s2member_paypal_proxy'] === 'clickbank')
    {
        
$id = (!empty($_POST['txn_id']) ?
            
$_POST['txn_id']
        : (!empty(
$_POST['payer_email']) ?
            
md5($_POST['payer_email'])
        : (!empty(
$_POST['subscr_id']) ?
            
$_POST['subscr_id']
        : 
            
time()
        )));

        return 
c_ws_plugin__s2member_utils_urls::remote('http://example.com/go/yourls-api.php?signature=xxxxxxxx&action=shorturl&format=simple&keyword=register-' $id '&url=' rawurlencode($link));
    }
}
 
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Next

Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron