Last active
August 29, 2015 14:11
-
-
Save Benoti/72f7ce5c302863a0bc83 to your computer and use it in GitHub Desktop.
[SNIPPET OF CODE] For cmb2 debugging. Working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$brp_clt_ads ='customer_ads'; //id du custom post | |
global $brp_clt_ads; | |
add_action('init', 'customer_ads_init'); | |
function customer_ads_init() | |
{ | |
global $brp_clt_ads; | |
$labels_settings = array( | |
'name' => 'Annonces', | |
'singular_name' => 'Annonce', | |
'search_items' => 'Rechercher annonce', | |
'all_items' => 'Toutes les annonces', | |
'edit_item' => 'Editer annonce', | |
'update_item' => 'Mettre à jour l\'annonce', | |
'add_new_item' => 'Ajouter nouvelle annonce', | |
'new_item' => 'Nouvelle annonce', | |
'not_found' => 'Aucune annonce trouvée.', | |
); | |
register_post_type($brp_clt_ads, array( | |
'label' => 'Annonces', | |
'labels' => $labels_settings, | |
'singular_label' =>'Annonce', | |
'public' => false, | |
'has_archive' => false, | |
'show_ui' => true, | |
'show_in_menu' => 'rapid-pub-admin', | |
'menu_name' => 'Annonces', | |
'menu_position' => '65', | |
'menu_icon' => 'dashicons-media-code', | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'rewrite' => array('slug' => 'annonces'), | |
'supports' => array('title','post-formats', 'custom-fields' ) | |
)); | |
} | |
$brp_editor_area ='editor_area'; //id du custom post | |
global $brp_editor_area; | |
add_action('init', 'editor_area_init'); | |
function editor_area_init() | |
{ | |
global $brp_editor_area; | |
$labels_settings = array( | |
'name' => 'Types de campagne', | |
'singular_name' => 'Type de campagne', | |
'search_items' => 'Rechercher type de campagne', | |
'all_items' => 'Blocs prédéfinis', | |
'edit_item' => 'Editer type de campagne', | |
'update_item' => 'Mettre à jour type de campagne', | |
'add_new_item' => 'Ajouter un nouveau type de campagne', | |
'new_item' => 'Nouveau type de campagne', | |
'not_found' => 'Aucun type de campagne trouvée.', | |
); | |
register_post_type($brp_editor_area, array( | |
'label' => 'Bloc d\'affichage des campagnes', | |
'labels' => $labels_settings, | |
'singular_label' =>'Type d\'affichage des campagnes', | |
'public' => false, | |
'has_archive' => false, | |
'show_ui' => true, | |
'show_in_menu' => 'rapid-pub-admin', | |
'menu_name' => 'Bloc annonces prédéfinis', | |
'menu_position' => '67', | |
'menu_icon' => 'dashicons-media-code', | |
'capability_type' => 'post', | |
'hierarchical' => true, | |
'rewrite' => array('slug' => 'annonces'), | |
'supports' => array('title','post-formats', 'custom-fields' ) | |
)); | |
} | |
add_filter('cmb2_meta_boxes', 'brp_metaboxes'); | |
function brp_metaboxes( array $meta_boxes ) { | |
$prefix = 'brp_'; // Prefix for all fields | |
$meta_boxes['editor_area'] = array( | |
'id' => 'rapid-pub-settings', | |
'title' => 'Rapid Pub réglages prédinis', | |
'object_types' => array('editor_area'), // Post type | |
'context' => 'normal', | |
'priority' => 'high', | |
'show_names' => true, | |
'fields' => array( | |
array( | |
'name' => 'Instructions', | |
'desc' => 'Set up your own display block.', | |
'type' => 'title', | |
), | |
array( | |
'name' => 'Nom', | |
'desc' => 'Nom de votre bloc', | |
'id' => $prefix.'editor_bloc_name', | |
'type' => 'text_medium' | |
), | |
array( | |
'name' => __( 'Vignette', 'cmb2' ), | |
'desc' => __( 'Téléchargez l\'image qui s\'affichera dans l\'interface utilisateur', 'cmb2' ), | |
'id' => $prefix . 'editor_bloc_thumbnail', | |
'type' => 'file', | |
), | |
array( | |
'name' => 'Dimensions du bloc', | |
'desc' => 'Taille en pixel', | |
'type' => 'title', | |
), | |
array( | |
'name' => 'Hauteur', | |
'desc' => 'hauteur du bloc en pixel', | |
'id' => $prefix.'editor_bloc_height', | |
'type' => 'text_small' | |
), | |
array( | |
'name' => 'Largeur', | |
'desc' => 'largeur du bloc en pixel', | |
'id' => $prefix.'editor_bloc_width', | |
'type' => 'text_small' | |
), | |
array( | |
'name' => 'Dimensions de l\'image', | |
'desc' => 'Taille en pixel', | |
'type' => 'title', | |
), | |
array( | |
'name' => 'Hauteur', | |
'desc' => 'hauteur de l\'image en pixel', | |
'id' => $prefix.'editor_img_height', | |
'type' => 'text_small' | |
), | |
array( | |
'name' => 'Largeur', | |
'desc' => 'largeur de l\'image en pixel', | |
'id' => $prefix.'editor_img_width', | |
'type' => 'text_small' | |
), | |
array( | |
'name' => __( 'Responsive', 'cmb2' ), | |
'desc' => __( 'ce bloc sera diffusé sur toutes les plateformes', 'cmb2' ), | |
'id' => $prefix . 'editor_bloc_is_responsive', | |
'type' => 'select', | |
'options' => array( | |
'true' => __( 'Yes', 'cmb' ), | |
'false' => __( 'No', 'cmb' ), | |
), | |
'default' => 'false', | |
), | |
), | |
); | |
$meta_boxes['customer_ads'] = array( | |
'id' => 'rapid-pub-settings', | |
'title' => 'Rapid Pub réglages annonce', | |
'object_types' => array('customer_ads'), // Post type | |
'context' => 'normal', | |
'priority' => 'high', | |
'show_names' => true, | |
'fields' => array( | |
array( | |
'name' => 'Instructions', | |
'desc' => 'In the form bellow upload a featured image. Make sure this image is at least 245x485px wide. Then fill out the information below.', | |
'type' => 'title', | |
), | |
array( | |
'name' => 'Nom', | |
'desc' => 'Nom de votre bloc annonce', | |
'id' => $prefix.'show_info', | |
'type' => 'text_medium' | |
), | |
array( | |
'name' => __( 'Image annonce', 'cmb2' ), | |
'desc' => __( 'Téléchargez votre visuel', 'cmb2' ), | |
'id' => $prefix . 'ads_image', | |
'type' => 'file', | |
), | |
array( | |
'name' => __( 'Website URL', 'cmb2' ), | |
'desc' => __( 'Liens vers votre page', 'cmb2' ), | |
'id' => $prefix . 'ads_url_link', | |
'type' => 'text_url', | |
'protocols' => array('http', 'https'), // Array of allowed protocols | |
// 'repeatable' => true, | |
), | |
array( | |
'name' => 'Activer le code de suivie', | |
'desc' => 'Active le tracking des liens pour Google Analytics', | |
'id' => $prefix.'analytics_ways', | |
'type' => 'radio', | |
'options' => array( | |
'true' => 'Oui', | |
'false' => 'Non', | |
), | |
), | |
array( | |
'name' => 'Code de suivie', | |
'desc' => 'Indiquez le nom de la campagne pour cette annonce (utm_campaign)', | |
'id' => $prefix.'code_suivi', | |
'type' => 'text' | |
), | |
array( | |
'name' => __( 'Date | Heure départ', 'cmb2' ), | |
'desc' => __( 'votre annonce sera diffusée à partir de la date et de l\'heure indiquée', 'cmb2' ), | |
'id' => $prefix . 'ads_datetime_start', | |
'type' => 'text_datetime_timestamp', | |
), | |
array( | |
'name' => __( 'Date | Heure fin', 'cmb2' ), | |
'desc' => __( 'votre annonce sera stoppée à partir de la date et de l\'heure indiquée', 'cmb2' ), | |
'id' => $prefix . 'ads_datetime_end', | |
'type' => 'text_datetime_timestamp', | |
), | |
array( | |
'name' => __( 'Campaign type', 'cmb' ), | |
'desc' => __( 'Select the campaign type for this ads', 'cmb' ), | |
'id' => $prefix . 'ads_campaign_type', | |
'type' => 'select', | |
'options' => cmb_get_editor_area( array( 'post_type' => 'editor_area', 'numberposts' => 5 ) ), | |
'default' => '' | |
), | |
), | |
); | |
return $meta_boxes; | |
} | |
// CMB2 new field | |
// field-type : campaign_type | |
/** | |
* Gets a number of posts and displays them as options | |
* @param array $query_args Optional. Overrides defaults. | |
* @return array An array of options that matches the CMB options array | |
*/ | |
function cmb_get_editor_area( $query_args ) { | |
$args = wp_parse_args( $query_args, array( | |
'post_type' => 'editor_area', | |
'numberposts' => -1, | |
) ); | |
$posts = get_posts( $args ); | |
$post_options = array(); | |
if ( $posts ) { | |
foreach ( $posts as $post ) { | |
$post_options[] = array( | |
'name' => $post->post_title, | |
'value' => $post->ID | |
); | |
} | |
} | |
return $post_options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment