Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter("attachment_fields_to_edit", "add_image_source_url", 10, 2);
- function add_image_source_url($form_fields, $post) {
- $form_fields["source_url"] = array(
- "label" => __("Source URL"),
- "input" => "text",
- "value" => get_post_meta($post->ID, "source_url", true),
- "helps" => __("Add the URL where the original image was posted"),
- );
- return $form_fields;
- }
- add_filter("attachment_fields_to_save", "save_image_source_url", 10 , 2);
- function save_image_source_url($post, $attachment) {
- if (isset($attachment['source_url']))
- update_post_meta($post['ID'], 'source_url', trim($attachment['source_url']));
- return $post;
- }
- add_filter('img_caption_shortcode', 'caption_shortcode_with_credits', 10, 3);
- function caption_shortcode_with_credits($empty, $attr, $content) {
- extract(shortcode_atts(array(
- 'id' => '',
- 'align' => 'alignnone',
- 'width' => '',
- 'caption' => ''
- ), $attr));
- // Extract attachment $post->ID
- preg_match('/\d+/', $id, $att_id);
- if (is_numeric($att_id[0]) && $source_url = get_post_meta($att_id[0], 'source_url', true)) {
- if (!strstr($source_url, 'http://'))
- $source_url = 'http://' . $source_url;
- $parts = parse_url($source_url);
- $caption .= ' ('. __('via') .' <a href="'. $source_url .'">'. $parts['host'] .'</a>)';
- }
- if ( 1 > (int) $width || empty($caption) )
- return $content;
- if ( $id )
- $id = 'id="' . esc_attr($id) . '" ';
- return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
- . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement