向欢迎邮件添加自定义快捷代码

时间:2016-04-28 作者:Luke

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...

1 个回复
SO网友:TheDeadMedic

根据您最新的问题和评论,这应该是您想要的:

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

    return $tags;
}

add_filter( \'wpbe_tags\', \'wpse_225078_wpbd_tags\' );
其想法是连接到WPBE提供的标记系统中,这样您就可以使用%one_time_link% 在您的电子邮件模板中。

请注意,这假设one_time_link 是主题中的一个函数/加载到WordPress环境中。

不能保证这会奏效,但我希望这能让你走上正确的道路。