functions.php 9.91 KB
Newer Older
agnez's avatar
agnez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
<?php
add_action( 'after_setup_theme', 'voisinssolidaires_setup' );
function voisinssolidaires_setup() { 
	load_child_theme_textdomain( 'voisinssolidaires', get_stylesheet_directory() . '/languages' );//Loads the child theme textdomain.
}
?>

<?php
//* Dequeue parent's styles - Remove Google Fonts https://technumero.com/remove-google-fonts-from-wordpress-theme/
add_action( 'wp_print_styles', 'tn_dequeue_google_fonts_style' );
function tn_dequeue_google_fonts_style() {
      wp_dequeue_style( 'multipurpose-blog-font' );
}

/*enqueue_scripts*/
add_action( 'wp_enqueue_scripts', 'my_parent_theme_css' );
function my_parent_theme_css() {
	wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
	wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.css');
	wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style,bootstrap' ) );
	wp_enqueue_style( 'dashicons' );
}
/*enqueue_styles*/
// hook in late to make sure the parent theme's registration has fired so you can undo it. Otherwise the parent will simply enqueue its script anyway.
add_action('wp_enqueue_scripts', 'my_parent_theme_js', 100);
function my_parent_theme_js()
{
	wp_dequeue_script('parent_theme_script_handle');
	wp_enqueue_script('child_theme_script_handle', get_stylesheet_directory_uri().'/js/jquery.nivo.slider.js', array('jquery'));
}

?>

<?php
add_action( 'after_setup_theme', 'vs_thumbs' );
function vs_thumbs() {
	add_theme_support( 'post-thumbnails' );
	//set_post_thumbnail_size( 300, 150, true ); // default Post Thumbnail dimensions (cropped)

	// additional image sizes
	add_image_size( 'imagebox', 600, 400, true );
	add_image_size( 'pagethumb', 760, 200 ); //soft proportional crop mode
}
?>

<?php
add_action( 'after_setup_theme', 'vs_remove_theme_support', 11 );
function vs_remove_theme_support() {
	remove_theme_support( 'post-formats' );
	add_theme_support( 'post-formats', array('video','audio',) );
}
?>

<?php
/* Theme Widgets Setup */
function vs_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Tob bandeau left', 'voisinssolidaires' ),
		'description'   => __( 'On the very top - left', 'voisinssolidaires' ),
		'id'            => 'top_border_left',
		'before_widget' => '<span id="%1$s" class="widget %2$s">',
		'after_widget'  => '</span>',
		'before_title'  => '<b class="widget-title">',
		'after_title'   => '</b>',
	) );	
	register_sidebar( array(
		'name'          => __( 'Tob bandeau right', 'voisinssolidaires' ),
		'description'   => __( 'On the very top - right', 'voisinssolidaires' ),
		'id'            => 'top_border_right',
		'before_widget' => '<span id="%1$s" class="widget %2$s">',
		'after_widget'  => '</span>',
		'before_title'  => '<b class="widget-title">',
		'after_title'   => '</b>',
	) );
	register_sidebar( array(
		'name'          => __( 'Bottom footer', 'voisinssolidaires' ),
		'description'   => __( 'On the very bottom', 'voisinssolidaires' ),
		'id'            => 'footer-b',
		'before_widget' => '<div>',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
	register_sidebar( array (
		'name'          => __( 'Page Login espace membre', 'voisinssolidaires' ),
		'description'   => __( 'Widgets sur page spécifique avec slug "espace-membres"', 'voisinssolidaires' ),
		'id'            => 'widget-em',
		'before_widget' => '<div id="espace-membres-widget">',
		'after_widget'  => '</div>',
		'before_title'  => '<b class="widget-title">',
		'after_title'   => '</b>',
	) );	
}
add_action( 'widgets_init', 'vs_widgets_init' );
?>

<?php
// taxonomies
	function vs_page_taxonomie() {
			$labels = array(
					'name'              => _x( 'Special functions', 'taxonomy general name', 'voisinssolidaires' ),
					'singular_name'     => _x( 'Special function', 'taxonomy singular name', 'voisinssolidaires' ),
					'all_items'         => __( 'All Special functions', 'voisinssolidaires' ),
					'parent_item'       => null,
					'parent_item_colon'	=> null,					
					'search_items'      => __( 'Search Special functions', 'voisinssolidaires' ),
					'edit_item'         => __( 'Edit Special function', 'voisinssolidaires' ),
					'update_item'       => __( 'Update Special function', 'voisinssolidaires' ),
					'add_new_item'      => __( 'Add New Special function', 'voisinssolidaires' ),
					'new_item_name'     => __( 'New special function Name', 'voisinssolidaires' ),
					'menu_name'         => __( 'Special functions' )
				);
				$capabilities = array (
					'manage_terms' 	=> 'manage_options', //by default only admin
					'edit_terms' 	=> 'manage_options',
					'delete_terms' 	=> 'manage_options',
					'assign_terms' 	=> 'edit_posts'			
				);
				$args = array(
					'hierarchical'      => false,
					'labels'            => $labels,
					'show_ui'           => true,
					'show_admin_column' => true,
					'query_var'         => true,
					'public' 			=> true, //needs to be public for the radio-button plugin to work
					'rewrite'           => false,
					'capabilities'      => $capabilities
				);
		register_taxonomy( 'pagetaxo', array( 'page' ), $args );
	}
	add_action( 'init', 'vs_page_taxonomie',0 );	

	function vs_metaboxes() {  
		// Add category metabox to page
		register_taxonomy_for_object_type('pagetaxo', 'page');  
	}
	add_action( 'init', 'vs_metaboxes' );
?>

<?php
// https://seventhqueen.com/blog/code-snippets/restrict-guest-users-from-accessing-buddypress-or-bbpress-pages.html
/**
* Redirect buddypress and bbpress pages to registration page
*/
function vs_page_template_redirect()
{
	//if not logged in and on a bp page except registration or activation
	if( ! is_user_logged_in() &&
		( ( ! bp_is_blog_page() && ! bp_is_activation_page() && ! bp_is_register_page() ) || is_bbpress() )
	)
	{
		wp_redirect( home_url( '/register/' ) );
		exit();
	}
}
add_action( 'template_redirect', 'vs_page_template_redirect' );
?>

<?php
// supprimer intitulé "catégorie" "tag" "autheur" https://wordpress.stackexchange.com/questions/179585/remove-category-tag-author-from-the-archive-title#answer-179590
add_filter( 'get_the_archive_title', function ($title) {

	if ( is_category() ) {

			$title = single_cat_title( '', false );

		} elseif ( is_tag() ) {

			$title = single_tag_title( '', false );

		} elseif ( is_author() ) {

			$title = '<span class="vcard">' . get_the_author() . '</span>' ;

		}

	return $title;

});
?>

<?php
// disable access to wp-admin for non-administrators
function block_wp_admin_access() {
	if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
		wp_redirect( home_url() );
		exit;
	}
}
//add_action( 'init', 'block_wp_admin_access' );

