0

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.

2
  • in the page make sure you close the shortcode eg: [citrusafterpayment][/citrusafterpayment] Commented May 27, 2015 at 4:39
  • @TouqeerShafi yes it is closed fine. :(
    – raj aryan
    Commented May 27, 2015 at 4:48

2 Answers 2

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.

4
  • NO. It did not solve it. still getting emails two times :(
    – raj aryan
    Commented May 27, 2015 at 4:54
  • I think you changed code. and yes now email is coming once but now another issue comes up that the message which I was returning not printing on my webpage
    – raj aryan
    Commented May 27, 2015 at 4:56
  • Are you sure that $_REQUEST['TxStatus'] are you getting ? Commented May 27, 2015 at 4:59
  • 100% sure. Code under function is working fine. I have tested it so many times.
    – raj aryan
    Commented May 27, 2015 at 5:02
0

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' );
1
  • The PHP interpreter parses functions when they're defined, but it doesn't execute them.
    – Chris Cox
    Commented Sep 1 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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