• I have created an own plugin. I added it to a wordpress page with following action:

    add_shortcode("myplugin", "MyFunction");

    I am posting some information via form/POST to this plugin. Unfortunately one important function (calling external URL/API via CURL) is processed twice every time I am posting this information in function1().

    Do you have any idea why/how to avoid this?

    function MyFunction($atts) {
    
              $content = "Content...";
              // [...]
    		  // switching tasks by GET/POST-parameters
    		  switch ($task) {
              	case "task1":
              		$content = function1($value1, $value2);
              		break;
              default: 
              		$content = showform();
              }
    		  
    		  return $content;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jmeyerdo

    (@jmeyerdo)

    I figured out that the problem is cause by one plugin: “Simple Facebook Connect”. With deactivated plugin there is no duplicate call of function. Strange. Any ideas for this?

    Moderator bcworkz

    (@bcworkz)

    You’d get a more accurate answer by asking the plugin’s author in their dedicated support forum. I’m guessing it re-processes the post content as part of the data included in connecting to facebook.

    Generally speaking, it’s not safe to assume anything in WP is processed only once per request. In cases such as gathering visitor statistics where only one pass per request is necessary for accuracy, one should take specific measures to prevent code from being executed more than once. For example, immediately returning from a function if a certain constant is defined, which is defined after the first pass through.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Own plugin calling function twice’ is closed to new replies.