1

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>
  • No, it wouldn't execute multiple times for a single occurrence. There must be something in the CODE. Please edit your question and include the CODE, otherwise it's not possible to say anything definitively. – Fayaz Aug 14 '18 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.