Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
This hook is used for altering the HTML for a file displayed with a file upload field when editing your form.
Usage
add_filter('frm_file_icon', 'frm_file_icon', 10, 2); function frm_file_icon($html, $atts){
Parameters
- $html (string) - The HTML to display
- $atts (array) - Includes 'image' from wp_get_attachment_image and 'media_id'
Examples
Default output
This example will return the HTML the way is it generated by default.
add_filter('frm_file_icon', 'frm_file_icon', 10, 2);
function frm_file_icon($html, $atts){
$image = $atts['image'];
$media_id = $atts['media_id'];
if ( $image && ! preg_match("wp-content/uploads/", $image) ) { //if this is a mime type icon
$attachment = get_post($media_id);
$label = basename($attachment->guid);
$image .= " <span id='frm_media_$media_id' class='frm_upload_label'><a href='". wp_get_attachment_url($media_id) ."'>$label</a></span>";
} else if ( $image ) {
$image = '<a href="'. wp_get_attachment_url($media_id) .'">'. $image .'</a>';
}
return $image;
}
Add label on all files
add_filter('frm_file_icon', 'frm_file_icon', 10, 2);
function frm_file_icon($html, $atts){
$image = $atts['image'];
$media_id = $atts['media_id'];
$attachment = get_post($media_id);
$label = basename($attachment->guid);
//if this is a mime type icon
if ( $image && ! preg_match("wp-content/uploads/", $image) ) {
$image = " <span id='frm_media_$media_id' class='frm_upload_label'><a href='". wp_get_attachment_url($media_id) ."'>$label</a></span>";
} else if ( $image ) {
$image = '<a href="'. wp_get_attachment_url($media_id) .'">'. $image . $label .'</a>';
}
return $image;
}