Hi Nicolas,
You can store the changed fields and then process the log when the post is saved. Here is what I suggest:
class MB_Log {
protected $fields = array();
public function __construct() {
add_filter( 'rwmb_value', array( $this, 'check_field_change' ), 20, 3 );
add_action( 'rwmb_after_save_post', array( $this, 'log' ) );
}
public function check_field_change( $new, $field, $old ) {
if ( $new !== $old ) {
$this->fields[] = $field;
}
return $new; // Do not change the value
}
public function log() {
foreach ( $this->fields as $field ) {
// Log
}
}
}