How to set default value for 'Alt text' on image upload dialog (ok)

https://wordpress.stackexchange.com/questions/182075/how-to-set-default-value-for-alt-text-on-image-upload-dialog

function update_attachment_fields($post, $attachment)
{
  if (isset($attachment['meta_credit'])) {
    $credit = $attachment['meta_credit'];
    $meta = wp_get_attachment_metadata($post['ID']);
    if ($credit !== $meta['image_meta']['credit']) {
        $meta['image_meta']['credit'] = $credit;
        wp_update_attachment_metadata($post['ID'], $meta);
    }
  }
  return $post;
}
add_filter('attachment_fields_to_save', 'update_attachment_fields', 10, 2);

Last updated