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.
<?php
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');
ob_start();
if ($comment) {
echo $comment.":\r\n";
}
if (is_array($value) || is_object($value)) {
print_r($value);
} elseif (is_bool($value)) {
var_dump($value);
} else {
echo $value;
}
echo "\r\n\r\n";
fwrite($handle, ob_get_clean());
fclose($handle);
}
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
π Weβre excited to announce we've released Composer support for installing ACF PRO.
— Advanced Custom Fields (@wp_acf) January 31, 2023
π #ComposerPHP fans rejoice!
β¨ Please see the release post for all the details and full instructions. https://t.co/ebEfp61nlR
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.