Home Forums Gutenberg How to Debug…


How to Debug…

  • I have been happily creating Gutenberg blocks using ACF 5.8 Beta 3 and it is really just great. In fact I am very close to a first release on a client website, using a range of custom blocks. I would say my workflow has improved considerably using Gutenberg, Blocks and ACF together – maybe as much as 15% time saving. Clients, which I have shown my work to, like the editor very much – less clutter and the previews are a real boon.

    The advantage of ACF Blocks for me is being able to leverage 15 years php dev experience without needing to learn ReactJS – It has saved the viability of WordPress as a CMS framework for me, as I was planning to just convert over to Drupal on 5.0 release. But maybe not so now – there is light at the end of the tunnel.

    The issue I find is when I do something stupid, the root of which is a PHP coding error, the page just sits there until it times out, then complains it cannot save the post if editing or just 500’s otherwise. Nothing produced in the PHP error log, WordPress debug gives no info – nothing to be had from the browser console either. Adding block support to ACF must have been quite frustrating at times.

    Further there is a real lack of documentation on Gutenberg for devs, so how to achieve a viable debug process seems to boil down to trial, error and persistence.

    What do you do to debug coding errors in your callbacks/templates?

  • When you say that wp debug give no help, you are not seeing PHP errors in the debug log at all?

    Or are the coding errors things that do not create an a PHP error (for example in infinite loop that just times out the server) and therefore don’t log errors in the error log?

    If it’s the second case, this is always a problem when working with AJAX or REST or whatever you want to popular term is :P, and you need to get some output to see what’s going on. One solution is to log an error yourself.

    Some examples:

    If I just want to see if my code gets to a specific place before it dies

    error_log('Got Here');

    let’s say that I want to see what the value of some array is during execution:

    ob_start(); print_r($array); error_log(ob_get_clean());
  • Yes that is pretty much what I have been doing – but you need to wait for the response to time out – 30 seconds on my server – so this is a time consuming and inefficient workflow. On the bright side, I suppose it gives you the chance to contemplate where the screw up fairy just waved her wand.

    It would be real nice for someone to come up with something more novel.

  • 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());
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘How to Debug…’ is closed to new replies.