Advertisement
Guest User

Exit Meta box

a guest
Apr 14th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.98 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: TT Metabox Employees
  4. Plugin URI:  
  5. Description: Metabox Nuorten Exitin henkilöstön lisäämiseksi etusivulle .
  6. Version:     1.0
  7. Author:      Topi Tiikkainen
  8. Author URI:  
  9. License:     GPLv2
  10. */
  11.  
  12.  
  13. function tt_henkilosto(){
  14.    
  15.    
  16.     $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
  17.     wp_nonce_field('tt-tallennus', 'tt_nonce_kentta');
  18.     if ($post_id == '12' && is_admin()) {
  19.         add_meta_box("henkilo1", "Henkilo 1", "luo_h1_kentat", "page", "normal", "high");
  20.         add_meta_box("henkilo2", "Henkilo 2", "luo_h2_kentat", "page", "normal", "high");
  21.         add_meta_box("henkilo3", "Henkilo 3", "luo_h3_kentat", "page", "normal", "high");
  22.         add_meta_box("henkilo4", "Henkilo 4", "luo_h4_kentat", "page", "normal", "high");
  23.         }
  24.  }
  25. add_action( 'add_meta_boxes_page', 'tt_henkilosto' );
  26.  
  27.  
  28. // --- METABOX: CAREER ... CONTENTS --- //
  29. function luo_h1_kentat(){
  30. $h1_kentat="";
  31.     $h1_kentat = '<label for="h1_nimi">Nimi</label><input type="text" class="henkilosto_kentta" id="h1_nimi" name="h1_nimi" value="' . get_post_meta( $post_id, 'h1_nimi', true ) . '">';
  32.     $h1_kentat .= '<label for="h1_titteli">Titteli</label><input type="text" class="henkilosto_kentta" id="h1_titteli" name="h1_titteli" value="' . get_post_meta( $post_id, 'h1_titteli', true ) . '">';
  33.     $h1_kentat .= '<label for="h1_numero">Numero</label><input type="text" class="henkilosto_kentta" id="h1_numero" name="h1_numero" value="' . get_post_meta( $post_id, 'h1_numero', true ) . '">';
  34. echo $h1_kentat;
  35.     }
  36. function luo_h2_kentat(){
  37.  
  38. $h2_kentat="";
  39.     $h2_kentat = '<label for="h2_nimi">Nimi</label><input type="text" class="henkilosto_kentta" id="h2_nimi" name="h2_nimi" value="' . get_post_meta( $post->ID, 'h2_nimi', true ) . '">';
  40.     $h2_kentat .= '<label for="h2_titteli">Titteli</label><input type="text" class="henkilosto_kentta" id="h2_titteli" name="h2_titteli" value="' . get_post_meta( $post->ID, 'h2_titteli', true ) . '">';
  41.     $h2_kentat .= '<label for="h2_numero">Numero</label><input type="text" class="henkilosto_kentta" id="h2_numero" name="h2_numero" value="' . get_post_meta( $post->ID, 'h2_numero', true ) . '">';
  42. echo $h2_kentat;
  43. }
  44. function luo_h3_kentat(){
  45. $h3_kentat="";
  46.     $h3_kentat = '<label for="h3_nimi">Nimi</label><input type="text" class="henkilosto_kentta" id="h3_nimi" name="h3_nimi" value="' . get_post_meta( $post->ID, 'h3_nimi', true ) . '">';
  47.     $h3_kentat .= '<label for="h3_titteli">Titteli</label><input type="text" class="henkilosto_kentta" id="h3_titteli" name="h3_titteli" value="' . get_post_meta( $post->ID, 'h3_titteli', true ) . '">';
  48.     $h3_kentat .= '<label for="h3_numero">Numero</label><input type="text" class="henkilosto_kentta" id="h3_numero" name="h3_numero" value="' . get_post_meta( $post->ID, 'h3_numero', true ) . '">';
  49. echo $h3_kentat;
  50.     }
  51. function luo_h4_kentat(){
  52. $h4_kentat="";
  53.     $h4_kentat = '<label for="h4_nimi">Nimi</label><input type="text" class="henkilosto_kentta" id="h4_nimi" name="h4_nimi" value="' . get_post_meta( $post->ID, 'h4_nimi', true ) . '">';
  54.     $h4_kentat .= '<label for="h4_titteli">Titteli</label><input type="text" class="henkilosto_kentta" id="h4_titteli" name="h4_titteli" value="' . get_post_meta( $post->ID, 'h4_titteli', true ) . '">';
  55.     $h4_kentat .= '<label for="h4_numero">Numero</label><input type="text" class="henkilosto_kentta" id="h4_numero" name="h4_numero" value="' . get_post_meta( $post->ID, 'h4_numero', true ) . '">';
  56. echo $h4_kentat;
  57.     }
  58.  
  59.  
  60.  
  61.  
  62. add_action( 'save_post', 'tt_tallenna' );
  63.  
  64. function tt_tallenna( ) {
  65.     $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
  66.     /*
  67.      * We need to verify this came from our screen and with proper authorization,
  68.      * because the save_post action can be triggered at other times.
  69.      */
  70.  
  71.     // Check if our nonce is set.
  72.    
  73.     if ( ! isset( $_POST['tt_nonce_kentta'] ) ) {
  74.         return;
  75.     }
  76.  
  77.     // Verify that the nonce is valid.
  78.     if ( ! wp_verify_nonce( $_POST['tt_nonce_kentta'], 'tt_henkilosto' ) ) {
  79.         return;
  80.     }
  81.  
  82.     // If this is an autosave, our form has not been submitted, so we don't want to do anything.
  83.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  84.         return;
  85.     }
  86.  
  87.     // Check the user's permissions.
  88.     if ( get_the_ID() == '12' ) {
  89.  
  90.         if ( ! current_user_can( 'edit_page', $post_id ) ) {
  91.             return;
  92.         }
  93.  
  94.     } else {
  95.  
  96.         if ( ! current_user_can( 'edit_post', $post_id ) ) {
  97.             return;
  98.         }
  99.     }
  100.  
  101.     /* OK, its safe for us to save the data now. */
  102.    
  103.     // Make sure that it is set.
  104.     if ( ! isset( $_POST['tt_henkilosto'] ) ) {
  105.         return;
  106.     }
  107.  
  108.     // Sanitize user input.
  109.     $my_h1_nimi = sanitize_text_field( $_POST['h1_nimi'] );
  110.     $my_h1_titteli = sanitize_text_field( $_POST['h1_titteli'] );  
  111.     $my_h1_numero = sanitize_text_field( $_POST['h1_numero'] );
  112.    
  113.     $my_h2_nimi = sanitize_text_field( $_POST['h2_nimi'] );
  114.     $my_h2_titteli = sanitize_text_field( $_POST['h2_titteli'] );  
  115.     $my_h2_numero = sanitize_text_field( $_POST['h2_numero'] );
  116.    
  117.     $my_h3_nimi = sanitize_text_field( $_POST['h3_nimi'] );
  118.     $my_h3_titteli = sanitize_text_field( $_POST['h3_titteli'] );  
  119.     $my_h3_numero = sanitize_text_field( $_POST['h3_numero'] );
  120.    
  121.     $my_h4_nimi = sanitize_text_field( $_POST['h4_nimi'] );
  122.     $my_h4_titteli = sanitize_text_field( $_POST['h4_titteli'] );  
  123.     $my_h4_numero = sanitize_text_field( $_POST['h4_numero'] );
  124.    
  125.     // Update the meta field in the database.
  126.     update_post_meta( $post_id, 'h1_nimi', $my_h1_nimi );
  127.     update_post_meta( $post_id, 'h1_titteli', $my_h1_titteli );
  128.     update_post_meta( $post_id, 'h1_numero', $my_h1_numero );
  129.    
  130.     update_post_meta( $post_id, 'h2_nimi', $my_h2_nimi );
  131.     update_post_meta( $post_id, 'h2_titteli', $my_h2_titteli );
  132.     update_post_meta( $post_id, 'h2_numero', $my_h2_numero );
  133.    
  134.     update_post_meta( $post_id, 'h3_nimi', $my_h3_nimi );
  135.     update_post_meta( $post_id, 'h3_titteli', $my_h3_titteli );
  136.     update_post_meta( $post_id, 'h3_numero', $my_h3_numero );
  137.    
  138.     update_post_meta( $post_id, 'h4_nimi', $my_h4_nimi );
  139.     update_post_meta( $post_id, 'h4_titteli', $my_h4_titteli );
  140.     update_post_meta( $post_id, 'h4_numero', $my_h4_numero );
  141. }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement