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
Add a comment  | 

2 Answers 2

Reset to default 0

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

  1. At the moment of initialization of the functions.php file
  2. 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