From 3b1e2eca064b57e4d9f274dd36e6047b64a58506 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 20 May 2023 11:36:03 +0200 Subject: [PATCH] chore: split functions.php --- functions.php | 349 ++--------------------------- functions/breadcrumb.php | 40 ++++ functions/flags.php | 91 ++++++++ functions/posts-support.php | 20 ++ functions/profile-extra-fields.php | 42 ++++ functions/reading-time.php | 23 ++ functions/romans.php | 73 ++++++ functions/tags-moreinfo.php | 50 +++++ 8 files changed, 359 insertions(+), 329 deletions(-) create mode 100644 functions/breadcrumb.php create mode 100644 functions/flags.php create mode 100644 functions/posts-support.php create mode 100644 functions/profile-extra-fields.php create mode 100644 functions/reading-time.php create mode 100644 functions/romans.php create mode 100644 functions/tags-moreinfo.php diff --git a/functions.php b/functions.php index c9e557b..b645043 100644 --- a/functions.php +++ b/functions.php @@ -5,336 +5,27 @@ * */ +include(TEMPLATEPATH . '/functions/posts-support.php'); +include(TEMPLATEPATH . '/functions/flags.php'); +include(TEMPLATEPATH . '/functions/breadcrumb.php'); +include(TEMPLATEPATH . '/functions/tags-moreinfo.php'); +include(TEMPLATEPATH . '/functions/profile-extra-fields.php'); +include(TEMPLATEPATH . '/functions/romans.php'); +include(TEMPLATEPATH . '/functions/reading-time.php'); - /* 0. Excerpt and thumbnail support - * - * Ces fonctions ajoutent les fonctionnalités de base du theme, - * tel que les extraits et les miniatures. - */ - - function kspace_post_supports() { - add_post_type_support( 'post', 'excerpt'); - } - - add_action( 'init', 'kspace_post_supports' ); - - add_theme_support( 'post-thumbnails' ); - set_post_thumbnail_size( 825, 825, true ); - -/* 1. Niveau support - * - * Permet d'afficher les niveaux de post pour les post features - */ - -// 1.1 - Enregistrement de la taxonomy pour le flag -register_taxonomy( - 'flag', - 'post', - array( - 'label' => 'Flag', - 'labels' => array( - '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' - ), - 'hierarchical' => false - ) -); - -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 -?> - - - - - - -
- - - - - __( 'Navbar (gauche)' ), + 'top-navbar-2' => __( 'Navbar (droite)' ), + 'link-menu' => __( 'Liste des liens' ), + 'footer-pages' => __( 'Pages dans le footer' ), + 'social' => __( 'Reseaux sociaux' ), + 'social-plus' => __( 'Reseaux sociaux supplémentaires' ), + ) + ); } - -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 -?> - -
- - -

.

-
- - - - -
- -
- -
- - -
- - - -

Une URL permettant d\'obtenir plus d\'information sur le tag.

- '; -} - -add_action( 'post_tag_edit_form_fields', 'kspace_edit_term_fields', 10, 2 ); - -function kspace_edit_term_fields( $term, $taxonomy ) { - - $value = get_term_meta( $term->term_id, 'plus-dinfo', true ); - - echo ' - - - - - -

Une URL permettant d\'obtenir plus d\'information sur le tag.

- - '; -} - -add_action( 'created_post_tag', 'kspace_save_term_fields' ); -add_action( 'edited_post_tag', 'kspace_save_term_fields' ); - -function kspace_save_term_fields( $term_id ) { - - update_term_meta( - $term_id, - 'plus-dinfo', - sanitize_text_field( $_POST[ 'plus-dinfo' ] ) - ); - -} - -/* 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.. - * - */ - -add_action( 'show_user_profile', 'kspace_show_extra_profile_fields' ); -add_action( 'edit_user_profile', 'kspace_show_extra_profile_fields' ); - -function kspace_show_extra_profile_fields( $user ) { - $year = get_the_author_meta( 'infodata', $user->ID ); - ?> -

