Guest User

Untitled

a guest
Oct 9th, 2014
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. function hhs_repeatable_meta_box_display()
  2. {
  3. global $post;
  4.  
  5. $repeatable_fields = get_post_meta($post->ID, 'repeatable_fields', true);
  6.  
  7. wp_nonce_field('hhs_repeatable_meta_box_nonce', 'hhs_repeatable_meta_box_nonce');
  8. ?>
  9. <script type="text/javascript">
  10. jQuery(document).ready(function ($) {
  11. $('#add-row').on('click', function () {
  12. var row = $('.empty-row.screen-reader-text').clone(true);
  13. row.removeClass('empty-row screen-reader-text');
  14. row.insertBefore('#repeatable-fieldset-one tbody>tr:last');
  15. return false;
  16. });
  17.  
  18. $('.remove-row').on('click', function () {
  19. $(this).parents('tr').remove();
  20. return false;
  21. });
  22. });
  23. </script>
  24.  
  25. <table id="repeatable-fieldset-one" width="100%">
  26. <thead>
  27. <tr>
  28. <th width="25%">Name</th>
  29. <th width="10%">Date</th>
  30. <th width="40%">Text</th>
  31. <th width="25%">Image</th>
  32. </tr>
  33. </thead>
  34. <tbody>
  35.  
  36. <?php $meta = get_post_meta($post->ID, $repeatable_fields['image'], true); ?>
  37. <?php
  38.  
  39. if ($repeatable_fields) :
  40.  
  41. foreach ($repeatable_fields as $field) {
  42. ?>
  43.  
  44. <!-- FRONT - EDITABLE -->
  45. <tr>
  46. <td><input type="text" class="widefat" name="name[]"
  47. value="<?php if ($field['name'] != '') echo esc_attr($field['name']); ?>"/></td>
  48.  
  49.  
  50. <td><input type="text" class="widefat" name="date[]"
  51. value="<?php if ($field['date'] != '') echo esc_attr($field['date']); ?>"/></td>
  52.  
  53. <td><input type="text" class="widefat" name="text[]"
  54. value="<?php if ($field['text'] != '') echo esc_attr($field['text']); ?>"/></td>
  55.  
  56. <td>
  57.  
  58. <?php
  59. if ($meta) { $image = wp_get_attachment_image_src($meta, 'medium'); $image = $image[0]; }
  60.  
  61. ?>
  62. <input type="hidden" class="custom_upload_image" name="image[]"
  63.  
  64. value="<?php if ($field['image'] != '') echo esc_attr($field['image']); ?>"/>
  65.  
  66. <img src=" <?php echo $image ?> " class="custom_preview_image" alt="" /><br /> <!-- BROKEN IMAGE (temp fix "echo") -->
  67.  
  68. <input class="custom_upload_image_button button" type="button" value="Choose Image" />
  69.  
  70. <small> <a href="#" class="custom_clear_image_button">Remove Image</a></small></td>
  71.  
  72. <td><a class="button remove-row" href="#">Remove</a></td>
  73. </tr>
  74.  
  75. <?php
  76.  
  77. }
  78. else :
  79. // BLANK ONE
  80. ?>
  81. <tr>
  82. <td><input type="text" class="widefat" name="name[]"/></td>
  83.  
  84. <td><input type="text" class="widefat" name="date[]"/></td>
  85.  
  86. <td><input type="text" class="widefat" name="text[]"/></td>
  87.  
  88.  
  89. <td>
  90.  
  91. <?php
  92. $image = get_template_directory_uri().'/images/image.png';
  93. echo '<span class="custom_default_image" style="display:none">'.$image.'</span>';
  94. if ($meta) { $image = wp_get_attachment_image_src($meta, 'medium'); $image = $image[0]; }
  95.  
  96. ?>
  97. <input type="hidden" class="custom_upload_image" name="image[]"/>
  98.  
  99. <img src=" <?php echo $image ?> " class="custom_preview_image" alt="" /><br /> <!-- BROKEN IMAGE (temp fix "echo") -->
  100.  
  101. <input class="custom_upload_image_button button" type="button" value="Choose Image" />
  102.  
  103. <small> <a href="#" class="custom_clear_image_button">Remove Image</a></small></td>
  104.  
  105. <td><a class="button remove-row" href="#">Remove</a></td>
  106.  
  107.  
  108. </tr>
  109. <?php endif; ?>
  110.  
  111. <!-- empty hidden one for jQuery
  112. LOAD THIS ONE IN !
  113. -->
  114.  
  115. <tr class="empty-row screen-reader-text">
  116. <td><input type="text" class="widefat" name="name[]"/></td>
  117.  
  118. <td><input type="text" class="widefat" name="date[]"/></td>
  119.  
  120. <td><input type="textarea" class="widefat" name="text[]"/></td>
  121.  
  122. <td>
  123.  
  124. <?php
  125. $image = get_template_directory_uri().'/images/image.png';
  126. echo '<span class="custom_default_image" style="display:none">'.$image.'</span>';
  127. if ($meta) { $image = wp_get_attachment_image_src($meta, 'medium'); $image = $image[0]; }
  128.  
  129. ?>
  130. <input type="hidden" class="custom_upload_image" name="image[]"
  131.  
  132. value="<?php if ($field['image'] != '') echo esc_attr($field['image']); ?>"/>
  133.  
  134.  
  135.  
  136. <img src=" <?php echo $image ?> " class="custom_preview_image" alt="" /><br /> <!-- BROKEN IMAGE (temp fix "echo") -->
  137.  
  138. <input class="custom_upload_image_button button" type="button" value="Choose Image" />
  139.  
  140. <small> <a href="#" class="custom_clear_image_button">Remove Image</a></small></td>
  141.  
  142.  
  143. <td><a class="button remove-row" href="#">Remove</a></td>
  144. </tr>
  145. </tbody>
  146. </table>
  147.  
  148. <p><a id="add-row" class="button" href="#">Add another</a></p>
  149. <?php
  150. }
Advertisement
Add Comment
Please, Sign In to add comment