Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mb_fichesmat = array(
- 'id' => 'mb_fichesmat',
- 'title' => 'Caractéristiques du matériel',
- 'page' => 'post',
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => array(
- // GENERAL
- array(
- 'titre' => 'CARACTERISTIQUES',
- 'champs' => array(
- 'name' => 'Nom',
- 'desc' => 'Nom du produit',
- 'id' => 'cmb_nom_mat',
- 'type' => 'text'
- ),
- array(
- 'name' => 'Constructeur',
- 'desc' => 'Nom du constructeur',
- 'id' => 'cmb_const_mat',
- 'type' => 'text'
- ),
- array(
- 'name' => 'Dimensions',
- 'desc' => 'Encombrement du produit en mm',
- 'id' => 'cmb_dim_mat',
- 'type' => 'text',
- 'std' => ' mm'
- ),
- array(
- 'name' => 'Poids',
- 'desc' => 'Poids du produit en Kg',
- 'id' => 'cmb_poids_mat',
- 'type' => 'text',
- 'std' => ' Kg'
- ),
- array(
- 'name' => 'Matériau',
- 'desc' => 'Plastique, acier, alu',
- 'id' => 'cmb_mater_mat',
- 'type' => 'multicheck',
- 'options' => array('Plastique', 'Acier', 'Alu', 'MESH', 'Cuivre', 'PVC')
- ),
- array(
- 'name' => 'Couleur',
- 'desc' => 'Noir, rouge, blanc',
- 'id' => 'cmb_color_mat',
- 'type' => 'select',
- 'options' => array('', 'Or', 'Cuivre', 'Argent', 'Metal', 'Alu', 'Bleu', 'Rouge', 'Vert', 'Jaune', 'Orange', 'Noir', 'Blanc', 'Mauve', 'Rose')
- ),
- array(
- 'name' => 'Référence produit',
- 'desc' => 'MEC-DD25-AAC',
- 'id' => 'cmb_ref_mat',
- 'type' => 'text'
- ),
- array(
- 'name' => 'Prix',
- 'desc' => 'Prix',
- 'id' => 'cmb_prix_mat',
- 'type' => 'text',
- 'std' => ' €'
- ),
- array(
- 'name' => 'Lien site officiel',
- 'desc' => 'Entrer l\'url du site officiel',
- 'id' => 'cmb_lien_site_mat',
- 'type' => 'text',
- 'std' => 'http://'
- )
- ),
- // BOITIER
- array(
- 'titre' => 'Section 2',
- 'champs' => array(
- 'name' => 'Type',
- 'desc' => 'desc 2',
- 'id' => 'cmb_typeboit_mat',
- 'type' => 'checkbox',
- 'options' => array( 'ATX', 'mATX', 'EATX', 'ITX', 'Mini ITX' )
- ),
- array(
- 'name' => 'Slots',
- 'desc' => 'desc 2.1',
- 'id' => 'cmb_slotsboit_mat',
- 'type' => 'text'
- ),
- array(
- 'name' => 'Baies 1',
- 'desc' => 'desc 2.3',
- 'id' => 'cmb_intbaiesboit_mat',
- 'type' => 'text'
- ),
- array(
- 'name' => 'Baies 2',
- 'desc' => 'desc 2.4',
- 'id' => 'cmb_extbaieboits_mat',
- 'type' => 'text'
- )
- )
- )
- );
- add_action('admin_menu', 'add_mb_fichesmat');
- function add_mb_fichesmat() {
- global $mb_fichesmat;
- add_meta_box($mb_fichesmat['id'], $mb_fichesmat['title'], 'show_mb_fichesmat', $mb_fichesmat['page'], $mb_fichesmat['context'], $mb_fichesmat['priority']);
- }
- function show_mb_fichesmat() {
- global $mb_fichesmat, $post;
- echo '<input type="hidden" name="add_mb_fichesmat_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
- echo '<div class="form-table"><div id="gd_metabox_wrap">';
- foreach ($mb_fichesmat['fields'] as $fields) {
- echo '<h3>'.$fields['titre'].'</h3>';
- echo '<div class="gd_mb_box">';
- foreach ($fields as $field) {
- $meta = get_post_meta($post->ID, $field['id'], true);
- $multimeta = get_post_meta($post->ID, $field['id'], false);
- $label = '<label for="'.$field['id'].'"><h4>'.$field['name'].'</h4></label>';
- $html_begin = '<div class="gd_metabox_label">'.$label.'<div class="gd_metabox_content"><div class="gd_metabox_desc">'.$field['desc'].'</div>';
- $html_end = '</div></div>';
- switch ($field['type']) {
- case 'checkbox':
- echo $html_begin;
- foreach ($field['options'] as $option => $value) {
- echo '<input type="checkbox" name="'.$field['id'].$value.'" id="'.$field['id'].$value.'" style="display:inline; width: 11px; height: 11px; margin-right: 10px;"', $meta ? ' checked="checked"' : '', ' />'.$value.'<br>';
- }
- echo $html_end;
- break;
- case 'multicheck':
- echo $html_begin;
- $i = 1;
- foreach ($field['options'] as $option => $value) {
- echo '<input style="display:inline; width: 11px; height: 11px; margin-right: 10px;" type="checkbox" name="', $field['id'], '[]" id="', $field['id'], $i, '" value="', $value, '"', in_array( $value, $multimeta ) ? ' checked="checked"' : '', ' />'.$value.'<br>';
- $i++;
- }
- echo $html_end;
- break;
- case 'textarea':
- echo $html_begin.'<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:70%;">', $meta ? $meta : $field['std'], '</textarea>'.$html_end;
- break;
- case 'select':
- echo $html_begin.'<select name="', $field['id'], '" id="', $field['id'], '" style="width:40%">';
- foreach ($field['options'] as $option) {
- echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';
- }
- echo '</select>'.$html_end;
- break;
- case 'text':
- echo $html_begin.'<div class="gd_input"><input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" /></div>'.$html_end;
- break;
- }
- }
- echo '</div>';
- }
- echo '</div></div>';
- }
- //Add Save Action
- add_action('save_post', 'save_mb_fichesmat');
- function save_mb_fichesmat($post_id) {
- global $mb_fichesmat;
- if (!wp_verify_nonce($_POST['add_mb_fichesmat_nonce'], basename(__FILE__))) {
- return $post_id;
- }
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return $post_id;
- }
- if ('page' == $_POST['post_type']) {
- if (!current_user_can('edit_page', $post_id)) {
- return $post_id;
- }
- } elseif (!current_user_can('edit_post', $post_id)) {
- return $post_id;
- }
- foreach ($mb_fichesmat['fields'] as $fields) {
- foreach ( $fields as $field ) {
- $old = get_post_meta($post_id, $field['id'], true);
- $new = $_POST[$field['id']];
- if ($new && $new != $old) {
- update_post_meta($post_id, $field['id'], $new);
- } elseif ('' == $new && $old) {
- delete_post_meta($post_id, $field['id'], $old);
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement