Title: Calling a plugin across two scripts
Last modified: August 31, 2016

---

# Calling a plugin across two scripts

 *  Resolved [onmas](https://wordpress.org/support/users/onmas/)
 * (@onmas)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/calling-a-plugin-across-two-scripts/)
 * Hi everyone.
 * This is my first post – I hope I’ve asked it correctly.
 * I need to make a call from WordPress (using Ajax) out to a script (CALL_SHORTCODE.
   php below) to retrieve some data from a table. To do this, the 1st script needs
   to call another script (TEST_SHORTCODE.php) to get the login name of the user
   from a plugin.
 * WP (ajax) –> CALL_SHORTCODE.php –> TEST_SHORTCODE.php
 * I’m not getting any data back in CALL_SHORTCODE.php. However, if I just call 
   TEST_SHORTCODE.php without calling it from CALL_SHORTCODE.php I get data I want(
   eh?). The following code will run.
 * [CALL_SHORTCODE.php]
 *     ```
       <?php
         // Call our script to get who's logged in
         $jsonurl = "http://my.url.com/scripts/TEST_SHORTCODE.php";
         $json = file_get_contents($jsonurl);
         var_dump($json);
       ?>
       ```
   
 * [TEST_SHORTCODE.php]
 *     ```
       <?php
         // Include WordPress
         // Tried using wp-blog-header.php as well to no avail
         include_once '../wp-load.php';
   
         // Get login name from Memberpress and return it
         $username = do_shortcode("[mepr-account-info field='user_login']");
         $rows[] = array( 'username'=>$username );
         echo json_encode($rows, JSON_NUMERIC_CHECK);
       ?>
       ```
   
 * …Output from calling TEST_SHORTCODE.php (valid JSON):
 * `[{"username":"foo.bar@gmail.com"}]`
 * …However, the output from calling CALL_SHORTCODE.php is:
 * `string(17) "[{"username":""}]"`
 * …As you can see, there is no value in the output of CALL_SHORTCODE.php.
 * This one is driving me bonkers 🙂
 * Many thanks in advance
    Jason

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [epicdevspace](https://wordpress.org/support/users/epicdevspace/)
 * (@epicdevspace)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/calling-a-plugin-across-two-scripts/#post-7395122)
 * Hi Jason
 * Where is call_shortcode.php located?
 *  Thread Starter [onmas](https://wordpress.org/support/users/onmas/)
 * (@onmas)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/calling-a-plugin-across-two-scripts/#post-7395136)
 * Hi there.
 * Thanks for getting back to me. Unfortunately, its behind a password protected
   server and I can’t provide access (much as I really want to as this is taking
   up loads of time). But the scripts are in the locations above (albeit with a 
   spurious URL) and produce the output shown when called as:
 * [http://my.url.com/scripts/TEST_SHORTCODE.php](http://my.url.com/scripts/TEST_SHORTCODE.php)
   
   [http://my.url.com/scripts/CALL_SHORTCODE.php](http://my.url.com/scripts/CALL_SHORTCODE.php)
 * Its very strange.
 * Jason
 *  [epicdevspace](https://wordpress.org/support/users/epicdevspace/)
 * (@epicdevspace)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/calling-a-plugin-across-two-scripts/#post-7395196)
 * Hi
 * What is the value of $json (before the var_dump) in your CALL_SHORTCODE.php?
 *  Thread Starter [onmas](https://wordpress.org/support/users/onmas/)
 * (@onmas)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/calling-a-plugin-across-two-scripts/#post-7395239)
 * Hi again epicdevspace,
 * Thanks for helping on this. Its just:
 * [{“username”:””}]
 * Jason
 *  Thread Starter [onmas](https://wordpress.org/support/users/onmas/)
 * (@onmas)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/calling-a-plugin-across-two-scripts/#post-7395244)
 * Hi again epicdevspace,
 * I’ve had a response that provides the reason for the problem. When the client
   calls TEST_SHORTCODE.php directly, MemberPress knows its a client (perhaps via
   cookie or session variable) and can respond. However, if the client calls the
   CALL_SHORTCODE.php script and its the script that calls TEST_SHORTCODE.php then
   the call is coming from the server not the client.
 * So I appear to have an explanation but no solution to my problem which will need
   a rethink.
 * Thanks for taking the time to consider it. I’ll mark the question closed.
 * Regards,
    -Jason

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Calling a plugin across two scripts’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 5 replies
 * 2 participants
 * Last reply from: [onmas](https://wordpress.org/support/users/onmas/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/calling-a-plugin-across-two-scripts/#post-7395244)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
