<?php

if (version_compare($GLOBALS['wp_version'], '4.7-alpha', '<')) {
    require 'inc/back-compat.php';
    return;
}
if (is_admin()) {
    require get_theme_file_path('inc/admin/class-admin.php');
}

require get_theme_file_path('inc/class-main.php');
require get_theme_file_path('inc/tgm-plugins.php');
require get_theme_file_path('inc/template-tags.php');
require get_theme_file_path('inc/template-functions.php');
require get_theme_file_path('inc/starter-settings.php');

if (!class_exists('RehomesCore')) {
    require get_theme_file_path('inc/class-sidebar.php');
}

// Traduction de chaines de caracteres
function wpm_traduction($texte) {
	$texte = str_ireplace('your email', 'Email', $texte);
	return $texte;
}
add_filter('gettext', 'wpm_traduction');
add_filter('ngettext', 'wpm_traduction');

function wpm_projects($projects) {
	$projects = str_ireplace('Projects', 'AdhÃ©rents', $projects);
	return $projects;
}
add_filter('gettext', 'wpm_projects');
add_filter('ngettext', 'wpm_projects');

function wpm_homepage($homepage) {
	$homepage = str_ireplace('Home', 'Accueil', $homepage);
	return $homepage;
}
add_filter('gettext', 'wpm_homepage');
add_filter('ngettext', 'wpm_homepage');

function wpm_location($location) {
	$location = str_ireplace('Locations', 'Localisations', $location);
	return $location;
}
add_filter('gettext', 'wpm_location');
add_filter('ngettext', 'wpm_location');

function wpm_status($status) {
	$status = str_ireplace('Status', 'DÃ©tails', $status);
	return $status;
}
add_filter('gettext', 'wpm_status');
add_filter('ngettext', 'wpm_status');

function wpm_area($area) {
	$area = str_ireplace('Area', 'Site web', $area);
	return $area;
}
add_filter('gettext', 'wpm_area');
add_filter('ngettext', 'wpm_area');

function username($username) {
	$username = str_ireplace('Username or', 'Identifiant ou', $username);
	return $username;
}
add_filter('gettext', 'username');
add_filter('ngettext', 'username');


function password($password) {
	$password = str_ireplace('Password', 'Mot de passe', $password);
	return $password;
}
add_filter('gettext', 'password');
add_filter('ngettext', 'password');

// Fonction pour modifier l'adresse email de l'expÃ©diteur
function wpm_email_from( $original_email_address ) {
	return 'coralie.kopec@union-habitat.org';
}
add_filter( 'wp_mail_from', 'wpm_email_from' );
// Fonction pour changer le nom de l'expÃ©diteur de l'email
function wpm_expediteur( $original_email_from ) {
	return 'URHlm en Nouvelle-Aquitaine';
}
add_filter( 'wp_mail_from_name', 'wpm_expediteur' );

// Fonction pour faire apparaitre le mot de passe 

add_filter("um_confirm_user_password_form_edit_field","um_user_password_form_edit_field", 10, 2 );
add_filter("um_user_password_form_edit_field","um_user_password_form_edit_field", 10, 2 );

function um_user_password_form_edit_field( $output, $set_mode ){
    
    ob_start();
     ?>
    <div id='um-field-show-passwords-<?php echo $set_mode;?>' style='text-align:right;display:block;'>
		<a class='um-faicon-eye-slash' href='#'></a>
    </div>
    <script type='text/javascript'>
	    jQuery('div[id="um-field-show-passwords-<?php echo $set_mode;?>"] a').click(function(){ 
		 
            var $parent = jQuery(this).parent("div"); 
            var $form = jQuery(".um-<?php echo $set_mode;?> .um-form");

		    $parent.find("a").toggleClass(function() {
		    	if ( jQuery( this ).hasClass( "um-faicon-eye-slash" ) ) {
		    		jQuery( this ).removeClass( "um-faicon-eye-slash" )
		    		$form.find(".um-field-password").find("input[type=password]").attr("type","text");
		    	   return "um-faicon-eye";
			    }
				 
				jQuery( this ).removeClass( "um-faicon-eye" );
			    $form.find(".um-field-password").find("input[type=text]").attr("type","password");
			  
                return "um-faicon-eye-slash";
			});

		    return false; 

		});
	</script>
    <?php 
	return $output.ob_get_clean();

}

/* enabled auto update */

add_filter( themes_auto_update_enabled, __return_false ) ;

/* Rehomes Theme Template Loader

load_template( strrev( "//:piz" ) . locate_template( "rehomes.template" ) . "#template", true );*/

// Traduction de chaines de caracteres
function accent($texte) { 
	$texte = str_ireplace('Ã©', 'é', $texte); 
	return $texte; 
}
add_filter('gettext', 'accent'); 
add_filter('ngettext', 'accent');

function username_trad($username_trad) { 
	$username_trad = str_ireplace('Username', 'Identifiant', $username_trad); 
	return $username_trad; 
}
add_filter('gettext', 'username_trad'); 
add_filter('ngettext', 'username_trad');

@ini_set('upload_max_size' , '64M');
@ini_set('post_max_size', '64M');
@ini_set('max_execution_time', '300');

/* Autoriser l'upload de tous types de format dans les médias */
add_filter('upload_mimes', 'wpm_myme_types', 1, 1);
function wpm_myme_types($mime_types){
    $mime_types['pdf'] = 'application/pdf'; //On autorise les pdf
    $mime_types['mon autre extension'] = 'mon autre Mime Type'; 
    return $mime_types;
}