2020-12-30 21:27:12 +01:00
|
|
|
<?php
|
2020-12-30 19:04:58 +01:00
|
|
|
/* functions.php
|
|
|
|
*
|
2021-01-03 14:00:37 +01:00
|
|
|
* All the function of Kazhnuz.Space
|
2020-12-30 19:04:58 +01:00
|
|
|
*
|
|
|
|
*/
|
2020-12-30 21:27:12 +01:00
|
|
|
|
2020-12-30 19:04:58 +01:00
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
/* 0. Excerpt and thumbnail support
|
|
|
|
*
|
|
|
|
* Ces fonctions ajoutent les fonctionnalités de base du theme,
|
|
|
|
* tel que les extraits et les miniatures.
|
|
|
|
*/
|
2020-12-30 19:04:58 +01:00
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
function kspace_post_supports() {
|
|
|
|
add_post_type_support( 'post', 'excerpt');
|
|
|
|
}
|
2020-12-30 21:27:12 +01:00
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
add_action( 'init', 'kspace_post_supports' );
|
|
|
|
|
|
|
|
add_theme_support( 'post-thumbnails' );
|
2023-03-12 17:28:10 +01:00
|
|
|
set_post_thumbnail_size( 825, 825, true );
|
2021-01-03 14:00:37 +01:00
|
|
|
|
|
|
|
/* 1. Niveau support
|
|
|
|
*
|
|
|
|
* Permet d'afficher les niveaux de post pour les post features
|
|
|
|
*/
|
2020-12-30 19:04:58 +01:00
|
|
|
|
2021-01-03 14:45:01 +01:00
|
|
|
// 1.1 - Enregistrement de la taxonomy pour le flag
|
2020-12-30 19:04:58 +01:00
|
|
|
register_taxonomy(
|
2021-01-03 14:45:01 +01:00
|
|
|
'flag',
|
2020-12-30 19:04:58 +01:00
|
|
|
'post',
|
|
|
|
array(
|
2021-01-03 14:45:01 +01:00
|
|
|
'label' => 'Flag',
|
2020-12-30 19:04:58 +01:00
|
|
|
'labels' => array(
|
2021-01-03 14:45:01 +01:00
|
|
|
'name' => 'Flags',
|
|
|
|
'singular_name' => 'Flag',
|
|
|
|
'all_items' => 'Tous les flags',
|
|
|
|
'edit_item' => 'Éditer le flag',
|
|
|
|
'view_item' => 'Voir le flag',
|
|
|
|
'update_item' => 'Mettre à jour le flag',
|
|
|
|
'add_new_item' => 'Ajouter un flag',
|
|
|
|
'new_item_name' => 'Nouveau flag',
|
|
|
|
'search_items' => 'Rechercher parmi les flags',
|
|
|
|
'popular_items' => 'Flags les plus utilisés'
|
2020-12-30 19:04:58 +01:00
|
|
|
),
|
|
|
|
'hierarchical' => false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2021-01-03 14:45:01 +01:00
|
|
|
register_taxonomy_for_object_type( 'flag', 'post' );
|
|
|
|
|
|
|
|
// 1.2 - Ajout/Modif du niveau du flag
|
|
|
|
function flags_taxonomy_custom_fields($tag) {
|
|
|
|
// Check for existing taxonomy meta for the term you're editing
|
|
|
|
$t_id = $tag->term_id; // Get the ID of the term you're editing
|
|
|
|
$term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check
|
|
|
|
?>
|
|
|
|
|
|
|
|
<tr class="form-field">
|
|
|
|
<th scope="row" valign="top">
|
|
|
|
<label for="niveau"><?php _e('Niveau du flag'); ?></label>
|
|
|
|
</th>
|
|
|
|
<td>
|
|
|
|
<input type="text" name="term_meta[niveau]" id="term_meta[niveau]" size="25" style="width:60%;" value="<?php echo $term_meta['niveau'] ? $term_meta['niveau'] : ''; ?>"><br />
|
|
|
|
<span class="description"><?php _e('Le niveau du flag (info, warning, danger…)'); ?></span>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
function flags_taxonomy_custom_fields_add( $taxonomy ) {
|
|
|
|
// Check for existing taxonomy meta for the term you're editing
|
|
|
|
$t_id = $tag->term_id; // Get the ID of the term you're editing
|
|
|
|
$term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check
|
|
|
|
?>
|
|
|
|
|
|
|
|
<div class="form-field">
|
|
|
|
<label for="term_meta[niveau]"><?php _e('Niveau du flag'); ?></label>
|
|
|
|
<input type="text" name="term_meta[niveau]" id="term_meta[niveau]" />
|
|
|
|
<p><?php _e('Le niveau du flag (info, warning, danger…)'); ?>.</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'post_tag_edit_form_fields', 'kspace_edit_term_fields', 10, 2 );
|
|
|
|
|
|
|
|
// 1.3 - Sauvegarde du niveau du flag
|
|
|
|
function save_taxonomy_custom_fields( $term_id ) {
|
|
|
|
if ( isset( $_POST['term_meta'] ) ) {
|
|
|
|
$t_id = $term_id;
|
|
|
|
$term_meta = get_option( "taxonomy_term_$t_id" );
|
|
|
|
$cat_keys = array_keys( $_POST['term_meta'] );
|
|
|
|
foreach ( $cat_keys as $key ){
|
|
|
|
if ( isset( $_POST['term_meta'][$key] ) ){
|
|
|
|
$term_meta[$key] = $_POST['term_meta'][$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//save the option array
|
|
|
|
update_option( "taxonomy_term_$t_id", $term_meta );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ajout des fields
|
|
|
|
add_action( 'flag_edit_form_fields', 'flags_taxonomy_custom_fields', 10, 2 );
|
|
|
|
add_action( 'flag_add_form_fields', 'flags_taxonomy_custom_fields_add' );
|
|
|
|
add_action( 'created_flag', 'save_taxonomy_custom_fields' );
|
|
|
|
add_action( 'edited_flag', 'save_taxonomy_custom_fields', 10, 2 );
|
2020-12-30 19:04:58 +01:00
|
|
|
|
2022-11-23 19:40:47 +01:00
|
|
|
|
|
|
|
function kspace_cat_breadcrumb_nav($categoryName, $icon) {
|
|
|
|
?>
|
|
|
|
<nav aria-label="breadcrumb">
|
|
|
|
<ol class="breadcrumb">
|
|
|
|
<li class="breadcrumb-item"><a href="<?php echo site_url(); ?>">kazhnuz.space</a>
|
|
|
|
</li><li class="breadcrumb-item" aria-current="page">
|
|
|
|
<span class="active"><i class="fa fa-<?php echo $icon; ?>" aria-hidden="true"></i> <?php echo $categoryName; ?></span>
|
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
</nav>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
function kspace_cat_breadcrumb($categoryName, $icon) {
|
|
|
|
?>
|
2023-05-20 10:02:10 +02:00
|
|
|
<div class="flex-that d-none d-flex-sm pr-half pl-half">
|
2022-11-23 19:40:47 +01:00
|
|
|
<?php kspace_cat_breadcrumb_nav($categoryName, $icon); ?>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
function kspace_cat_breadcrumb_with_rss($categoryName, $icon, $categoryType, $rssLink) {
|
|
|
|
?>
|
2023-05-20 10:02:10 +02:00
|
|
|
<div class="flex-that d-none d-flex-sm pr-half pl-half">
|
2022-11-23 19:40:47 +01:00
|
|
|
<?php kspace_cat_breadcrumb_nav($categoryName, $icon); ?>
|
|
|
|
<div class="rss">
|
2023-05-20 10:02:10 +02:00
|
|
|
<a href="<?php echo $rssLink; ?>" class="btn btn-warning d-block m-0" /><i class="fa fa-rss" aria-hidden="true"></i><span class="sr-only">Flux RSS de <?php echo $categoryType; ?></span></a>
|
2022-11-23 19:40:47 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
/* 3. Plus d'info sur les tags
|
|
|
|
*
|
|
|
|
* Permet d'afficher un lien vers plus d'informations.
|
|
|
|
* Le liens est gardé comme un champ supplémentaire dans les tags.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-12-31 11:53:45 +01:00
|
|
|
add_action( 'post_tag_add_form_fields', 'kspace_add_term_fields' );
|
|
|
|
|
|
|
|
function kspace_add_term_fields( $taxonomy ) {
|
|
|
|
echo '<div class="form-field">
|
2021-01-03 14:00:37 +01:00
|
|
|
<label for="plus-dinfo">Plus d\'Info</label>
|
2020-12-31 11:53:45 +01:00
|
|
|
<input type="text" name="plus-dinfo" id="plus-dinfo" />
|
|
|
|
<p>Une URL permettant d\'obtenir plus d\'information sur le tag.</p>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
add_action( 'post_tag_edit_form_fields', 'kspace_edit_term_fields', 10, 2 );
|
2020-12-31 11:53:45 +01:00
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
function kspace_edit_term_fields( $term, $taxonomy ) {
|
2020-12-31 11:53:45 +01:00
|
|
|
|
|
|
|
$value = get_term_meta( $term->term_id, 'plus-dinfo', true );
|
|
|
|
|
|
|
|
echo '<tr class="form-field">
|
|
|
|
<th>
|
2021-01-03 14:00:37 +01:00
|
|
|
<label for="plus-dinfo">Plus d\'Info</label>
|
2020-12-31 11:53:45 +01:00
|
|
|
</th>
|
|
|
|
<td>
|
|
|
|
<input name="plus-dinfo" id="plus-dinfo" type="text" value="' . esc_attr( $value ) .'" />
|
|
|
|
<p class="description">Une URL permettant d\'obtenir plus d\'information sur le tag.</p>
|
|
|
|
</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
add_action( 'created_post_tag', 'kspace_save_term_fields' );
|
|
|
|
add_action( 'edited_post_tag', 'kspace_save_term_fields' );
|
2020-12-31 11:53:45 +01:00
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
function kspace_save_term_fields( $term_id ) {
|
2020-12-31 11:53:45 +01:00
|
|
|
|
|
|
|
update_term_meta(
|
|
|
|
$term_id,
|
|
|
|
'plus-dinfo',
|
|
|
|
sanitize_text_field( $_POST[ 'plus-dinfo' ] )
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2021-01-03 11:40:57 +01:00
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
/* 3. Info supplémentaire sur profil utilisateur
|
|
|
|
*
|
|
|
|
* Permet d'afficher sous forme de chaine de caractères des infos supplémentaires qui seront
|
|
|
|
* transformé en un tableau..
|
|
|
|
*
|
|
|
|
*/
|
2021-01-03 11:40:57 +01:00
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
add_action( 'show_user_profile', 'kspace_show_extra_profile_fields' );
|
|
|
|
add_action( 'edit_user_profile', 'kspace_show_extra_profile_fields' );
|
2021-01-03 11:40:57 +01:00
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
function kspace_show_extra_profile_fields( $user ) {
|
2021-01-03 11:40:57 +01:00
|
|
|
$year = get_the_author_meta( 'infodata', $user->ID );
|
|
|
|
?>
|
2021-01-03 14:00:37 +01:00
|
|
|
<h3><?php esc_html_e( 'More Info', 'kspace' ); ?></h3>
|
2021-01-03 11:40:57 +01:00
|
|
|
|
|
|
|
<table class="form-table">
|
|
|
|
<tr>
|
2021-01-03 14:00:37 +01:00
|
|
|
<th><label for="infodata"><?php esc_html_e( 'infodata', 'kspace' ); ?></label></th>
|
2021-01-03 11:40:57 +01:00
|
|
|
<td>
|
|
|
|
<input type="input"
|
|
|
|
id="infodata"
|
|
|
|
name="infodata"
|
|
|
|
value="<?php echo esc_attr( $year ); ?>"
|
|
|
|
class="regular-text"
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
add_action( 'personal_options_update', 'kspace_update_profile_fields' );
|
|
|
|
add_action( 'edit_user_profile_update', 'kspace_update_profile_fields' );
|
2021-01-03 11:40:57 +01:00
|
|
|
|
2021-01-03 14:00:37 +01:00
|
|
|
function kspace_update_profile_fields( $user_id ) {
|
2021-01-03 11:40:57 +01:00
|
|
|
if ( ! current_user_can( 'edit_user', $user_id ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
update_user_meta( $user_id, 'infodata', $_POST['infodata'] );
|
|
|
|
}
|
2021-01-04 13:05:09 +01:00
|
|
|
|
|
|
|
/* 4. Romans
|
|
|
|
*
|
|
|
|
* Permet de catégoriser des chapitres ensemble, via une catégorie spécifiques.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
register_taxonomy('roman', 'post',
|
|
|
|
array(
|
|
|
|
'label' => 'Roman',
|
|
|
|
'labels' => array(
|
|
|
|
'name' => 'Romans',
|
|
|
|
'singular_name' => 'Roman',
|
|
|
|
'all_items' => 'Tous les romans',
|
|
|
|
'edit_item' => 'Éditer le roman',
|
|
|
|
'view_item' => 'Voir le roman',
|
|
|
|
'update_item' => 'Mettre à jour le roman',
|
|
|
|
'add_new_item' => 'Ajouter un roman',
|
|
|
|
'new_item_name' => 'Nouveau roman',
|
|
|
|
'search_items' => 'Rechercher parmi les romans',
|
|
|
|
'popular_items' => 'Romans les plus utilisés'),
|
|
|
|
'rewrite' => array('slug' => 'roman'),
|
|
|
|
'hierarchical' => false,
|
|
|
|
'public' => true,
|
|
|
|
'hierarchical' => true,
|
|
|
|
'show_in_nav_menus' => true,
|
|
|
|
'has_archive' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
register_taxonomy_for_object_type( 'roman', 'post' );
|
|
|
|
|
|
|
|
// 1.2 - Ajout/Modif du niveau du flag
|
|
|
|
function romans_taxonomy_custom_fields($tag) {
|
|
|
|
// Check for existing taxonomy meta for the term you're editing
|
|
|
|
$t_id = $tag->term_id; // Get the ID of the term you're editing
|
|
|
|
$term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check
|
|
|
|
?>
|
|
|
|
|
|
|
|
<tr class="form-field">
|
|
|
|
<th scope="row" valign="top">
|
|
|
|
<label for="niveau"><?php _e('Couverture du roman'); ?></label>
|
|
|
|
</th>
|
|
|
|
<td>
|
|
|
|
<input type="text" name="term_meta[cover]" id="term_meta[cover]" size="25" style="width:60%;" value="<?php echo $term_meta['cover'] ? $term_meta['cover'] : ''; ?>"><br />
|
|
|
|
<span class="description"><?php _e('La couverture du roman, sous format URL'); ?></span>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
function romans_taxonomy_custom_fields_add( $taxonomy ) {
|
|
|
|
// Check for existing taxonomy meta for the term you're editing
|
|
|
|
$t_id = $tag->term_id; // Get the ID of the term you're editing
|
|
|
|
$term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check
|
|
|
|
?>
|
|
|
|
|
|
|
|
<div class="form-field">
|
|
|
|
<label for="term_meta[cover]"><?php _e('Couverture du roman'); ?></label>
|
|
|
|
<input type="text" name="term_meta[cover]" id="term_meta[cover]" />
|
|
|
|
<p><?php _e('La couverture du roman, sous format URL)'); ?>.</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ajout des fields
|
|
|
|
add_action( 'roman_edit_form_fields', 'romans_taxonomy_custom_fields', 10, 2 );
|
|
|
|
add_action( 'roman_add_form_fields', 'romans_taxonomy_custom_fields_add' );
|
|
|
|
add_action( 'created_roman', 'save_taxonomy_custom_fields' );
|
|
|
|
add_action( 'edited_roman', 'save_taxonomy_custom_fields', 10, 2 );
|
2021-01-24 14:52:23 +01:00
|
|
|
|
|
|
|
/* 4. Menus custom
|
|
|
|
*
|
|
|
|
* Quelques menus custom
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function wpb_custom_new_menu() {
|
|
|
|
register_nav_menus(
|
|
|
|
array(
|
2022-12-08 13:46:17 +01:00
|
|
|
'top-navbar' => __( 'Navbar (gauche)' ),
|
|
|
|
'top-navbar-2' => __( 'Navbar (droite)' ),
|
|
|
|
'link-menu' => __( 'Liste des liens' ),
|
|
|
|
'footer-pages' => __( 'Pages dans le footer' ),
|
2022-12-18 19:19:04 +01:00
|
|
|
'social' => __( 'Reseaux sociaux' ),
|
|
|
|
'social-plus' => __( 'Reseaux sociaux supplémentaires' ),
|
2021-01-24 14:52:23 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
add_action( 'init', 'wpb_custom_new_menu' );
|
2023-03-12 16:26:45 +01:00
|
|
|
|
|
|
|
//estimated reading time
|
|
|
|
function reading_time() {
|
|
|
|
$content = get_post_field( 'post_content', $post->ID );
|
|
|
|
$word_count = str_word_count( strip_tags( $content ) );
|
|
|
|
$readingtime = ceil($word_count / 200);
|
|
|
|
|
|
|
|
if ($readingtime == 1) {
|
|
|
|
$timer = " minute";
|
|
|
|
} else {
|
|
|
|
$timer = " minutes";
|
|
|
|
}
|
|
|
|
$totalreadingtime = $readingtime . $timer;
|
|
|
|
|
|
|
|
return $totalreadingtime;
|
|
|
|
}
|