Shortcode function executed twice?

I use a shortcode function to do some processing as a callback from external service. I created a page, the only content of which is the shortcode. User is redirected to this page from external function to trigger some data processing and inform user about the result.

The problem is: the page shows an error, because the specified data have already been processed. Further investigation revealed that the processing function is called twice on a single request.

Is it normal that shortcode function is executed multiple times, even if there is only one occurence of the shortcode on the page? What is a better way of using a plugin to provide a callback point to an external service?

UPDATE: Adding code:

plugin main file:

add_shortcode('myplugin-callback-page', 'myplugin_do_callback_page');
function myplugin_do_callback_page () {
    ob_start();
    require "callback_page.php";
    return ob_get_clean();
}

callback_page.php:

?php
if (!isset($_GET['param1']) || !isset($_GET['param2']) || !isset($_GET['param3'])) {
    // Not a valid callback, redirect to homepage
    wp_redirect(home_url());
    exit;
}

echo 'article id="callback-page-container"';

if ($_GET['RESULT'] != "OK") {
        $error = "error from external service";
} else {
        $result = myplugin_api_process_data($_GET['param1']);
        if ($result) {
                // Processed successfully
                do_something();
        } else {
                $error = "error from internal api";
        }
}

// Just display some stuff for user
require 'callback-page-content.php';
?
/article

Topic callbacks shortcode Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.