Hopefully it’s OK asking a second question pretty much directly after the first one…
I’m currently having some difficulties accomplishing this:
I’ve been able to remove the ‘Attachment Post URL’ button using
function medium_attachment_fields_to_edit($form_fields) {
$form_fields['url']['html'] = preg_replace("/<button type='button' class='button urlpost' title='(.)*'>(.*)</button>/", "", $form_fields['url']['html']);
return $form_fields;
}
add_filter('attachment_fields_to_edit', 'medium_attachment_fields_to_edit', 0, 2);
but I’m somehow unable to make the remaining buttons into a checkbox. Checked being the ‘File URL’, unchecked being ‘None’. (or changing things into a ‘Yes/No’ set of radio buttons if this would be easier to accomplish)
I’ve read about all articles about this matter of course (especially this one), but they about all seem to be about adding new settings, instead of altering existing ones.
You can just replace the html with a checkbox, ensuring the name of the checkbox is the name of the
<input>
we’re replacing.You can also change the ‘label’ and the ‘help’ text, (see here for there the filter is fired) – just simply uncomment the appropritate lines and replace the text with your own.
The html we are replacing is normally provided by
image_link_input_fields
(see here). Looking into that code we see the name of the input isattachments[$post->ID][url]
– which is the name we give our checkbox, with value the url of the file.The above works perfectly, however, you may have noticed when selecting ‘file url’ or ‘post url’, or ‘none’ that WordPress remembers your choice and uses this as the default for next time. Your choice is stored in the user setting ‘urlbutton’.
Unfortunately this method means that the setting is no longer updated (i.e. you can manually set the setting to ‘file’ or ‘none’, but it won’t behave dynamically as before). I think the reason is that clicking the buttons triggers an AJAX request to update the settings.
What this means is that unless you add some javascript to trigger this, all instances of
$checked
are a bit useless and can be removed.Give the checkbox the same name as the text field and set it’s value to the ‘File URL’ value. Either rename the Link URL text field or remove it. You can remove the buttons.