Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: TT Metabox Employees
- Plugin URI:
- Description: Metabox Nuorten Exitin henkilöstön lisäämiseksi etusivulle .
- Version: 1.0
- Author: Topi Tiikkainen
- Author URI:
- License: GPLv2
- */
- function tt_henkilosto(){
- $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
- wp_nonce_field('tt-tallennus', 'tt_nonce_kentta');
- if ($post_id == '12' && is_admin()) {
- add_meta_box("henkilo1", "Henkilo 1", "luo_h1_kentat", "page", "normal", "high");
- add_meta_box("henkilo2", "Henkilo 2", "luo_h2_kentat", "page", "normal", "high");
- add_meta_box("henkilo3", "Henkilo 3", "luo_h3_kentat", "page", "normal", "high");
- add_meta_box("henkilo4", "Henkilo 4", "luo_h4_kentat", "page", "normal", "high");
- }
- }
- add_action( 'add_meta_boxes_page', 'tt_henkilosto' );
- // --- METABOX: CAREER ... CONTENTS --- //
- function luo_h1_kentat(){
- $h1_kentat="";
- $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 ) . '">';
- $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 ) . '">';
- $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 ) . '">';
- echo $h1_kentat;
- }
- function luo_h2_kentat(){
- $h2_kentat="";
- $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 ) . '">';
- $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 ) . '">';
- $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 ) . '">';
- echo $h2_kentat;
- }
- function luo_h3_kentat(){
- $h3_kentat="";
- $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 ) . '">';
- $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 ) . '">';
- $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 ) . '">';
- echo $h3_kentat;
- }
- function luo_h4_kentat(){
- $h4_kentat="";
- $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 ) . '">';
- $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 ) . '">';
- $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 ) . '">';
- echo $h4_kentat;
- }
- add_action( 'save_post', 'tt_tallenna' );
- function tt_tallenna( ) {
- $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
- /*
- * We need to verify this came from our screen and with proper authorization,
- * because the save_post action can be triggered at other times.
- */
- // Check if our nonce is set.
- if ( ! isset( $_POST['tt_nonce_kentta'] ) ) {
- return;
- }
- // Verify that the nonce is valid.
- if ( ! wp_verify_nonce( $_POST['tt_nonce_kentta'], 'tt_henkilosto' ) ) {
- return;
- }
- // If this is an autosave, our form has not been submitted, so we don't want to do anything.
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return;
- }
- // Check the user's permissions.
- if ( get_the_ID() == '12' ) {
- if ( ! current_user_can( 'edit_page', $post_id ) ) {
- return;
- }
- } else {
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- return;
- }
- }
- /* OK, its safe for us to save the data now. */
- // Make sure that it is set.
- if ( ! isset( $_POST['tt_henkilosto'] ) ) {
- return;
- }
- // Sanitize user input.
- $my_h1_nimi = sanitize_text_field( $_POST['h1_nimi'] );
- $my_h1_titteli = sanitize_text_field( $_POST['h1_titteli'] );
- $my_h1_numero = sanitize_text_field( $_POST['h1_numero'] );
- $my_h2_nimi = sanitize_text_field( $_POST['h2_nimi'] );
- $my_h2_titteli = sanitize_text_field( $_POST['h2_titteli'] );
- $my_h2_numero = sanitize_text_field( $_POST['h2_numero'] );
- $my_h3_nimi = sanitize_text_field( $_POST['h3_nimi'] );
- $my_h3_titteli = sanitize_text_field( $_POST['h3_titteli'] );
- $my_h3_numero = sanitize_text_field( $_POST['h3_numero'] );
- $my_h4_nimi = sanitize_text_field( $_POST['h4_nimi'] );
- $my_h4_titteli = sanitize_text_field( $_POST['h4_titteli'] );
- $my_h4_numero = sanitize_text_field( $_POST['h4_numero'] );
- // Update the meta field in the database.
- update_post_meta( $post_id, 'h1_nimi', $my_h1_nimi );
- update_post_meta( $post_id, 'h1_titteli', $my_h1_titteli );
- update_post_meta( $post_id, 'h1_numero', $my_h1_numero );
- update_post_meta( $post_id, 'h2_nimi', $my_h2_nimi );
- update_post_meta( $post_id, 'h2_titteli', $my_h2_titteli );
- update_post_meta( $post_id, 'h2_numero', $my_h2_numero );
- update_post_meta( $post_id, 'h3_nimi', $my_h3_nimi );
- update_post_meta( $post_id, 'h3_titteli', $my_h3_titteli );
- update_post_meta( $post_id, 'h3_numero', $my_h3_numero );
- update_post_meta( $post_id, 'h4_nimi', $my_h4_nimi );
- update_post_meta( $post_id, 'h4_titteli', $my_h4_titteli );
- update_post_meta( $post_id, 'h4_numero', $my_h4_numero );
- }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement