admin管理员组文章数量:1122832
I developed a plugin for my citrus payment gateway.I created a shortcode to manage it. It was running absolutely fine some days ago.Now I don't know who changed what, now that shortcode is running twice :(
This is my code I am using.
add_shortcode('citrusafterpayment', 'citrusafterpayment_function');
function citrusafterpayment_function()
{
mail('[email protected]','check-in','asd');
global $wpdb;
if(isset($_REQUEST['TxStatus']) && $_REQUEST['TxStatus'] != '')
{
if($TxStatus == 'CANCELED')
{
$return_msg = '<div class="row-fluid"><div class="span12"> <div class="error">You have canceled your transaction.</div></div></div>';
return $return_msg;
}
}
}
I am using this shortcode on one of my webpage. Whenever that page is hitting I am getting emails two times.
I googled it but there is no useful result.
Please help me.
I developed a plugin for my citrus payment gateway.I created a shortcode to manage it. It was running absolutely fine some days ago.Now I don't know who changed what, now that shortcode is running twice :(
This is my code I am using.
add_shortcode('citrusafterpayment', 'citrusafterpayment_function');
function citrusafterpayment_function()
{
mail('[email protected]','check-in','asd');
global $wpdb;
if(isset($_REQUEST['TxStatus']) && $_REQUEST['TxStatus'] != '')
{
if($TxStatus == 'CANCELED')
{
$return_msg = '<div class="row-fluid"><div class="span12"> <div class="error">You have canceled your transaction.</div></div></div>';
return $return_msg;
}
}
}
I am using this shortcode on one of my webpage. Whenever that page is hitting I am getting emails two times.
I googled it but there is no useful result.
Please help me.
Share Improve this question edited May 27, 2015 at 4:58 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked May 27, 2015 at 4:34 raj aryanraj aryan 11 bronze badge 2- in the page make sure you close the shortcode eg: [citrusafterpayment][/citrusafterpayment] – Touqeer Shafi Commented May 27, 2015 at 4:39
- @TouqeerShafi yes it is closed fine. :( – raj aryan Commented May 27, 2015 at 4:48
2 Answers
Reset to default 0Try this way, it's not the proper way to figure it out but it will solve your problem.
function citrusafterpayment_function()
{
static $calls = 0;
if($calls == 0){ $calls++;
mail('[email protected]','check-in','asd');
global $wpdb;
if(isset($_REQUEST['TxStatus']) && $_REQUEST['TxStatus'] != '')
{
if($_REQUEST['TxStatus'] == 'CANCELED')
{
$return_msg = '<div class="row-fluid"><div class="span12"> <div class="error">You have canceled your transaction.</div></div></div>';
return $return_msg;
}
}
}
}
Edited:
You should pass: $_REQUEST['TxStatus']
in the if statement $TxStatus
is not defined in the function.
Maybe someone else will find it useful:
A shortcode is also a function. WordPress executes it twice.
- At the moment of initialization of the functions.php file
- At the moment of finding the shortcode on the page Alternatively:
/// [my_shortcode init = 1]
function my_shortcode($atts) {
include_once ( 'my code.php');
// my code.....
return $x;
}
add_shortcode( 'my_shortcode', 'my_shortcode' );
本文标签: pluginswordpress Shortocode running twice
版权声明:本文标题:plugins - wordpress Shortocode running twice? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296301a1929761.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论