Created
March 21, 2013 14:49
-
-
Save tareq1988/5213621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpuf_show_custom_fields( $content ) { | |
global $post; | |
$form_id = get_post_meta( $post->ID, '_wpuf_form_id', true ); | |
if ( !$form_id ) { | |
return $content; | |
} | |
$html = '<ul class="wpuf_customs">'; | |
$form_vars = get_post_meta( $form_id, 'wpuf_form', true ); | |
$meta = array(); | |
if ( $form_vars ) { | |
foreach ($form_vars as $attr) { | |
if ( isset( $attr['is_meta'] ) && $attr['is_meta'] == 'yes' ) { | |
$meta[] = $attr; | |
} | |
} | |
if ( !$meta ) { | |
return $content; | |
} | |
foreach ($meta as $attr) { | |
if ( $attr['input_type'] == 'image_upload' ) { | |
$images = get_post_meta( $post->ID, $attr['name'] ); | |
$image_html = '<li><label>' . $attr['label'] . ':</lable> '; | |
if ( $images ) { | |
foreach ($images as $attachment_id) { | |
$thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' ); | |
$full_size = wp_get_attachment_url( $attachment_id ); | |
$image_html .= sprintf( '<a href="%s">%s</a> ', $full_size, $thumb ); | |
} | |
} | |
$html .= $image_html . '</li>'; | |
} else if ( $attr['input_type'] == 'file_upload' ) { | |
$images = get_post_meta( $post->ID, $attr['name'] ); | |
$image_html = '<li><label>' . $attr['label'] . ':</lable> '; | |
if ( $images ) { | |
foreach ($images as $attachment_id) { | |
$full_size = wp_get_attachment_url( $attachment_id ); | |
$image_html .= sprintf( '<a href="%s">%s</a> ', $full_size, get_post_field( 'post_title', $attachment_id ) ); | |
} | |
} | |
$html .= $image_html . '</li>'; | |
} else { | |
$value = get_post_meta( $post->ID, $attr['name'] ); | |
$html .= sprintf( '<li><label>%s</label>: %s</li>', $attr['label'], implode( ', ', $value ) ); | |
} | |
} | |
} | |
$html .= '</ul>'; | |
return $content . $html; | |
} | |
add_filter( 'the_content' , 'wpuf_show_custom_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"Site is experiencing technical difficulties" after adding this to functions.php