Make WordPress Core

Ticket #21114: add-link-to-large-image.php

File add-link-to-large-image.php, 1.7 KB (added by SergeyBiryukov, 11 years ago)

In plugin form

Line 
1<?php
2/*
3Plugin Name: Add Link to Large Image in Add Media Window
4Version: 1.0
5Plugin URI: http://core.trac.wordpress.org/ticket/21114
6Description: Allows to insert a link to the large version of the image into post content.
7Author: Robert Staddon, Sergey Biryukov
8*/
9
10function add_link_to_large_image( $form_fields, $post ) {
11        $file = wp_get_attachment_url( $post->ID );
12        $link = get_attachment_link( $post->ID );
13
14        $url_type = get_option( 'image_default_link_type' );
15        if ( empty( $url_type ) )
16                $url_type = get_user_setting( 'urlbutton', 'post' );
17
18        $url = '';
19        if ( $url_type == 'file' )
20                $url = $file;
21        elseif ( $url_type == 'post' )
22                $url = $link;
23
24        if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) {
25                $large_image_array = wp_get_attachment_image_src( $post->ID, 'large' );
26                $file_large = $large_image_array[0];
27                $url = $file_large;
28        }
29
30        $form_fields['url']['html'] = "
31                <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr( $url ) . "' /><br />
32                <button type='button' class='button urlnone' data-link-url=''>" . __( 'None' ) . "</button>
33        ";
34        if ( ! empty( $file_large ) )
35                $form_fields['url']['html'] .= "
36                <button type='button' class='button urlfile' data-link-url='" . esc_attr( $file_large ) . "'>" . __( 'Large Image' ) . "</button>
37        ";
38        $form_fields['url']['html'] .= "
39                <button type='button' class='button urlfile' data-link-url='" . esc_attr( $file ) . "'>" . __( 'File URL' ) . "</button>
40                <button type='button' class='button urlpost' data-link-url='" . esc_attr( $link ) . "'>" . __( 'Attachment Post URL' ) . "</button>
41        ";
42
43        return $form_fields;
44}
45add_filter( 'attachment_fields_to_edit', 'add_link_to_large_image', 10, 2 );
46?>