194 lines
6.6 KiB
PHP
194 lines
6.6 KiB
PHP
<?php
|
|
/* functions.php
|
|
*
|
|
* All the function of Kazhnuz.Space
|
|
*
|
|
*/
|
|
|
|
|
|
/* 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, 510, true );
|
|
|
|
/* 1. Niveau support
|
|
*
|
|
* Permet d'afficher les niveaux de post pour les post features
|
|
*/
|
|
|
|
register_taxonomy(
|
|
'niveau',
|
|
'post',
|
|
array(
|
|
'label' => 'Niveau',
|
|
'labels' => array(
|
|
'name' => 'Niveaux',
|
|
'singular_name' => 'Niveaux',
|
|
'all_items' => 'Tous les niveaux',
|
|
'edit_item' => 'Éditer le niveau',
|
|
'view_item' => 'Voir le niveau',
|
|
'update_item' => 'Mettre à jour le niveau',
|
|
'add_new_item' => 'Ajouter un niveau',
|
|
'new_item_name' => 'Nouveau niveau',
|
|
'search_items' => 'Rechercher parmi les niveaux',
|
|
'popular_items' => 'Niveaux les plus utilisés'
|
|
),
|
|
'hierarchical' => false
|
|
)
|
|
);
|
|
|
|
register_taxonomy_for_object_type( 'niveau', 'post' );
|
|
|
|
/* 2. Réseaux sociaux
|
|
*
|
|
* Permet d'afficher les réseaux sociaux en bas du post.
|
|
*
|
|
*/
|
|
|
|
function mypost_social_sharing_buttons($content) {
|
|
// Fork of mypost_social_sharing_buttons
|
|
// You can find the original at the following url:
|
|
// https://mypost_.com/how-to-create-social-sharing-button-without-any-plugin-and-script-loading-wordpress-speed-optimization-goal/
|
|
|
|
global $post;
|
|
if(is_singular() && !is_page()){
|
|
|
|
// Get current page URL
|
|
$mypost_URL = urlencode(get_permalink());
|
|
|
|
// Get current page title
|
|
$mypost_Title = htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8');
|
|
// $mypost_Title = str_replace( ' ', '%20', get_the_title());
|
|
|
|
// Get Post Thumbnail for pinterest
|
|
$mypost_Thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
|
|
|
|
// Construct sharing URL without using any script
|
|
$twitterURL = 'https://twitter.com/intent/tweet?text='.$mypost_Title.'&url='.$mypost_URL.'&via=mypost_';
|
|
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$mypost_URL;
|
|
$bufferURL = 'https://bufferapp.com/add?url='.$mypost_URL.'&text='.$mypost_Title;
|
|
$whatsappURL = 'whatsapp://send?text='.$mypost_Title . ' ' . $mypost_URL;
|
|
$linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$mypost_URL.'&title='.$mypost_Title;
|
|
$diasporaURL = 'http://sharetodiaspora.github.io/?title=' . $mypost_Title . '&url=' . $mypost_URL;
|
|
|
|
// Based on popular demand added Pinterest too
|
|
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$mypost_URL.'&media='.$mypost_Thumbnail[0].'&description='.$mypost_Title;
|
|
|
|
// Add sharing button at the end of page/page content
|
|
$content .= '<!-- based on crunchify social sharing. Get your copy here: http://crunchify.me/1VIxAsz -->';
|
|
$content .= '<div class="reagir share-buttons">';
|
|
$content .= '<a class="btn-small btn-twitter" href="'. $twitterURL .'" target="_blank"><i alt="twitter" class="fa fa-fw fa-twitter"></i></a> ';
|
|
$content .= '<a class="btn-small btn-facebook" href="'.$facebookURL.'" target="_blank"><i alt="facebook" class="fa fa-fw fa-facebook"></i></a> ';
|
|
$content .= '<a title="Share to Diaspora*" class="btn-small btn-diaspora" href="'.$diasporaURL.'" target="_blank"><i class="fa fa-fw fa-diaspora"></i></a>';
|
|
//$content .= '<a class="btn btn-whatsapp" href="'.$whatsappURL.'" target="_blank"><i alt="whatsapp" class="fa fa-fw fa-whatsapp"></i></a>';
|
|
// $content .= '<a class="btn btn-buffer" href="'.$bufferURL.'" target="_blank"><i alt="buffer" class="fa fa-fw fa-buffer"></i></a>';
|
|
//$content .= '<a class="btn btn-linkedin" href="'.$linkedInURL.'" target="_blank"><i alt="linkedin" class="fa fa-fw fa-linkedin"></i></a>';
|
|
//$content .= '<a class="btn btn-pinterest" href="'.$pinterestURL.'" data-pin-custom="true" target="_blank"><i alt="Pin It" class="fa fa-fw fa-pinterest"></i></a>';
|
|
$content .= '</div>';
|
|
|
|
return $content;
|
|
}else{
|
|
// if not a post/page then don't include sharing button
|
|
return $content;
|
|
}
|
|
};
|
|
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' );
|
|
|
|
function kspace_add_term_fields( $taxonomy ) {
|
|
echo '<div class="form-field">
|
|
<label for="plus-dinfo">Plus d\'Info</label>
|
|
<input type="text" name="plus-dinfo" id="plus-dinfo" />
|
|
<p>Une URL permettant d\'obtenir plus d\'information sur le tag.</p>
|
|
</div>';
|
|
}
|
|
|
|
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 '<tr class="form-field">
|
|
<th>
|
|
<label for="plus-dinfo">Plus d\'Info</label>
|
|
</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>';
|
|
}
|
|
|
|
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 );
|
|
?>
|
|
<h3><?php esc_html_e( 'More Info', 'kspace' ); ?></h3>
|
|
|
|
<table class="form-table">
|
|
<tr>
|
|
<th><label for="infodata"><?php esc_html_e( 'infodata', 'kspace' ); ?></label></th>
|
|
<td>
|
|
<input type="input"
|
|
id="infodata"
|
|
name="infodata"
|
|
value="<?php echo esc_attr( $year ); ?>"
|
|
class="regular-text"
|
|
/>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<?php
|
|
}
|
|
|
|
add_action( 'personal_options_update', 'kspace_update_profile_fields' );
|
|
add_action( 'edit_user_profile_update', 'kspace_update_profile_fields' );
|
|
|
|
function kspace_update_profile_fields( $user_id ) {
|
|
if ( ! current_user_can( 'edit_user', $user_id ) ) {
|
|
return false;
|
|
}
|
|
|
|
update_user_meta( $user_id, 'infodata', $_POST['infodata'] );
|
|
}
|