406 lines
13 KiB
PHP
406 lines
13 KiB
PHP
<?php
|
|
|
|
/*******************************************
|
|
****** Inclusions de scripts et styles ****
|
|
*******************************************/
|
|
/**
|
|
** activation theme parent
|
|
**/
|
|
add_action( 'wp_enqueue_scripts', 'enqueue_style_parent' );
|
|
function enqueue_style_parent() {
|
|
wp_enqueue_style( 'child-style', get_template_directory_uri() . '/style.css' );
|
|
}
|
|
|
|
/**
|
|
** Ajout des scripts et styles tardifs
|
|
**/
|
|
add_action('wp_enqueue_scripts', 'enqueue_scripts_child', 20);
|
|
function enqueue_scripts_child() {
|
|
wp_register_script('customJS', get_stylesheet_directory_uri() . '/custom.js', array('jquery'),'1.1', true);
|
|
wp_enqueue_script('customJS');
|
|
wp_enqueue_style('dashicons');
|
|
//wp_enqueue_style( 'responsive-child', get_stylesheet_directory_uri() . '/path/to/file.css' );
|
|
}
|
|
|
|
|
|
/**
|
|
** Ajout du code HTML pour les stats
|
|
**/
|
|
function add_stats_html() {
|
|
?>
|
|
<!-- Matomo -->
|
|
<script type="text/javascript">
|
|
var _paq = window._paq || [];
|
|
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
|
|
_paq.push([function() {
|
|
var self = this;
|
|
function getOriginalVisitorCookieTimeout() {
|
|
var now = new Date(),
|
|
nowTs = Math.round(now.getTime() / 1000),
|
|
visitorInfo = self.getVisitorInfo();
|
|
var createTs = parseInt(visitorInfo[2]);
|
|
var cookieTimeout = 33696000; // 13 mois en secondes
|
|
var originalTimeout = createTs + cookieTimeout - nowTs;
|
|
return originalTimeout;
|
|
}
|
|
this.setVisitorCookieTimeout( getOriginalVisitorCookieTimeout() );
|
|
}]);
|
|
|
|
_paq.push(['trackPageView']);
|
|
_paq.push(['enableLinkTracking']);
|
|
(function() {
|
|
var u="//stats.marcha.pro/";
|
|
_paq.push(['setTrackerUrl', u+'matomo.php']);
|
|
_paq.push(['setSiteId', '2']);
|
|
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
|
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
|
|
})();
|
|
</script>
|
|
<noscript><p><img src="//stats.marcha.pro/matomo.php?idsite=2&rec=1" style="border:0;" alt="" /></p></noscript>
|
|
<!-- End Matomo Code -->
|
|
<?php
|
|
}
|
|
add_action('wp_head', 'add_stats_html');
|
|
|
|
/**
|
|
* changement du terme "articles" par "mesures"
|
|
*/
|
|
add_action( 'init', 'cp_change_post_object' );
|
|
|
|
function cp_change_post_object() {
|
|
$get_post_type = get_post_type_object('post');
|
|
$labels = $get_post_type->labels;
|
|
$labels->name = 'Mesures';
|
|
$labels->singular_name = 'Mesure';
|
|
$labels->add_new = 'Ajouter une mesure';
|
|
$labels->add_new_item = 'Ajouter une mesure';
|
|
$labels->edit_item = 'Modifier la mesure';
|
|
$labels->new_item = 'Nouvelle mesure';
|
|
$labels->view_item = 'Voir la mesure';
|
|
$labels->search_items = 'Chercher dans les mesures';
|
|
$labels->not_found = 'Aucune mesure trouvée';
|
|
$labels->not_found_in_trash = 'Aucune mesure dans la corbeille';
|
|
$labels->all_items = 'Toutes les mesures';
|
|
$labels->menu_name = 'Mesures';
|
|
$labels->name_admin_bar = 'Mesure';
|
|
}
|
|
|
|
|
|
/**
|
|
* Suppression de la metabox catégories
|
|
*/
|
|
|
|
function ccc_remove_metaboxes() {
|
|
remove_meta_box( 'categorydiv', 'post', 'normal' );
|
|
}
|
|
|
|
add_action( 'admin_menu', 'ccc_remove_metaboxes' );
|
|
|
|
|
|
/**
|
|
* Shortcode affichant la liste des mesures
|
|
*/
|
|
|
|
function generate_home_posts_list() {
|
|
// On récupère la liste des mesures par date de MaJ décroissante
|
|
$measures = get_posts([ 'post_type' => 'post',
|
|
'orderby' => 'modified',
|
|
'order' => 'DESC',
|
|
'numberposts' => -1
|
|
]);
|
|
|
|
// Conteneur pour les filtres
|
|
$html = "<div id='filters-container' class='filters-container'></div>";
|
|
// input pour la recherche
|
|
$html .= "<div class='search-container'><input id='measure-search' type='text' name='filters-search' placeholder='Rechercher'><button type='reset' id='measure-search-reset'><span class='dashicons dashicons-no-alt'></span></button> </div>";
|
|
|
|
$html .= '<div id="measures-container">';
|
|
foreach ($measures as $measure) {
|
|
$status = get_the_terms($measure->ID, 'post-status')[0];
|
|
$color = get_field('couleur', 'category_'.$status->term_id);
|
|
$link = get_field('proposition-url', $measure->ID);
|
|
$date = get_the_modified_date("d/m/Y à H:i", $measure);
|
|
$cats = wp_get_object_terms($measure->ID, 'category', ['orderby'=>'parent', 'fields'=>'id=>name']);
|
|
|
|
$html .= "<article class='measure-wrapper ".$status->slug." ". implode(' ',array_keys($cats)) ."' style='border-color: $color'>";
|
|
$html .= "<h3 class='measure-title' style='background-color: $color'>". $measure->post_title ."</h3>";
|
|
$html .= "<div class='measure-content'>";
|
|
$html .= "<div class='measure-meta' style='background-color: $color'>
|
|
<p class='measure-meta-categories'>" . implode(' > ', $cats) . "</p>
|
|
<p class='measure-meta-desc'>". $measure->post_excerpt ." <a href='$link' target='_blank' class='external'>Lire la mesure</a></p>
|
|
</div>";
|
|
$html .= "<div class='status-desc' style='background-color: $color'><p>". $status->description . "</p></div>";
|
|
$html .= "<div class='content'>" . $measure->post_content . "</div>";
|
|
$html .= "<p class='measure-meta' style='background-color: $color'>Mise à jour le " . $date . "<br /> ";
|
|
$html .= "</div></article>";
|
|
$html .= "<hr />";
|
|
}
|
|
|
|
$html .= '</div>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
add_shortcode('mesures', 'generate_home_posts_list');
|
|
|
|
|
|
|
|
|
|
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('<p class="comment-form-author">%s %s</p>',
|
|
sprintf( '<label for="author">%s%s</label>', 'Prénom et initiale du nom', ( $req ? ' <span class="required">*</span>' : '' ) ),
|
|
sprintf( '<input id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />',
|
|
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.<br /> 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 ) {
|
|
|
|
?>
|
|
|
|
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
|
|
|
|
<footer class="comment-meta">
|
|
<div class="comment-author vcard">
|
|
<?php
|
|
$comment_author_url = get_comment_author_url( $comment );
|
|
$comment_author = get_comment_author( $comment );
|
|
$avatar = get_avatar( $comment, $args['avatar_size'] );
|
|
if ( 0 !== $args['avatar_size'] ) {
|
|
if ( empty( $comment_author_url ) ) {
|
|
echo wp_kses_post( $avatar );
|
|
} else {
|
|
printf( '<a href="%s" rel="external nofollow" class="url">', $comment_author_url ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped --Escaped in https://developer.wordpress.org/reference/functions/get_comment_author_url/
|
|
echo wp_kses_post( $avatar );
|
|
}
|
|
}
|
|
|
|
printf(
|
|
'<span class="fn">%1$s</span><span class="screen-reader-text says">%2$s</span>',
|
|
esc_html( $comment_author ),
|
|
__( 'says:', 'twentytwenty' )
|
|
);
|
|
|
|
if ( ! empty( $comment_author_url ) ) {
|
|
echo '</a>';
|
|
}
|
|
?>
|
|
</div><!-- .comment-author -->
|
|
<div class="comment-metadata">
|
|
<?php
|
|
/* translators: 1: Comment date, 2: Comment time. */
|
|
$comment_timestamp = sprintf( __( '%1$s at %2$s', 'twentytwenty' ), get_comment_date( '', $comment ), get_comment_time() );
|
|
|
|
printf(
|
|
'<a href="%s"><time datetime="%s" title="%s">%s</time></a>',
|
|
esc_url( get_comment_link( $comment, $args ) ),
|
|
get_comment_time( 'c' ),
|
|
esc_attr( $comment_timestamp ),
|
|
esc_html( $comment_timestamp )
|
|
);
|
|
|
|
if ( get_edit_comment_link() ) {
|
|
printf(
|
|
' <span aria-hidden="true">•</span> <a class="comment-edit-link" href="%s">%s</a>',
|
|
esc_url( get_edit_comment_link() ),
|
|
__( 'Edit', 'twentytwenty' )
|
|
);
|
|
}
|
|
?>
|
|
</div><!-- .comment-metadata -->
|
|
|
|
</footer><!-- .comment-meta -->
|
|
|
|
<div class="comment-content entry-content">
|
|
|
|
<?php if( get_field('sf_maj_statut', $comment) ): ?>
|
|
|
|
<p class="sf-comment-status">Statut : <?php echo get_term_by('term_taxonomy_id', get_field('sf_maj_statut', $comment))->name; ?></p>
|
|
|
|
<?php endif; ?>
|
|
<?php if( get_field('sf_maj_texte_officiel', $comment) ): ?>
|
|
|
|
<p class="sf_comment_texte_officiel">Référence : <?php the_field('sf_maj_texte_officiel', $comment); ?></p>
|
|
|
|
<?php endif; ?>
|
|
<?php if( get_field('sf_maj_source', $comment) ): ?>
|
|
|
|
<p class="sf_comment_source"><a target="_blank" href="<?php the_field('sf_maj_source', $comment); ?>">Source</a></p>
|
|
|
|
<?php endif; ?>
|
|
|
|
<p>Commentaire :</p>
|
|
<?php
|
|
|
|
comment_text();
|
|
|
|
if ( '0' === $comment->comment_approved ) {
|
|
?>
|
|
<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwenty' ); ?></p>
|
|
<?php
|
|
}
|
|
|
|
?>
|
|
|
|
</div><!-- .comment-content -->
|
|
|
|
|
|
<?php
|
|
|
|
$comment_reply_link = get_comment_reply_link(
|
|
array_merge(
|
|
$args,
|
|
array(
|
|
'add_below' => 'div-comment',
|
|
'depth' => $depth,
|
|
'max_depth' => $args['max_depth'],
|
|
'before' => '<span class="comment-reply">',
|
|
'after' => '</span>',
|
|
)
|
|
)
|
|
);
|
|
|
|
$by_post_author = twentytwenty_is_comment_by_post_author( $comment );
|
|
|
|
if ( $comment_reply_link || $by_post_author ) {
|
|
?>
|
|
|
|
<footer class="comment-footer-meta">
|
|
|
|
<?php
|
|
if ( $comment_reply_link ) {
|
|
echo $comment_reply_link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Link is escaped in https://developer.wordpress.org/reference/functions/get_comment_reply_link/
|
|
}
|
|
if ( $by_post_author ) {
|
|
echo '<span class="by-post-author">' . __( 'By Post Author', 'twentytwenty' ) . '</span>';
|
|
}
|
|
?>
|
|
|
|
</footer>
|
|
|
|
<?php
|
|
}
|
|
?>
|
|
|
|
</article><!-- .comment-body -->
|
|
<hr />
|
|
<?php
|
|
}
|