Skip to content

Instantly share code, notes, and snippets.

@kuipou
Created January 3, 2021 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuipou/6ddd8f713a760367c49337387d7a74e4 to your computer and use it in GitHub Desktop.
Save kuipou/6ddd8f713a760367c49337387d7a74e4 to your computer and use it in GitHub Desktop.
<?php
function paroisse_horaire() {
$labels = array(
'name' => _x( 'Horaires', 'Post Type General Name', 'sgbcards' ),
'singular_name' => _x( 'Horaire', 'Post Type Singular Name', 'sgbcards' ),
'menu_name' => __( 'Horaires', 'sgbcards' ),
'name_admin_bar' => __( 'Horaire', 'sgbcards' ),
'archives' => __( 'Archive d\'Horaire', 'sgbcards' ),
'attributes' => __( 'Item Attributes', 'sgbcards' ),
'parent_item_colon' => __( 'Parent Item:', 'sgbcards' ),
'all_items' => __( 'All Items', 'sgbcards' ),
'add_new_item' => __( 'Ajouter un nouvel horaire', 'sgbcards' ),
'add_new' => __( 'Ajouter un nouvel horaire', 'sgbcards' ),
'new_item' => __( 'Nouvel Horaire', 'sgbcards' ),
'edit_item' => __( 'Editer un Horaire', 'sgbcards' ),
'update_item' => __( 'Modifier un Horaire', 'sgbcards' ),
'view_item' => __( 'Voir', 'sgbcards' ),
'view_items' => __( 'View Items', 'sgbcards' ),
'search_items' => __( 'Rechercher', 'sgbcards' ),
'not_found' => __( 'Introuvable', 'sgbcards' ),
'not_found_in_trash' => __( 'Not found in Trash', 'sgbcards' ),
'featured_image' => __( 'Featured Image', 'sgbcards' ),
'set_featured_image' => __( 'Set featured image', 'sgbcards' ),
'remove_featured_image' => __( 'Remove featured image', 'sgbcards' ),
'use_featured_image' => __( 'Use as featured image', 'sgbcards' ),
'insert_into_item' => __( 'Insert into item', 'sgbcards' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'sgbcards' ),
'items_list' => __( 'Items list', 'sgbcards' ),
'items_list_navigation' => __( 'Items list navigation', 'sgbcards' ),
'filter_items_list' => __( 'Filter items list', 'sgbcards' ),
);
$args = array(
'label' => __( 'Horaire', 'sgbcards' ),
'description' => __( 'Post Type Description', 'sgbcards' ),
'labels' => $labels,
'supports' => array( 'title' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'horaire', $args );
}
add_action( 'init', 'paroisse_horaire', 0 );
add_action( 'cmb2_init', 'paroisse_horraire_add_meta' );
function paroisse_horraire_add_meta() {
$prefix = '_horaire_';
$mass = new_cmb2_box( array(
'id' => $prefix . 'metabox2',
'title' => __( 'Messe', 'cmb2' ),
'object_types' => array( 'horaire' ),
'context' => 'normal',
'priority' => 'default',
) );
$mass_check = $mass->add_field( array(
'name' => __( 'Est-ce une messe?', 'cmb2' ),
'id' => $prefix . 'mass_check',
'type' => 'checkbox',
) );
$mass_date =$mass->add_field( array(
'name' => __( 'Choisir la date', 'cmb2' ),
'id' => $prefix . 'mass_date',
'type' => 'text_date',
'date_format' => 'Y-m-d',
'attributes' => array(
'data-conditional-id' => $prefix . 'mass_check',),
'data-datepicker' => json_encode( array(
// dayNames: http://api.jqueryui.com/datepicker/#option-dayNames
'dayNames' => array( 'Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi' ),
// monthNamesShort: http://api.jqueryui.com/datepicker/#option-monthNamesShort
'monthNamesShort' => explode( ',', 'En,Feb,Mar,Abr,May,Jun,Jul,Ago,Sep,Oct,Nov,Dic' ),
// yearRange: http://api.jqueryui.com/datepicker/#option-yearRange
// and http://stackoverflow.com/a/13865256/1883421
'yearRange' => '-100:+0',
// Get 1990 through 10 years from now.
// 'yearRange' => '1990:'. ( date( 'Y' ) + 10 ),
) ),
) );
$cmb2Grid = new \Cmb2Grid\Grid\Cmb2Grid( $mass );
$row = $cmb2Grid->addRow();
$row->addColumns( array(
$mass_check, $mass_date
));
$cmb = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => __( 'Horaire', 'cmb2' ),
'object_types' => array( 'horaire' ),
'context' => 'normal',
'priority' => 'default',
) );
$hor_type = $cmb->add_field( array(
'name' => __( 'Type d\'horaire', 'cmb2' ),
'id' => $prefix . 'hor_type',
'type' => 'select',
"default" => "0",
'options' => array(
'0' => __( 'Tout les jours', 'cmb2' ),
'1' => __( 'Periode', 'cmb2' ),
),
) );
$hor_peroide_start = $cmb->add_field( array(
'name' => __( 'Debut', 'cmb2' ),
'id' => $prefix . 'hor_periode_start',
'type' => 'select',
'default' => '1',
'options' => array(
'1' => __( 'Lundi', 'cmb2' ),
'2' => __( 'Mardi', 'cmb2' ),
'3' => __( 'Mercredi', 'cmb2' ),
'4' => __( 'Jeudi', 'cmb2' ),
'5' => __( 'Vendredi', 'cmb2' ),
'6' => __( 'Samedi', 'cmb2' ),
'7' => __( 'Dimanche', 'cmb2' ),
),
'attributes' => array(
'data-conditional-id' => $prefix . 'hor_type',
'data-conditional-value' => '1',
),
) );
$hor_peroide_end = $cmb->add_field( array(
'name' => __( 'Fin', 'cmb2' ),
'id' => $prefix . 'hor_periode_end',
'type' => 'select',
'default' => '1',
'options' => array(
'1' => __( 'Lundi', 'cmb2' ),
'2' => __( 'Mardi', 'cmb2' ),
'3' => __( 'Mercredi', 'cmb2' ),
'4' => __( 'Jeudi', 'cmb2' ),
'5' => __( 'Vendredi', 'cmb2' ),
'6' => __( 'Samedi', 'cmb2' ),
'7' => __( 'Dimanche', 'cmb2' ),
),
'attributes' => array(
'data-conditional-id' => $prefix . 'hor_type',
'data-conditional-value' => '1',
),
) );
$mon_check = $cmb->add_field( array(
'name' => __( 'Ouvert?', 'cmb2' ),
'id' => $prefix . 'mon_check',
'type' => 'select',
'options' => array(
'open' => __( 'Ouvert', 'cmb2' ),
'closed' => __( 'Fermé', 'cmb2' ),
'call' => __( 'Sur appel', 'cmb2' ),
),
'before_row' => '<h1>Lundi</h1>',
) );
$mon_start = $cmb->add_field( array(
'name' => __( "Heure d'ouverture", 'cmb2' ),
'id' => $prefix . 'mon_hour_start',
'type' => 'text_time',
'default' => "10:00",
'attributes' => array(
'data-conditional-id' => $prefix . 'mon_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$mon_end = $cmb->add_field( array(
'name' => __( 'Heure de fermeture', 'cmb2' ),
'id' => $prefix . 'mon_hour_end',
'type' => 'text_time',
'attributes' => array(
'data-conditional-id' => $prefix . 'mon_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$tues_check = $cmb->add_field( array(
'name' => __( 'Ouvert?', 'cmb2' ),
'id' => $prefix . 'tues_check',
'type' => 'select',
'options' => array(
'open' => __( 'Ouvert', 'cmb2' ),
'closed' => __( 'Fermé', 'cmb2' ),
'call' => __( 'Sur appel', 'cmb2' ),
),
'before_row' => '<h1>Mardi</h1>',
) );
$tues_start = $cmb->add_field( array(
'name' => __( "Heure d'ouverture", 'cmb2' ),
'id' => $prefix . 'tues_hour_start',
'type' => 'text_time',
'default' => "10:00",
'attributes' => array(
'data-conditional-id' => $prefix . 'tues_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$tues_end = $cmb->add_field( array(
'name' => __( 'Heure de fermeture', 'cmb2' ),
'id' => $prefix . 'tues_hour_end',
'type' => 'text_time',
'attributes' => array(
'data-conditional-id' => $prefix . 'tues_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$wed_check = $cmb->add_field( array(
'name' => __( 'Ouvert?', 'cmb2' ),
'id' => $prefix . 'wed_check',
'type' => 'select',
'options' => array(
'open' => __( 'Ouvert', 'cmb2' ),
'closed' => __( 'Fermé', 'cmb2' ),
'call' => __( 'Sur appel', 'cmb2' ),
),
'before_row' => '<h1>Mercredi</h1>',
) );
$wed_start = $cmb->add_field( array(
'name' => __( "Heure d'ouverture", 'cmb2' ),
'id' => $prefix . 'wed_hour_start',
'type' => 'text_time',
'default' => "10:00",
'attributes' => array(
'data-conditional-id' => $prefix . 'wed_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$wed_end = $cmb->add_field( array(
'name' => __( 'Heure de fermeture', 'cmb2' ),
'id' => $prefix . 'wed_hour_end',
'type' => 'text_time',
'attributes' => array(
'data-conditional-id' => $prefix . 'wed_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$thurs_check = $cmb->add_field( array(
'name' => __( 'Ouvert?', 'cmb2' ),
'id' => $prefix . 'thurs_check',
'type' => 'select',
'options' => array(
'open' => __( 'Ouvert', 'cmb2' ),
'closed' => __( 'Fermé', 'cmb2' ),
'call' => __( 'Sur appel', 'cmb2' ),
),
'before_row' => '<h1>Jeudi</h1>',
) );
$thurs_start = $cmb->add_field( array(
'name' => __( "Heure d'ouverture", 'cmb2' ),
'id' => $prefix . 'thurs_hour_start',
'type' => 'text_time',
'default' => "10:00",
'attributes' => array(
'data-conditional-id' => $prefix . 'thurs_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$thurs_end = $cmb->add_field( array(
'name' => __( 'Heure de fermeture', 'cmb2' ),
'id' => $prefix . 'thurs_hour_end',
'type' => 'text_time',
'attributes' => array(
'data-conditional-id' => $prefix . 'thurs_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$fri_check = $cmb->add_field( array(
'name' => __( 'Ouvert?', 'cmb2' ),
'id' => $prefix . 'fri_check',
'type' => 'select',
'options' => array(
'open' => __( 'Ouvert', 'cmb2' ),
'closed' => __( 'Fermé', 'cmb2' ),
'call' => __( 'Sur appel', 'cmb2' ),
),
'before_row' => '<h1>Vendredi</h1>',
) );
$fri_start = $cmb->add_field( array(
'name' => __( "Heure d'ouverture", 'cmb2' ),
'id' => $prefix . 'fri_hour_start',
'type' => 'text_time',
'default' => "10:00",
'attributes' => array(
'data-conditional-id' => $prefix . 'fri_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$fri_end = $cmb->add_field( array(
'name' => __( 'Heure de fermeture', 'cmb2' ),
'id' => $prefix . 'fri_hour_end',
'type' => 'text_time',
'attributes' => array(
'data-conditional-id' => $prefix . 'fri_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$sat_check = $cmb->add_field( array(
'name' => __( 'Ouvert?', 'cmb2' ),
'id' => $prefix . 'sat_check',
'type' => 'select',
'options' => array(
'open' => __( 'Ouvert', 'cmb2' ),
'closed' => __( 'Fermé', 'cmb2' ),
'call' => __( 'Sur appel', 'cmb2' ),
),
'before_row' => '<h1>Samedi</h1>',
) );
$sat_start = $cmb->add_field( array(
'name' => __( "Heure d'ouverture", 'cmb2' ),
'id' => $prefix . 'sat_hour_start',
'type' => 'text_time',
'default' => "10:00",
'attributes' => array(
'data-conditional-id' => $prefix . 'sat_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$sat_end = $cmb->add_field( array(
'name' => __( 'Heure de fermeture', 'cmb2' ),
'id' => $prefix . 'sat_hour_end',
'type' => 'text_time',
'attributes' => array(
'data-conditional-id' => $prefix . 'sat_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$sun_check = $cmb->add_field( array(
'name' => __( 'Ouvert?', 'cmb2' ),
'id' => $prefix . 'sun_check',
'type' => 'select',
'options' => array(
'open' => __( 'Ouvert', 'cmb2' ),
'closed' => __( 'Fermé', 'cmb2' ),
'call' => __( 'Sur appel', 'cmb2' ),
),
'before_row' => '<h1>Dimanche</h1>',
) );
$sun_start = $cmb->add_field( array(
'name' => __( "Heure d'ouverture", 'cmb2' ),
'id' => $prefix . 'sun_hour_start',
'type' => 'text_time',
'default' => "10:00",
'attributes' => array(
'data-conditional-id' => $prefix . 'sun_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
$sun_end = $cmb->add_field( array(
'name' => __( 'Heure de fermeture', 'cmb2' ),
'id' => $prefix . 'sun_hour_end',
'type' => 'text_time',
'attributes' => array(
'data-conditional-id' => $prefix . 'sun_check',
'data-conditional-value' => 'open',
'data-timepicker' => json_encode( array(
'timeOnlyTitle' => __( 'Choisir l\'heure', 'cmb2' ),
'timeFormat' => 'HH:mm',)),
),
) );
// Create a default grid.
// $cmb2Grid = new \Cmb2Grid\Grid\Cmb2Grid( $mass );
// $row = $cmb2Grid->addRow();
// $row = addColumns(array($mass_check, $mass_date));
$cmb2Grid = new \Cmb2Grid\Grid\Cmb2Grid( $cmb );
$row = $cmb2Grid->addRow();
$row->addColumns(array($hor_type, $hor_peroide_start, $hor_peroide_end));
$row = $cmb2Grid->addRow();
$row->addColumns(array($mon_check, $mon_start, $mon_end));
$row = $cmb2Grid->addRow();
$row->addColumns(array($tues_check, $tues_start, $tues_end));
$row = $cmb2Grid->addRow();
$row->addColumns(array($wed_check, $tues_start, $wed_end));
$row = $cmb2Grid->addRow();
$row->addColumns(array($thurs_check,$thurs_start, $thurs_end));
$row = $cmb2Grid->addRow();
$row->addColumns(array($fri_check, $fri_start, $fri_end));
$row = $cmb2Grid->addRow();
$row->addColumns(array($sat_check, $sat_start, $sat_end));
$row = $cmb2Grid->addRow();
$row->addColumns(array($sun_check, $sun_start, $sun_end));
}
function the_horaire($id) {
//echo "horaire fired";
$post = get_post($id);
//var_dump($post);
$meta = get_post_meta($id);
$mon_check = get_post_meta( $id, '_horaire_mon_check', true);
$mon_check = get_post_meta( $id, '_horaire_mon_check', true);
//var_dump($meta);
$mon_start = get_post_meta( $id, '_horaire_mon_hour_start', true );
//var_dump($mon_start);
$tues_start = get_post_meta( $id, '_horaire_tues_hour_start', true );
$wed_start = get_post_meta( $id, '_horaire_wed_hour_start', true );
$thurs_start = get_post_meta( $id, '_horaire_thurs_hour_start', true );
$fri_start = get_post_meta( $id, '_horaire_fri_hour_start', true );
$sat_start = get_post_meta( $id, '_horaire_sat_hour_start', true );
$sun_start = get_post_meta( $id, '_horaire_sun_hour_start', true );
$mon_end = get_post_meta( $id, '_horaire_mon_hour_end', true );
$tues_end = get_post_meta( $id, '_horaire_tues_hour_end', true );
$wed_end = get_post_meta( $id, '_horaire_wed_hour_end', true );
$thurs_end = get_post_meta( $id, '_horaire_thurs_hour_end', true );
$fri_end = get_post_meta( $id, '_horaire_fri_hour_end', true );
$sat_end = get_post_meta( $id, '_horaire_sat_hour_end', true );
$sun_end = get_post_meta( $id, '_horaire_sun_hour_end', true );
$output = "<h5>{$post->post_title}</h5><ul>";
if (isset($post->_horaire_mon_check) && $post->_horaire_mon_check === "open") {
$output .= "<li><strong>Lundi:</strong> {$mon_start} - {$_mon_end}</li>";
} else {
$output .= "<li><strong>Lundi:</strong>{$post->_horaire_mon_check}</li>";
}
if (isset($post->_horaire_tues_check)) {
$output .= "<li><strong>Mardi:</strong> {$tues_start} - {$tues_end}</li>";
} else {
$output .= "<li><strong>Mardi:</strong> Fermé</li>";
}
if (isset($post->_horaire_wed_check)) {
$output .= "<li><strong>Mercredi:</strong> {$wed_start} - {$wed_end}</li>";
} else {
$output .= "<li><strong>Mercredi:</strong> Fermé</li>";
}
if (isset($post->_horaire_thurs_check)) {
$output .= "<li><strong>Jeudi:</strong> {$thurs_start} - {$thurs_end}</li>";
} else {
$output .= "<li><strong>Jeudi:</strong> Fermé</li>";
}
if (isset($post->_horaire_fri_check)) {
$output .= "<li><strong>Vendredi:</strong> {$fri_start} - {$fri_end}</li>";
} else {
$output .= "<li><strong>Vendredi:</strong> Fermé</li>";
}
if (isset($post->_horaire_sat_check)) {
$output .= "<li><strong>Samedi:</strong> {$sat_start} - {$sat_end}</li>";
} else {
$output .= "<li><strong>Samedi:</strong> Fermé</li>";
}
if (isset($post->_horaire_sun_check)) {
$output .= "<li><strong>Dimanche:</strong> {$sun_start} - {$sun_end}</li>";
} else {
$output .= "<li><strong>Dimanche:</strong> Fermé</li>";
}
$output .= "</ul>";
echo $output;
}
add_action( 'cmb2_admin_init', 'yourprefix_register_main_options_metabox' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment