Il logging è fondamentale per monitorare il funzionamento dei nostri plugin di WordPress.
Possiamo implementare la seguente funzione:
<?php
function my_log( $message = '' ) {
$log = strftime( '%Y-%m-%d', time() ) . '.log';
$path = plugin_dir_path( __FILE__ ) . 'logs/' . $log;
if( !file_exists( $path ) ) {
file_put_contents( $path, $message . "\n" );
} else {
file_put_contents( $path, $message . "\n", FILE_APPEND );
}
}