- - - - - - -
- -
- '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 - ?> - - - - - - -
- - - - - term_id; // Get the ID of the term you're editing - $term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check - ?> - -
- - -

.

-
- - __( 'Navbar (gauche)' ), - 'top-navbar-2' => __( 'Navbar (droite)' ), - 'link-menu' => __( 'Liste des liens' ), - 'footer-pages' => __( 'Pages dans le footer' ), - 'social' => __( 'Reseaux sociaux' ), - 'social-plus' => __( 'Reseaux sociaux supplémentaires' ), - ) - ); - } - add_action( 'init', 'wpb_custom_new_menu' ); +add_action( 'init', 'wpb_custom_new_menu' ); //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; -} \ No newline at end of file +?> \ No newline at end of file diff --git a/functions/breadcrumb.php b/functions/breadcrumb.php new file mode 100644 index 0000000..1d2f78a --- /dev/null +++ b/functions/breadcrumb.php @@ -0,0 +1,40 @@ + + + +
+ +
+ +
+ + +
+ \ No newline at end of file diff --git a/functions/flags.php b/functions/flags.php new file mode 100644 index 0000000..7fc6110 --- /dev/null +++ b/functions/flags.php @@ -0,0 +1,91 @@ + 'Flag', + 'labels' => array( + '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' + ), + 'hierarchical' => false + ) +); + +register_taxonomy_for_object_type( 'flag', 'post' ); + +// Add field to be able to change the flags +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 +?> + + + + + + +
+ + + + +term_id; // Get the ID of the term you're editing + $term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check +?> + +
+ + +

.

+
+ + \ No newline at end of file diff --git a/functions/posts-support.php b/functions/posts-support.php new file mode 100644 index 0000000..32c236f --- /dev/null +++ b/functions/posts-support.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/functions/profile-extra-fields.php b/functions/profile-extra-fields.php new file mode 100644 index 0000000..b3340cc --- /dev/null +++ b/functions/profile-extra-fields.php @@ -0,0 +1,42 @@ +ID ); + ?> +

+ + + + + + +
+ +
+ \ No newline at end of file diff --git a/functions/reading-time.php b/functions/reading-time.php new file mode 100644 index 0000000..5a4ca24 --- /dev/null +++ b/functions/reading-time.php @@ -0,0 +1,23 @@ +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; +} + +?> \ No newline at end of file diff --git a/functions/romans.php b/functions/romans.php new file mode 100644 index 0000000..1e530b4 --- /dev/null +++ b/functions/romans.php @@ -0,0 +1,73 @@ + '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 + ?> + + + + + + +
+ + + + + term_id; // Get the ID of the term you're editing + $term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check + ?> + +
+ + +

.

+
+ + \ No newline at end of file diff --git a/functions/tags-moreinfo.php b/functions/tags-moreinfo.php new file mode 100644 index 0000000..423554d --- /dev/null +++ b/functions/tags-moreinfo.php @@ -0,0 +1,50 @@ + + + +

Une URL permettant d\'obtenir plus d\'information sur le tag.

+ '; +} + +add_action( 'post_tag_edit_form_fields', 'kspace_edit_term_fields_moreinfo', 10, 2 ); + +function kspace_edit_term_fields_moreinfo( $term, $taxonomy ) { + + $value = get_term_meta( $term->term_id, 'plus-dinfo', true ); + + echo ' + + + + + +

Une URL permettant d\'obtenir plus d\'information sur le tag.

+ + '; +} + +add_action( 'created_post_tag', 'kspace_save_term_fields_moreinfo' ); +add_action( 'edited_post_tag', 'kspace_save_term_fields_moreinfo' ); + +function kspace_save_term_fields_moreinfo( $term_id ) { + + update_term_meta( + $term_id, + 'plus-dinfo', + sanitize_text_field( $_POST[ 'plus-dinfo' ] ) + ); + +} + + +?> \ No newline at end of file