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