I have a test shortcode to read a JSON file:
function test( ) {
$strJsonFileContents = file_get_contents("./node.json");
$array = json_decode($strJsonFileContents, true);
echo var_dump($array); // print array
}
add_shortcode( 'test', 'test' );
Adding this shortcode into a post I can’t update it due to the error
Updating failed. The response is not a valid JSON response.
Following the article How to Fix The Invalid JSON Error in WordPress (Beginner’s Guide), I activate the Health Check & Troubleshooting, use the Classic Editor add the debug code into the wp-config.php :
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
And this is the result:
Warning: file_get_contents(./node.json): failed to open stream: No such file or directory in /home/xnqucuhr5aza/public_html/wp-content/plugins/Custom 1/Custom plugin.php on line 67
NULL
Why does this happen? Obviously the file is in the same directory to the plugin (i.e. /home/xnqucuhr5aza/public_html/wp-content/plugins/Custom 1/node.json)