Advertisement
Guest User

Code

a guest
Mar 10th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. /**
  2. * Show custom fields in post content area
  3. *
  4. * @global object $post
  5. * @param string $content
  6. * @return string
  7. */
  8. function wpuf_show_custom_fields( $content ) {
  9. global $post;
  10.  
  11. $show_custom = wpuf_get_option( 'cf_show_front', 'wpuf_general' );
  12.  
  13. if ( $show_custom != 'on' ) {
  14. return $content;
  15. }
  16.  
  17. $form_id = get_post_meta( $post->ID, '_wpuf_form_id', true );
  18.  
  19. if ( !$form_id ) {
  20. return $content;
  21. }
  22.  
  23. $html = '<ul class="wpuf_customs">';
  24.  
  25. $form_vars = get_post_meta( $form_id, 'wpuf_form', true );
  26. $meta = array();
  27.  
  28. if ( $form_vars ) {
  29. foreach ($form_vars as $attr) {
  30. if ( isset( $attr['is_meta'] ) && $attr['is_meta'] == 'yes' ) {
  31. $meta[] = $attr;
  32. }
  33. }
  34.  
  35. if ( !$meta ) {
  36. return $content;
  37. }
  38.  
  39. foreach ($meta as $attr) {
  40. $field_value = get_post_meta( $post->ID, $attr['name'] );
  41.  
  42. if ( $attr['input_type'] == 'hidden' ) {
  43. continue;
  44. }
  45.  
  46. if ( $attr['input_type'] == 'image_upload' || $attr['input_type'] == 'file_upload' ) {
  47. $image_html = '<li><label>' . $attr['label'] . ':</label> ';
  48.  
  49. if ( $field_value ) {
  50. foreach ($field_value as $attachment_id) {
  51.  
  52. if ( $attr['input_type'] == 'image_upload' ) {
  53. $thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
  54. } else {
  55. $thumb = get_post_field( 'post_title', $attachment_id );
  56. }
  57.  
  58. $full_size = wp_get_attachment_url( $attachment_id );
  59. $image_html .= sprintf( '<a href="%s">%s</a> ', $full_size, $thumb );
  60. }
  61. }
  62.  
  63. $html .= $image_html . '</li>';
  64.  
  65. } elseif ( $attr['input_type'] == 'map' ) {
  66. ob_start();
  67. wpuf_shortcode_map_post($attr['name'], $post->ID);
  68. $html .= ob_get_clean();
  69. } else {
  70.  
  71. $value = get_post_meta( $post->ID, $attr['name'] );
  72. $html .= sprintf( '<li><label>%s</label>: %s</li>', $attr['label'], make_clickable( implode( ', ', $value ) ) );
  73. }
  74. }
  75. }
  76.  
  77. $html .= '</ul>';
  78.  
  79. return $content . $html;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement