0

I need to add a custom shortcode to the welcome email of my website.

I'm not expert; what I need is in plugabble.php file?

I tried a lot of plugins for edit email template but nothing seems work.

Is there anyone that can help me please?

Thanks in advance!

Ps. This is the one time link script that I have modified:


function one_time_link(){

/* Generate a unique token: */
$token = md5(uniqid(rand(),1));

$file = "/tmp/urls.txt";
if( !($fd = fopen($file,"a")) )
        die("Could not open $file!");

if( !(flock($fd,LOCK_EX)) )
        die("Could not aquire exclusive lock on $file!");

if( !(fwrite($fd,$token."\n")) )
        die("Could not write to $file!");

if( !(flock($fd,LOCK_UN)) )
        die("Could not release lock on $file!");

if( !(fclose($fd)) )
        die("Could not close file pointer for $file!");

/* Report the one-time URL to the user: */
$linkResult = "Your One Time Link\n";

}

I've tried this:


class LinkGenerator {
public function one_time_link(){

/* Generate a unique token: */
$token = md5(uniqid(rand(),1));

/* This file is used for storing tokens. One token per line. */
$file = "/tmp/urls.txt";
if( !($fd = fopen($file,"a")) )
        die("Could not open $file!");

if( !(flock($fd,LOCK_EX)) )
        die("Could not aquire exclusive lock on $file!");

if( !(fwrite($fd,$token."\n")) )
        die("Could not write to $file!");

if( !(flock($fd,LOCK_UN)) )
        die("Could not release lock on $file!");

if( !(fclose($fd)) )
        die("Could not close file pointer for $file!");

/* Report the one-time URL to the user: */
$linkResult = "Your Special Link\n";

echo "$linkResult";

}
}

add_filter( 'wpbe_tags', 'wpse_225078_wpbd_tags' );

function wpse_225078_wpbd_tags( $tags ) {
    $genLink = 'LinkGenerator';
    $a = new $genLink();
    $tags['one_time_link'] = $a->one_time_link(); 

    return $tags;
}

It seems correct for me but it doesn't work...

  • Hi Euca 90, welcome to WPSE! We would love to help, but you really need to clarify your question - it's simply too broad to answer. Perhaps specify which plugins you have tried, why exactly you need this custom shortcode (and perhaps what it does), and maybe any relevant code you already have? – TheDeadMedic Apr 28 '16 at 14:57
  • Sorry, you're right. I have created a php script that generates a one-time link. I would add this ever-changing link to each welcome email sent to the new members. I find WP Better Emails that allows me to create custom tags for my template...but I would like to understand how to take the new link generated before sending welcome emails to new users. Do you understand what i'm trying to explain? Thanks – Luke Apr 28 '16 at 15:50
  • Looking at the faq, you can register tags with PHP - you would just need to integrate your "php script" within your filter function (which I can't really help with unless you post some code) – TheDeadMedic Apr 28 '16 at 16:00
  • Yes, I have added script above (the variable is: $linkResult = "<a href='http://".$_SERVER['HTTP_HOST']."/wp-content/custom-php/get_file.php?q=$token'>Your One Time Link</a>\n"; ) – Luke Apr 28 '16 at 16:17
  • Then the script connects to get_file.php that verifies the generated link. I would like to understand how to take the new link generated ($linkResult - how to call function one_time_link()) before sending welcome emails to new users. – Luke Apr 28 '16 at 16:25
0

Based on your updated question and comments, this should be what you are looking for:

function wpse_225078_wpbd_tags( $tags ) {
    $tags['one_time_link'] = one_time_link();

    return $tags;
}

add_filter( 'wpbe_tags', 'wpse_225078_wpbd_tags' );

The idea is to hook into the tag system provided by WPBE so you can just use %one_time_link% in your email template.

Please note that this assumes one_time_link is a function in your theme/loaded within the WordPress environment.

There's no guarantee this will work, but I hope it puts you on the right path.

  • Thank you for the answer. Yes, but I should not first call the function one_time_link(); (inserted in function.php) and then take the variable $linkResult and insert it in an <a href></a>? – Luke Apr 28 '16 at 16:48
  • Yes you are correct - sorry, it's bit confusing without knowing your setup in detail. I hope I've helped enough that you can finally solve it, but let me know if you get really stuck. – TheDeadMedic Apr 28 '16 at 17:43
  • I have added script above - it seems correct for me but it doesn't work – Luke Apr 29 '16 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.