Set media upload attachment link to none and hide it in WP v3.5

In the Media upload popup page, how do I set the attachment link to none and hide it in WordPress version 3.5? The following filter worked fine in earlier versions of WP:

function my_attachment_fields_edit($form_fields,$post){ 
    // Set attachment link to none and hide it.
    $html = "<input type="hidden" name="attachments[".$post->ID."][url]" value=""/>";

    $form_fields['url']['html'] = $html; //Replace html
    $form_fields['url']['label'] = ''; //Remove label
    $form_fields['url']['helps'] ='';//Remove help text

    return $form_fields;
}
add_filter('attachment_fields_to_edit', 'my_attachment_fields_edit', 10, 2);

This was actually an excellent filter posted by someone here I believe. Do anyone know how to accomplish this in WP 3.5?

2 s
2

Include this small plugin, activate and test.

A tested version in 3.6-alpha, works only on click on a thumbnail.

<?php
/**
 * Plugin Name: Remove Attachment Link-To and set to value 'none' 
 */

add_action( 'admin_footer-post-new.php', 'wpse_76214_script' );
add_action( 'admin_footer-post.php', 'wpse_76214_script' );
function wpse_76214_script() {
    ?>
    <script type="text/javascript">
    jQuery(document).ready( function($) {
        $( 'li.attachment' ).live( 'click', function( event ) {
            $( ".link-to > [value="none"]").attr( "selected", true ); // selected none in select field
            $( ".link-to-custom" ).val( '' ); // clear input field for target of link
            $( '.media-sidebar div.setting' ).remove(); // remove link field
        });
    } );
    </script>
    <?php
}

// filter a-Tag in data, there was send to edit; fallback
add_filter( 'media_send_to_editor', 'wpse_76214_send_to_editor', 10, 3 );
function wpse_76214_send_to_editor( $html, $id, $attachment ) {

    $html = preg_replace( '@\<a([^>]*)>(.*?)\<\/a>@i', '$2', $html );

    return $html;
}

Leave a Comment