chore: improve functions file

This commit is contained in:
Kazhnuz Klappsthul 2021-01-03 14:00:37 +01:00
parent 860038b1e7
commit f47183844d
1 changed files with 51 additions and 41 deletions

View File

@ -1,22 +1,30 @@
<?php <?php
/* functions.php /* functions.php
* *
* All the function of Quarante-Douze * All the function of Kazhnuz.Space
* *
*/ */
/* 1. Sidebar support */ /* 0. Excerpt and thumbnail support
*
* Ces fonctions ajoutent les fonctionnalités de base du theme,
* tel que les extraits et les miniatures.
*/
if ( function_exists('register_sidebar') ) function kspace_post_supports() {
register_sidebar(array( add_post_type_support( 'post', 'excerpt');
'before_widget' => '<section id="%1$s" class="widget %2$s card card-primary">', }
'after_widget' => '</section>',
'before_title' => '<div class="section card-header"><h1>',
'after_title' => '</h1></div>',
));
/* 2. Niveau support (for featured posts) */ add_action( 'init', 'kspace_post_supports' );
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 825, 510, true );
/* 1. Niveau support
*
* Permet d'afficher les niveaux de post pour les post features
*/
register_taxonomy( register_taxonomy(
'niveau', 'niveau',
@ -41,18 +49,11 @@ register_taxonomy(
register_taxonomy_for_object_type( 'niveau', 'post' ); register_taxonomy_for_object_type( 'niveau', 'post' );
/* 3. Excerpt and thumbnail support */ /* 2. Réseaux sociaux
*
function wpqdouze_post_supports() { * Permet d'afficher les réseaux sociaux en bas du post.
add_post_type_support( 'post', 'excerpt'); *
} */
add_action( 'init', 'wpqdouze_post_supports' );
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 825, 510, true );
/* 4. Social Network */
function mypost_social_sharing_buttons($content) { function mypost_social_sharing_buttons($content) {
// Fork of mypost_social_sharing_buttons // Fork of mypost_social_sharing_buttons
@ -103,25 +104,32 @@ function mypost_social_sharing_buttons($content) {
}; };
add_filter( 'the_content', 'mypost_social_sharing_buttons'); add_filter( 'the_content', 'mypost_social_sharing_buttons');
/* 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.
*
*/
add_action( 'post_tag_add_form_fields', 'kspace_add_term_fields' ); add_action( 'post_tag_add_form_fields', 'kspace_add_term_fields' );
function kspace_add_term_fields( $taxonomy ) { function kspace_add_term_fields( $taxonomy ) {
echo '<div class="form-field"> echo '<div class="form-field">
<label for="misha-text">Plus d\'Info</label> <label for="plus-dinfo">Plus d\'Info</label>
<input type="text" name="plus-dinfo" id="plus-dinfo" /> <input type="text" name="plus-dinfo" id="plus-dinfo" />
<p>Une URL permettant d\'obtenir plus d\'information sur le tag.</p> <p>Une URL permettant d\'obtenir plus d\'information sur le tag.</p>
</div>'; </div>';
} }
add_action( 'post_tag_edit_form_fields', 'misha_edit_term_fields', 10, 2 ); add_action( 'post_tag_edit_form_fields', 'kspace_edit_term_fields', 10, 2 );
function misha_edit_term_fields( $term, $taxonomy ) { function kspace_edit_term_fields( $term, $taxonomy ) {
$value = get_term_meta( $term->term_id, 'plus-dinfo', true ); $value = get_term_meta( $term->term_id, 'plus-dinfo', true );
echo '<tr class="form-field"> echo '<tr class="form-field">
<th> <th>
<label for="misha-text">Plus d\'Info</label> <label for="plus-dinfo">Plus d\'Info</label>
</th> </th>
<td> <td>
<input name="plus-dinfo" id="plus-dinfo" type="text" value="' . esc_attr( $value ) .'" /> <input name="plus-dinfo" id="plus-dinfo" type="text" value="' . esc_attr( $value ) .'" />
@ -130,10 +138,10 @@ function misha_edit_term_fields( $term, $taxonomy ) {
</tr>'; </tr>';
} }
add_action( 'created_post_tag', 'misha_save_term_fields' ); add_action( 'created_post_tag', 'kspace_save_term_fields' );
add_action( 'edited_post_tag', 'misha_save_term_fields' ); add_action( 'edited_post_tag', 'kspace_save_term_fields' );
function misha_save_term_fields( $term_id ) { function kspace_save_term_fields( $term_id ) {
update_term_meta( update_term_meta(
$term_id, $term_id,
@ -143,22 +151,24 @@ function misha_save_term_fields( $term_id ) {
} }
// --------------------------------------------- /* 3. Info supplémentaire sur profil utilisateur
// Ajout des champs custom pour l'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' );
add_action( 'show_user_profile', 'crf_show_extra_profile_fields' ); function kspace_show_extra_profile_fields( $user ) {
add_action( 'edit_user_profile', 'crf_show_extra_profile_fields' );
function crf_show_extra_profile_fields( $user ) {
$year = get_the_author_meta( 'infodata', $user->ID ); $year = get_the_author_meta( 'infodata', $user->ID );
?> ?>
<h3><?php esc_html_e( 'More Info', 'crf' ); ?></h3> <h3><?php esc_html_e( 'More Info', 'kspace' ); ?></h3>
<table class="form-table"> <table class="form-table">
<tr> <tr>
<th><label for="infodata"><?php esc_html_e( 'infodata', 'crf' ); ?></label></th> <th><label for="infodata"><?php esc_html_e( 'infodata', 'kspace' ); ?></label></th>
<td> <td>
<input type="input" <input type="input"
id="infodata" id="infodata"
@ -172,10 +182,10 @@ function crf_show_extra_profile_fields( $user ) {
<?php <?php
} }
add_action( 'personal_options_update', 'crf_update_profile_fields' ); add_action( 'personal_options_update', 'kspace_update_profile_fields' );
add_action( 'edit_user_profile_update', 'crf_update_profile_fields' ); add_action( 'edit_user_profile_update', 'kspace_update_profile_fields' );
function crf_update_profile_fields( $user_id ) { function kspace_update_profile_fields( $user_id ) {
if ( ! current_user_can( 'edit_user', $user_id ) ) { if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false; return false;
} }