I am working on a plugin but I am getting this error Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
when adding elements in gravity forms Version 2.5.10.1 only when my plugin is calling a class. This error also occurs when When interacting with different tools in WordPress (kind of all over) but again, only when my plugin is calling a class. But I receive no errors when I do this with functions as opposed to OOP.
Using XAMMP 7.4.23-0
macOS Big Sur: Version 11.6
Plugin Code
/*
Plugin Name: Testing plugin
Description: filler
Version: 1.0
Author: me
Author URI: http://www.google.com
License: GPLv2 or later
Text Domain: plugins testing
*/
if ( ! defined ( 'ABSPATH')) exit; // Exit if accessed directly
define( 'AGFR__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
class testing_reporting{
public function init() {
$this->console_log("Initiating AgfReport class.");
$this->console_log("AgfReport Short Code initiated.");
}
private function console_log($output = null, $with_script_tags = true) {
if($output != null){
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ');';
if ($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
echo $js_code;
}
}
}
$new_class = new testing_reporting();
$new_class->init();