Advertisement
Guest User

Untitled

a guest
Oct 30th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.02 KB | None | 0 0
  1. <?php
  2. // --- METABOX CREATE --- //
  3. //add_action('admin_init', 'page_spec_meta');
  4. add_action( 'load-post.php', 'page_spec_meta' );
  5. function page_spec_meta(){
  6.  
  7. $post_id = (isset($_GET['post'])) ? $_GET['post'] : $_POST['post_ID'] ;
  8. $template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
  9.  
  10. if ($template_file == 'talenten.php')
  11. {
  12. add_meta_box("career-meta", "Career", "career_meta", "page", "normal", "high");
  13. add_meta_box("business-meta", "Business", "business_meta", "page", "normal", "high");
  14. add_meta_box("inspired-meta", "inspired", "inspired_meta", "page", "normal", "high");
  15. add_meta_box("network-meta", "Network", "network_meta", "page", "normal", "high");
  16. add_meta_box("future-meta", "Future", "future_meta", "page", "normal", "high");
  17. add_action( 'save_post', 'save_custom_meta');
  18.  
  19. }
  20. if ($template_file == 'bedrijven.php')
  21. {
  22. add_meta_box("unique-meta", "Unique", "unique_meta", "page", "normal", "high");
  23. add_meta_box("providing-meta", "Providing", "providing_meta", "page", "normal", "high");
  24. add_meta_box("inspired-meta", "inspired", "inspired_meta", "page", "normal", "high");
  25. add_meta_box("network-meta", "Network", "network_meta", "page", "normal", "high");
  26. add_meta_box("future-meta", "Future", "future_meta", "page", "normal", "high");
  27. add_action( 'save_post', 'save_custom_meta');
  28. }
  29. }
  30.  
  31. // --- METABOX: CAREER ... CONTENTS --- //
  32. function career_meta($object){
  33.  
  34.  
  35. $career1 = get_post_meta( $object->ID, 'career1', true );
  36. $career2 = get_post_meta( $object->ID, 'career2', true );
  37. $career3 = get_post_meta( $object->ID, 'career3', true );
  38. ?>
  39. <label for="career1">Subtitel</label><input type="text" class="widefat" id="career1" name="career1" value="<?php echo $career1; ?>" />
  40. <label for="career2">Textveld Links</label>
  41. <textarea id="career2" name="career2"><?php echo $career2; ?></textarea>
  42. <label for="career3">Textveld Rechts</label>
  43. <textarea id="career3" name="career3"><?php echo $career3; ?></textarea>
  44. <input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
  45. <?php }
  46.  
  47.  
  48.  
  49. // --- METABOX: BUSINESS ... CONTENTS --- //
  50. function business_meta($object){
  51.  
  52. $business1 = get_post_meta( $object->ID, 'business1', true );
  53. $business2 = get_post_meta( $object->ID, 'business2', true );
  54. $business3 = get_post_meta( $object->ID, 'business3', true );
  55. $business4 = get_post_meta( $object->ID, 'business4', true );
  56. $business5 = get_post_meta( $object->ID, 'business5', true );
  57. $business6 = get_post_meta( $object->ID, 'business6', true );
  58. ?>
  59. <label for="business1">Subtitel</label><input type="text" class="widefat" id="business1" name="business1" value="<?php echo $business1; ?>" />
  60. <label for="business2">Textveld Links</label>
  61. <textarea id="business2" name="business2"><?php echo $business2; ?></textarea>
  62. <label for="business3">Textveld Rechts</label>
  63. <textarea id="business3" name="business3"><?php echo $business3; ?></textarea>
  64. <label for="business4">Textveld Links</label>
  65. <textarea id="business4" name="business4"><?php echo $business4; ?></textarea>
  66. <label for="business5">Textveld Rechts</label>
  67. <textarea id="business5" name="business5"><?php echo $business5; ?></textarea>
  68. <label for="business6">Textveld Links</label>
  69. <textarea id="business6" name="business6"><?php echo $business6; ?></textarea>
  70. <input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
  71. <?php }
  72.  
  73.  
  74.  
  75. // --- METABOX: INSPIRED ... CONTENTS --- //
  76. function inspired_meta($object){
  77. $inspired1 = get_post_meta( $object->ID, 'inspired1', true );
  78. $inspired2 = get_post_meta( $object->ID, 'inspired2', true );
  79. ?>
  80. <label for="inspired1">Subtitel</label><input type="text" class="widefat" id="inspired1" name="inspired1" value="<?php echo $inspired1; ?>" />
  81. <label for="inspired2">Textveld Links</label>
  82. <textarea id="inspired2" name="inspired2"><?php echo $inspired2; ?></textarea>
  83. <input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
  84. <?php }
  85.  
  86.  
  87.  
  88. // --- METABOX: NETWORK ... CONTENTS --- //
  89. function network_meta($object){
  90. $network1 = get_post_meta( $object->ID, 'network1', true );
  91. $network2 = get_post_meta( $object->ID, 'network2', true );
  92. ?>
  93. <label for="network1">Subtitel</label><input type="text" class="widefat" id="network1" name="network1" value="<?php echo $network1; ?>" />
  94. <label for="network2">Textveld Links</label>
  95. <textarea id="network2" name="network2"><?php echo $network2; ?></textarea>
  96. <input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
  97. <?php }
  98.  
  99.  
  100.  
  101. // --- METABOX: FUTURE ... CONTENTS --- //
  102. function future_meta($object){
  103. $future1 = get_post_meta( $object->ID, 'future1', true );
  104. $future2 = get_post_meta( $object->ID, 'future2', true );
  105. ?>
  106. <label for="future1">Subtitel</label><input type="text" class="widefat" id="future1" name="future1" value="<?php echo $future1; ?>" />
  107. <label for="future2">Textveld Links</label>
  108. <textarea id="future2" name="future2"><?php echo $future2; ?></textarea>
  109. <input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
  110. <?php }
  111.  
  112.  
  113.  
  114. // --- METABOX: UNIQUE ... CONTENTS --- //
  115. function unique_meta($object){
  116. $unique1 = get_post_meta( $object->ID, 'unique1', true );
  117. $unique2 = get_post_meta( $object->ID, 'unique2', true );
  118. ?>
  119. <label for="unique1">Subtitel</label><input type="text" class="widefat" id="unique1" name="unique1" value="<?php echo $unique1; ?>" />
  120. <label for="unique2">Textveld Links</label>
  121. <textarea id="unique2" name="unique2"><?php echo $unique2; ?></textarea>
  122. <input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
  123. <?php }
  124.  
  125. // --- METABOX: PROVIDING ... CONTENTS --- //
  126. function providing_meta($object){
  127. $providing1 = get_post_meta( $object->ID, 'providing1', true );
  128. $providing2 = get_post_meta( $object->ID, 'providing2', true );
  129. $providing3 = get_post_meta( $object->ID, 'providing3', true );
  130. $providing4 = get_post_meta( $object->ID, 'providing4', true );
  131. ?>
  132. <label for="providing1">Subtitel</label><input type="text" class="widefat" id="providing1" name="providing1" value="<?php echo $providing1; ?>" />
  133. <label for="providing2">Textveld Links</label>
  134. <textarea id="providing2" name="providing2"><?php echo $providing2; ?></textarea>
  135. <label for="providing3">Textveld Rechts</label>
  136. <textarea id="providing3" name="providing3"><?php echo $providing3; ?></textarea>
  137. <label for="providing4">Textveld Links</label>
  138. <textarea id="providing4" name="providing4"><?php echo $providing4; ?></textarea>
  139. <input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
  140. <?php }
  141.  
  142.  
  143. // Save the Data
  144. function save_custom_meta($post_id) {
  145. $custom_meta_fields = array(
  146. 'career1','career2','career3',
  147. 'business1','business2','business3','business4','business5','business6',
  148. 'inspired1','inspired2',
  149. 'network1','network2',
  150. 'future1','future2',
  151. 'unique1','unique2',
  152. 'providing1','providing2','providing3','providing4'
  153. );
  154.  
  155. //echo $_POST['my_meta_box_nonce'];
  156. // verify nonce
  157. if (!wp_verify_nonce($_POST['my_meta_box_nonce'], 'my_meta_box'))
  158. return $post_id;
  159. // check autosave
  160. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
  161. return $post_id;
  162. // check permissions
  163.  
  164. if ('page' == $_POST['post_type']) {
  165.  
  166. if (!current_user_can('edit_page', $post_id))
  167. return $post_id;
  168. } elseif (!current_user_can('edit_post', $post_id)) {
  169. return $post_id;
  170. }
  171.  
  172. // loop through fields and save the data
  173. foreach ($custom_meta_fields as $field) {
  174.  
  175. if(isset($_POST[$field])) {
  176. $old = get_post_meta($post_id, $field, true);
  177. $new = $_POST[$field];
  178. if ($new && $new != $old) {
  179. update_post_meta($post_id, $field, $new);
  180. } elseif ('' == $new && $old) {
  181. delete_post_meta($post_id, $field, $old);
  182. }
  183. }
  184. } // end foreach
  185. }
  186. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement