Home Forums Gutenberg How to Debug… Reply To: How to Debug…

  • When dealing with AJAX I usually debug by returning something as JSON and logging the return to the console, but it will be different in this case since there is no return to use. I’m sure that I’ll find other ways but I have not had much chance to play around creating blocks with ACF.

    I do have a function I use to write data to a text file. I call the function with debugging information. I change the path as I need it, but the file name is a time stamp. Then I can watch the server for the new file to appear so I can get the file and see what’s going on. I make other adjustments as the need arises as well depending on what I’m looking for.

    Here it is in case it helps anyone.

      function write_to_file($value, $comment='') {
        // this function for testing & debuggin only
        $file = dirname(__FILE__).'/-data-'.date('Y-m-d-h-i').'.txt';
        $handle = fopen($file, 'a');
        if ($comment) {
          echo $comment.":\r\n";
        if (is_array($value) || is_object($value)) {
        } elseif (is_bool($value)) {
        } else {
          echo $value;
        echo "\r\n\r\n";
        fwrite($handle, ob_get_clean());