";
- $html .= "
". $measure->post_excerpt ." Lire la mesure
";
+ $html .= "
";
$html .= "
". $status->description . "
";
$html .= "
" . $measure->post_content . "
";
$html .= "
Mise à jour le " . $date . "
";
@@ -113,29 +117,29 @@ function generate_home_status_graph() {
// calculer le pourcentage sur le total de mesures
// créer un bloc html avec l data correspondante
- $cats = ["validated", "partially-validated", "discussed", "danger", "rejected", "undiscussed"];
+ $stats = ["validated", "partially-validated", "discussed", "danger", "rejected", "undiscussed"];
$obj_total = 0;
$html = "";
- foreach ($cats as $cat) {
+ foreach ($stats as $stat) {
- $cat = get_category_by_slug($cat);
- $color = get_field('couleur', "category_" . $cat->term_id);
- $percent = $cat->count * 100 / $total;
+ $stat = get_term_by('slug', $stat, 'post-status');
+ $color = get_field('couleur', "category_" . $stat->term_id);
+ $percent = $stat->count * 100 / $total;
$html .= "
";
- $html .= "
" . $cat->name . "
";
+ $html .= "
" . $stat->name . "
";
$html .= "
";
$html .= "
";
$html .= "
";
$html .= "
";
- $html .= "
" . $cat->count . "
";
+ $html .= "
" . $stat->count . "
";
$html .= "
";
- if (in_array($cat->slug, ['validated', 'partially-validated'])) {
- $obj_total += $cat->count;
+ if (in_array($stat->slug, ['validated', 'partially-validated'])) {
+ $obj_total += $stat->count;
}
}
@@ -156,6 +160,260 @@ function generate_home_status_graph() {
add_shortcode('graph_mesures', 'generate_home_status_graph');
+if ( ! function_exists( 'status_taxonomy' ) ) {
+
+// Création de la taxonomie "statuts"
+ function status_taxonomy() {
+
+ $labels = array(
+ 'name' => 'Statuts',
+ 'singular_name' => 'Statut',
+ 'menu_name' => 'Statut',
+ 'all_items' => 'Tous les statuts',
+ 'parent_item' => 'Statut parent',
+ 'parent_item_colon' => 'Statut parent :',
+ 'new_item_name' => 'Nom du nouveau statut',
+ 'add_new_item' => 'Ajouter un statut',
+ 'edit_item' => 'Modifier le statut',
+ 'update_item' => 'Mettre à jour le statut',
+ 'view_item' => 'Voir le statut',
+ 'separate_items_with_commas' => 'Séparer les statuts par une virugle',
+ 'add_or_remove_items' => 'Ajouter ou supprimer des statuts',
+ 'choose_from_most_used' => 'Choisir parmis les statuts les plus utilisés',
+ 'popular_items' => 'Statuts les plus fréquents',
+ 'search_items' => 'Chercher parmi les statuts',
+ 'not_found' => 'Introuvable',
+ 'no_terms' => 'Aucun statut',
+ 'items_list' => 'Liste des statuts',
+ 'items_list_navigation' => 'Navigation de la liste de statuts',
+ );
+ $args = array(
+ 'labels' => $labels,
+ 'hierarchical' => false,
+ 'public' => true,
+ 'show_ui' => true,
+ 'show_admin_column' => true,
+ 'show_in_nav_menus' => true,
+ 'show_tagcloud' => true,
+ );
+ register_taxonomy( 'post-status', array( 'post' ), $args );
+
+ }
+ add_action( 'init', 'status_taxonomy', 0 );
+
+}
+
+/**
+ * On continue le foutoir du function.php avant refactoring
+ * ENREGISTREMENT DES PROPOSITIONS DE MISE À JOUR
+ */
+
+// Sur le papier c'est simple : on attribue au commentaire un au ID de post référent juste avant son enregistrement
+function filter_sf_comment_referer( $comment_data ) {
+
+ // On vérifie que le champ ACF soit bien présent
+ if (isset($_POST['acf']['field_6026cfd4eaefc'])) {
+ // si oui on change l'ID de rattachement du commentaire
+ $comment_data['comment_post_ID'] = $_POST['acf']['field_6026cfd4eaefc'];
+ }
+
+ return $comment_data;
+}
+
+add_filter( 'preprocess_comment' , 'filter_sf_comment_referer', 10, 1);
+
+// En pratique on se retrouve à devoir aussi modifier l'affichage du form des commentaires
+
+add_filter( 'comment_form_default_fields', 'custom_comment_form_fields', 10 );
+
+function custom_comment_form_fields( $fields ) {
+
+ // variables névéssaires à la suite
+ $req = get_option( 'require_name_email' );
+ $commenter = wp_get_current_commenter();
+ $html_req = ( $req ? " required='required'" : '' );
+
+ // le champ nom, on change juste le label
+ $fields['author'] =
+ sprintf('',
+ sprintf( '
', 'Prénom et initiale du nom', ( $req ? '
*' : '' ) ),
+ sprintf( '
',
+ esc_attr( $commenter['comment_author'] ),
+ $html_req
+ )
+ );
+
+ //on vire l'url qui sert à rien
+ unset($fields['url']);
+
+ return $fields;
+}
+
+// On change quelques mentions
+
+add_filter('comment_form_defaults', 'custom_comment_form_labels', 10);
+
+function custom_comment_form_labels ($defaults) {
+ //Modification du titre
+ $defaults['title_reply'] = "Proposer la mise à jour d'une mesure.";
+ //Et du sous titre
+ $defaults['comment_notes_before'] = "Votre adresse e-mail ne sera pas publiée et gardée uniquement le temps de traiter votre proposition.
Les champs obligatoires sont indiqués avec *";
+
+ return $defaults;
+}
+
+// Et la rediction
+
+function sf_comment_redirect( $location ) {
+ $location = get_page_uri(740);
+
+ return $location;
+}
+
+add_filter( 'comment_post_redirect', 'sf_comment_redirect' );
+
+// Enfin on ajoute un petit quelque chose aux commentaires vide pour les accepter quand même
+
+function sf_accept_empty_comment($post_id, $author=null, $email=null) {
+ $comment = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
+ if (!$comment) {
+ $_POST['comment'] = "N/A";
+ }
+}
+add_action('pre_comment_on_post', 'sf_accept_empty_comment');
+// Enfin on gère l'affichage
+function sf_comment_template( $comment, $args, $depth ) {
+
+ ?>
+
+
+
+
+
+
+
+
+ 'div-comment',
+ 'depth' => $depth,
+ 'max_depth' => $args['max_depth'],
+ 'before' => '',
+ )
+ )
+ );
+
+ $by_post_author = twentytwenty_is_comment_by_post_author( $comment );
+
+ if ( $comment_reply_link || $by_post_author ) {
+ ?>
+
+
+
+
+
+
+
+
+ +
+ +