How to add custom classes to figure element only if image has caption?

How to add custom classes to figure element only if image has caption?

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)