diff --git a/lib/image-licensing.php b/lib/image-licensing.php index bd1f8e4a..4fc8ec00 100644 --- a/lib/image-licensing.php +++ b/lib/image-licensing.php @@ -3,63 +3,77 @@ global $gds_image_licences; $gds_image_licences = [ - 'ogl' => [ - 'name' => 'OGL', - 'link' => 'http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/', - 'display' => false, - ], - 'cc-by' => [ - 'name' => 'Creative Commons Attribution', - 'link' => 'http://creativecommons.org/licenses/by/4.0', - 'display' => true, - ], - 'cc-by-sa' => [ - 'name' => 'Creative Commons Attribution-ShareAlike', - 'link' => 'http://creativecommons.org/licenses/by-sa/4.0', - 'display' => true, - ], - 'cc-by-nd' => [ - 'name' => 'Creative Commons Attribution-NoDerivs', - 'link' => 'http://creativecommons.org/licenses/by-nd/4.0', - 'display' => true, - ], - 'cc-by-nc' => [ - 'name' => 'Creative Commons Attribution-NonCommercial', - 'link' => 'http://creativecommons.org/licenses/by-nc/4.0', - 'display' => true, - ], - 'cc-by-nc-sa' => [ - 'name' => 'Creative Commons Attribution-NonCommercial-ShareAlike', - 'link' => 'http://creativecommons.org/licenses/by-nc-sa/4.0', - 'display' => true, - ], - 'cc-by-nc-nd' => [ - 'name' => 'Creative Commons Attribution-NonCommercial-NoDerivs', - 'link' => 'http://creativecommons.org/licenses/by-nc-nd/4.0', - 'display' => true, - ], - 'other' => [ - 'name' => 'Other', - 'link' => null, - 'display' => false, - ], + 'ogl' => [ + 'name' => 'OGL', + 'link' => 'https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/', + 'display' => false, + ], + 'cc-by' => [ + 'name' => 'Creative Commons Attribution', + 'link' => 'https://creativecommons.org/licenses/by/4.0/', + 'display' => true, + ], + 'cc-by-sa' => [ + 'name' => 'Creative Commons Attribution-ShareAlike', + 'link' => 'https://creativecommons.org/licenses/by-sa/4.0/', + 'display' => true, + ], + 'cc-by-nd' => [ + 'name' => 'Creative Commons Attribution-NoDerivs', + 'link' => 'https://creativecommons.org/licenses/by-nd/4.0/', + 'display' => true, + ], + 'cc-by-nc' => [ + 'name' => 'Creative Commons Attribution-NonCommercial', + 'link' => 'https://creativecommons.org/licenses/by-nc/4.0/', + 'display' => true, + ], + 'cc-by-nc-sa' => [ + 'name' => 'Creative Commons Attribution-NonCommercial-ShareAlike', + 'link' => 'https://creativecommons.org/licenses/by-nc-sa/4.0/', + 'display' => true, + ], + 'cc-by-nc-nd' => [ + 'name' => 'Creative Commons Attribution-NonCommercial-NoDerivs', + 'link' => 'https://creativecommons.org/licenses/by-nc-nd/4.0/', + 'display' => true, + ], + 'other' => [ + 'name' => 'Other', + 'link' => null, + 'display' => false, + ], ]; add_filter('image_send_to_editor', function ($html, $id, $caption, $title, $align, $url, $size, $alt) { global $gds_image_licences; + $caption = ''; $_licence = get_post_meta($id, 'licence', true); - $licence = $gds_image_licences[$_licence]; + if (!empty($_licence)) { + $licence = $gds_image_licences[$_licence]; + } else { + $licence = $gds_image_licences['other']; + } + $copyright_holder = get_post_meta($id, 'copyright_holder', true); $link_to_source = get_post_meta($id, 'link_to_source', true); - $caption = 'Licence: '; - if ($licence['display'] === true) { - $caption .= ''.esc_html($licence['name']).''; + if ($licence['display'] === true || !empty($copyright_holder)) { + if ($licence['display'] === true) { + $caption .= __('Licence:'); + $caption .= ' '.esc_html($licence['name']).''; + if (!empty($copyright_holder)) { + $caption .= ', '; + } + } + if (!empty($copyright_holder)) { + $caption .= ''.esc_html($copyright_holder).''; + } + $output_html = '
'.$html.'
'.$caption.'
'; } else { - return $html; + $output_html = $html; } - $caption .= ' '.esc_html($copyright_holder).''; - return '
'.$html.'
'.$caption.'
'; + return $output_html; }, 999, 8);