?>

<?php
//email new user accound created
add_filter( 'wp_new_user_notification_email_admin', 'vs_new_user_notification_email', 10, 3 );
function vs_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
    $wp_new_user_notification_email['subject'] = sprintf( '[%s] nouveau voisin solidaire %s enregistré.', $blogname, $user->user_login );
    $wp_new_user_notification_email['message'] = sprintf( "%s ( %s ) a été ajouté au site %s.", $user->user_login, $user->user_email, $blogname );
    return $wp_new_user_notification_email;
}

add_filter( 'wp_new_user_notification_email' , 'edit_user_notification_email', 10, 3 );
function edit_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {

    $message = sprintf(__("Bonjour %s %s," ), $user->user_firstname, $user->user_lastname ) . "\r\n\r\n";
    $message .= sprintf(__( "L’administrateur ou l’administratrice du site %s vient de vous créer un profil pour accéder à l’espace membre du site, réservé uniquement aux voisin.e.s solidaire.s engagé.e.s dans le projet. Cet espace a été pensé comme un espace collectif et d’échanges entre tous les voisins solidaires, notamment pour vous accompagner durant la relation avec vos voisin.e.s réfugié.e.s." ), $blogname ) . "\r\n\r\n";
    $message .= wp_login_url() . "\r\n";    
    $message .= sprintf(__( 'Votre login : %s' ), $user->user_login ) . "\r\n";
    $message .= sprintf(__( 'Votre mot de passe : %s' ), $user->user_pass ) . "\r\n\r\n";
    $message .= __("Grâce à cet accès, nous vous invitons à aller sur votre profil pour le personnaliser (changer le mot de passe, mettre une photo etc.) mais aussi à interagir avec d’autres sur le forum, structuré en différentes thématiques utiles. De plus, Vous pourrez accéder à notre boite à outils, pensée comme une aide pratique, et à la liste de tous les autres membres afin de pouvoir aussi leur envoyer un message privé." ) . "\r\n";
    $message .= __("Cet espace est le vôtre, n’hésitez pas à nous contacter pour nous faire des retours, que ce soit à propos de sa forme ou du fond, mais aussi pour proposer d’autres outils qui vous sembleraient pertinent de partager etc." ) . "\r\n";
    $message .= __("Merci d’avance et à bientôt !" );

    $wp_new_user_notification_email['message'] = $message;

    return $wp_new_user_notification_email;

}
?>

<?php
// external links to blank https://stackoverflow.com/questions/41874623/open-every-external-link-in-a-new-window-automatically-html-css
function cdx_handel_external_links() {?>
<script type="text/javascript">
( function( $ ) {

    $("a[href^=http]").click(function(){
      if(this.href.indexOf(location.hostname) == -1) {
         $(this).attr({
            target: "_blank"
         });
      }
    })

   //Add Nofollow
   $("a").each(function(){
    if(this.href.indexOf('nytimes.com') >0 ){
        $(this).attr({
            rel: "nofollow"
         });
    }
   });

} )( jQuery );
</script>
   <?php
}
add_filter( 'wp_footer', 'cdx_handel_external_links', 999);
?>

<?php
//add_action('wp_head', 'vs_add_googleanalytics');
function vs_add_googleanalytics() { ?>
 
// Paste your Google Analytics code here
UA-12605197-11
 
<?php } 

/**
 * Checks to see if we're on the front page or not.
 */
function twentyseventeen_is_frontpage() {
	return ( is_front_page() && ! is_home() );
}
?>