Title: Own plugin calling function twice
Last modified: February 15, 2017

---

# Own plugin calling function twice

 *  [jmeyerdo](https://wordpress.org/support/users/jmeyerdo/)
 * (@jmeyerdo)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/own-plugin-calling-function-twice/)
 * 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](https://wordpress.org/support/users/jmeyerdo/)
 * (@jmeyerdo)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/own-plugin-calling-function-twice/#post-8807435)
 * 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](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/own-plugin-calling-function-twice/#post-8809443)
 * 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.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/own-plugin-calling-function-twice/#post-8809443)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
