1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Save Custom Link URL |
---|
4 | Version: 0.1 |
---|
5 | Plugin URI: http://core.trac.wordpress.org/ticket/13429 |
---|
6 | Description: Allows to specify a custom Link URL for any attachment. |
---|
7 | Author: Sergey Biryukov |
---|
8 | Author URI: http://profiles.wordpress.org/sergeybiryukov/ |
---|
9 | */ |
---|
10 | |
---|
11 | function _save_attachment_url($post, $attachment) { |
---|
12 | if ( isset($attachment['url']) ) |
---|
13 | update_post_meta( $post['ID'], '_wp_attachment_url', esc_url_raw($attachment['url']) ); |
---|
14 | |
---|
15 | return $post; |
---|
16 | } |
---|
17 | add_filter('attachment_fields_to_save', '_save_attachment_url', 10, 2); |
---|
18 | |
---|
19 | function _replace_attachment_url($form_fields, $post) { |
---|
20 | if ( isset($form_fields['url']['html']) ) { |
---|
21 | $url = get_post_meta( $post->ID, '_wp_attachment_url', true ); |
---|
22 | if ( ! empty($url) ) |
---|
23 | $form_fields['url']['html'] = preg_replace( "/value='.*?'/", "value='$url'", $form_fields['url']['html'] ); |
---|
24 | } |
---|
25 | |
---|
26 | return $form_fields; |
---|
27 | } |
---|
28 | add_filter('attachment_fields_to_edit', '_replace_attachment_url', 10, 2); |
---|
29 | ?> |
---|