functions.php 11.6 KB
Newer Older
agnez's avatar
agnez committed
1 2 3 4
<?php
// Include Beans. Do not remove the line below.
require_once( get_template_directory() . '/lib/init.php' );

agnez's avatar
agnez committed
5 6 7 8
add_action( 'after_setup_theme', 'gasap_setup' );
function gasap_setup() { 
	load_child_theme_textdomain( 'beans_gasap', get_stylesheet_directory() . '/languages' );//Loads the child theme textdomain.
}
agnez's avatar
agnez committed
9

agnez's avatar
agnez committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

/*  Thumbnail upscale
/* ------------------------------------
 *http://alxmedia.se/code/2013/10/thumbnail-upscale-correct-crop-in-wordpress/#comment-106069
 */ 
//casse les formats carrés
//add_filter( 'image_resize_dimensions', 'alx_thumbnail_upscale', 10, 6 );
function alx_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ){
    if ( !$crop ) return null; // let the wordpress default function handle this
 
    $aspect_ratio = $orig_w / $orig_h;
    $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
 
    $crop_w = round($new_w / $size_ratio);
    $crop_h = round($new_h / $size_ratio);
 
    $s_x = floor( ($orig_w - $crop_w) / 2 );
    $s_y = floor( ($orig_h - $crop_h) / 2 );
 
    return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}


agnez's avatar
agnez committed
33 34 35 36 37 38 39 40 41
/* Image formats */
add_action( 'after_setup_theme', 'gasap_formats', 20 );	
function gasap_formats(){
	add_theme_support( 'post-thumbnails' );
	add_image_size( 'diaporama', 1200, 370, true );
	add_image_size( 'newsthumb', 230, 210, true );
	add_image_size( 'calendarthumb', 310, 310, true );
	add_image_size( 'medium2', 500, 500, true );
}	
agnez's avatar
agnez committed
42

agnez's avatar
agnez committed
43
/*
agnez's avatar
agnez committed
44
 * Useing LESS + UIkit variables + js
agnez's avatar
agnez committed
45 46 47 48
 */
add_action( 'beans_uikit_enqueue_scripts', 'gasap_enqueue_uikit_assets' );
function gasap_enqueue_uikit_assets() {
	// Enqueue uikit overwrite theme folder
agnez's avatar
agnez committed
49
	beans_uikit_enqueue_theme( 'beans_gasap', get_stylesheet_directory_uri() . '/assets/less/uikit' );	
agnez's avatar
agnez committed
50
	// Add the theme style as a uikit fragment to have access to all the variables
51
	beans_uikit_enqueue_components( array( 'switcher', 'modal', 'tab', 'overlay', 'cover', 'smooth-scroll' ) );
agnez's avatar
agnez committed
52
	beans_uikit_enqueue_components( array( 'slider', 'slideshow', 'grid', 'accordion' ), 'add-ons' );
agnez's avatar
agnez committed
53 54 55
	beans_compiler_add_fragment( 'uikit', get_stylesheet_directory_uri() . '/assets/less/style.less', 'less' );
	beans_compiler_add_fragment( 'uikit', get_stylesheet_directory_uri() . '/assets/less/gasap.less', 'less' );
	// Remove unnecessary components.
agnez's avatar
agnez committed
56 57 58 59 60
	//beans_uikit_dequeue_components( array( 'breadcrumb', 'comment', 'pagination', 'form', 'table' ) );
}

add_action( 'wp_enqueue_scripts', 'gasap_js_scripts' );
function gasap_js_scripts() {
agnez's avatar
agnez committed
61 62 63 64 65 66
	wp_register_script('gasap_post_id_script', get_stylesheet_directory_uri() . '/assets/js/gasap_post_id.js', array('jquery'));
	wp_register_script('gasap_trois_prod', get_stylesheet_directory_uri() . '/assets/js/fill_page_trois_prod.js', array('jquery'));
	//wp_register_script( 'gasap_map_script', get_stylesheet_directory_uri() . '/assets/js/gasap_map.js', array('jquery') );// pour GASAP map
	//wp_register_script( 'google_map', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js' );// pour GASAP map
	//wp_enqueue_script( 'gasap_map_script');
	//wp_enqueue_script( 'google_map');
agnez's avatar
agnez committed
67 68
	wp_enqueue_script( 'gasap_post_id_script');
	wp_enqueue_script( 'gasap_trois_prod');
agnez's avatar
agnez committed
69 70
	wp_localize_script( 'gasap_post_id_script', 'gasap_frontend_ajax',array('ajaxurl' => admin_url( 'admin-ajax.php' ),));
	wp_localize_script( 'gasap_trois_prod', 'gasap_frontend_ajax',array('ajaxurl' => admin_url( 'admin-ajax.php' ),));
agnez's avatar
agnez committed
71 72
}

agnez's avatar
agnez committed
73 74 75 76 77 78

add_action( 'beans_head', 'embed_google_script'  );
function embed_google_script(){
    echo '<script src="https://www.google.com/recaptcha/api.js"></script>';
}

agnez's avatar
agnez committed
79
//TODO encore besoin ?
agnez's avatar
agnez committed
80 81 82 83 84 85 86 87 88 89 90
add_action( 'wp_ajax_gasap_activepost', 'gasap_get_activepost' );
add_action( 'wp_ajax_nopriv_gasap_activepost', 'gasap_get_activepost' );
function gasap_get_activepost() {
	if(isset($_POST['postid'])) {
		$activepost = $_POST['postid'];
		$fiche_producteur = new WP_Query( array( 'p' => $active_prod) );
		$activepost = "fff";
	}
	else {
		$activepost = 'hhhh';
	}
agnez's avatar
agnez committed
91
	//echo $activepost."ddd";
agnez's avatar
agnez committed
92 93 94 95
    die();
}


agnez's avatar
agnez committed
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
//overwrite beans site branding
beans_modify_action_callback( 'beans_site_branding', 'beans_gasap_site_branding' );
function beans_gasap_site_branding() {
	beans_open_markup_e( 'beans_site_title_link', 'a', array(
		'href'     => home_url(), // Automatically escaped.
		'rel'      => 'home',
		'itemprop' => 'headline',
	) );	

		beans_open_markup_e( 'beans_gasap_site_branding', 'div', array(
			'class' => 'tm-site-branding uk-float-left uk-grid uk-width-1-2  uk-width-large-1-4' . ( ! get_bloginfo( 'description' ) ? ' uk-margin-small-top' : null ),
		) );
			
			beans_open_markup_e( 'beans_gasap_site_branding', 'div', array('class' => 'logo uk-width-1-1 uk-width-medium-1-4') );
				if ( $logo = get_theme_mod( 'beans_logo_image', false ) ) {
					beans_selfclose_markup_e( 'beans_logo_image', 'img', array(
						'class' => 'tm-logo',
						'src'   => $logo, // Automatically escaped.
						'alt'   => get_bloginfo( 'name' ), // Automatically escaped.
					) );
				} else {
					beans_output_e( 'beans_site_title_text', get_bloginfo( 'name' ) );
				}
			beans_close_markup_e( 'beans_gasap_site_branding', 'div' );

			beans_open_markup_e( 'beans_gasap_site_branding', 'div', array('class' => 'uk-width-3-4 uk-hidden-small') );
				beans_open_markup_e( 'beans_gasap_site_branding', 'div', array('class' => 'name ') );
					beans_output_e( 'beans_site_title_text', get_bloginfo( 'name' ) );
				beans_close_markup_e( 'beans_gasap_site_branding', 'div' );
				beans_open_markup_e( 'beans_gasap_site_branding', 'div', array('class' => 'descr') );		
					beans_output_e( 'beans_site_title_text', get_bloginfo( 'description' ) );		
				beans_close_markup_e( 'beans_gasap_site_branding', 'div' );
			beans_close_markup_e( 'beans_gasap_site_branding', 'div' );	
		beans_close_markup_e( 'beans_gasap_site_branding', 'div' );
	beans_close_markup_e( 'beans_site_title_link', 'a' );	
}


agnez's avatar
agnez committed
134 135 136 137 138
// Setup document fragements, markups and attributes
add_action( 'wp', 'gasap_setup_document' );
function gasap_setup_document() {
	beans_remove_action( 'beans_breadcrumb' );
	beans_remove_action( 'beans_footer_partial_template' );
agnez's avatar
agnez committed
139
	beans_remove_action( 'beans_post_meta_categories' );
agnez's avatar
agnez committed
140 141 142
	//emojis not needed
	remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
	remove_action( 'wp_print_styles', 'print_emoji_styles' );
agnez's avatar
agnez committed
143 144 145 146 147 148
}
// remove author from posts
add_filter( 'beans_post_meta_items', 'beans_child_remove_post_meta_items' );
function beans_child_remove_post_meta_items( $items ) {
	unset( $items['author'] );
	return $items;
agnez's avatar
agnez committed
149 150 151 152 153 154 155 156
}

require_once( get_stylesheet_directory() . '/assets/helpers/cleaner.php' );
require_once( get_stylesheet_directory() . '/assets/helpers/shared.php' );

// Force layout.
add_filter( 'beans_layout', 'gasap_force_layout' );
function gasap_force_layout() {
agnez's avatar
agnez committed
157
	return 'c';
agnez's avatar
agnez committed
158 159
}

agnez's avatar
agnez committed
160
add_action( 'beans_head', 'gasap_add_font' );
agnez's avatar
agnez committed
161 162
function gasap_add_font() {
?><link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet"><?php
agnez's avatar
agnez committed
163 164
}

agnez's avatar
agnez committed
165
// ?? ça fait quoi ça encore ?
agnez's avatar
agnez committed
166
//add_filter( 'beans_post_meta_post_types_gasap', 'gasap_register_beans_layout' );
agnez's avatar
agnez committed
167
function gasap_register_beans_layout( $conditions ) {
agnez's avatar
agnez committed
168 169
	$conditions[] = 'piece';
	return $conditions;
agnez's avatar
agnez committed
170 171 172 173 174 175 176
}

add_action( 'beans_post_append_markup', 'gasap_post_edit_link' );
function gasap_post_edit_link() {
	//add edit link for post content
	edit_post_link( esc_html__( 'Edit', 'beans_gasap' ), '<span class="edit-link">', '</span>' );
}
agnez's avatar
agnez committed
177 178 179 180 181

add_filter( 'query_vars', 'gasap_prodlink_add_custom_query_var' );
function gasap_prodlink_add_custom_query_var( $vars ){
  $vars[] = "choix_prod"; //pour template part three_producers
  return $vars;
agnez's avatar
agnez committed
182 183 184 185 186 187 188 189 190 191 192 193 194
}

//http://wordpress.stackexchange.com/questions/125554/get-image-description#answer-125613
function wp_get_attachment( $attachment_id ) {
	$attachment = get_post( $attachment_id );
	return array(
		'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
		'caption' => $attachment->post_excerpt,
		'description' => $attachment->post_content,
		'href' => get_permalink( $attachment->ID ),
		'src' => $attachment->guid,
		'title' => $attachment->post_title
	);
195 196
}

agnez's avatar
agnez committed
197 198 199
// Register widget
add_action( 'widgets_init', 'header_widget_areas' );
function header_widget_areas() {
agnez's avatar
agnez committed
200
	beans_register_widget_area( array(
agnez's avatar
agnez committed
201 202
		'name' => __( 'Header Widget Area', 'beans_gasap' ),
		'id'   => 'header_widget_area',
agnez's avatar
agnez committed
203
	) );
agnez's avatar
agnez committed
204 205 206 207 208 209 210
}
add_action( 'beans_primary_menu_after_markup', 'gasap_header_widget_area' );
function gasap_header_widget_area() { ?>
	<div class="uk-float-right"> <?php
		echo beans_widget_area( 'header_widget_area' );	?>
	</div> <?php
}
agnez's avatar
agnez committed
211

agnez's avatar
agnez committed
212 213
//pour three_producers ?? obsolethe ?
/*
agnez's avatar
agnez committed
214 215 216 217
add_filter( 'query_vars', 'add_gasap_query_vars_filter' );
function add_gasap_query_vars_filter( $vars ){
  $vars[] = "prod";
  return $vars;
agnez's avatar
agnez committed
218
} */
agnez's avatar
agnez committed
219

220 221 222 223

// ----------- pour GASAP map
add_action( 'gmw_before_no_results', 'gasap_no_results_show_map' );
function gasap_no_results_show_map( $form ) {
agnez's avatar
agnez committed
224 225 226 227 228 229 230 231
	//exit;
	$form['your_lat'] = "51.103210";
	$form['your_lng'] = "4.729270";
	$form['results_map']['zoom_level'] = "7";
	$gmw = new GMW($form);
	
	$gmw->map_element();
}
232

agnez's avatar
agnez committed
233 234
add_filter( 'gmw_pt_map_icon', 'gasap_map_icon', 99, 2 );
function gasap_map_icon($post) {
235
	$terms = get_the_terms( get_the_ID(), 'gasapstatus' );
agnez's avatar
agnez committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
	if($terms != ''){
		return get_stylesheet_directory_uri() . '/assets/img/map_picto_'.$terms[0]->slug.'.png';
	}
	else{
		return get_stylesheet_directory_uri() . '/assets/img/map_picto_ouvert.png';
	}
}

add_filter( 'gmw_pt_info_window_content', 'gasap_posts_info_window', 50, 3 );
function gasap_posts_info_window( $output, $post, $gmw ) {

	$pLink = "#post_".$post->ID."";
	$output['title'] = "<tr><td><div class=\"title wppl-info-window-permalink\"><a data-uk-modal='' href=\"{$pLink}\">{$post->post_title}</a></div></td></tr>";

	$new_output = array();
	$new_output['start'] = $output['start'];
	$new_output['content_start'] = $output['content_start'];
	$new_output['title'] = $output['title'];
	$new_output['address'] = $output['address'];
	$new_output['content_end'] = $output['content_end'];
	$new_output['end'] 		   = $output['end'];

	return $new_output;
259 260

}
agnez's avatar
agnez committed
261

agnez's avatar
agnez committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
add_filter( 'gmw_pt_dropdown_taxonomy_args', 'gasap_gmw_modify_taxonomy', 10, 3 );
function gasap_gmw_modify_taxonomy( $args, $gmw, $taxonomy ) {
	
	//check that we are within form ID 1, otherwise do nothing
	if ( $gmw['ID'] != 1 )
		return $args;
	
	//check that this is 'gasapday' taxonomy, otherwise do nothing
	if ( $taxonomy->name != 'gasapday' )
		return $args;
	
	//modify the show_option_all of the taxonomy which is responsible 
	//of the default value of the drop-down select box
	$args['orderby'] = 'slug';
	$args['order'] = 'ASC';
	
	
	//return the modifyed args
	return $args;

}

284 285 286 287 288 289 290 291 292 293 294
add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 );
function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
    $attr_mailreferent = 'email-referent';
    $attr_nomgasap = 'nom-gasap';
 
    if ( isset( $atts[$attr_mailreferent] ) ) {
        $out[$attr_mailreferent] = $atts[$attr_mailreferent];
        $out[$attr_nomgasap] = $atts[$attr_nomgasap];
    }
 
    return $out;
295
}
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
// ----------- 

// Remove all feeds http://www.wpbeginner.com/wp-tutorials/how-to-disable-rss-feeds-in-wordpress/
function gasap_disable_feed() {
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}

add_action('do_feed', 'gasap_disable_feed', 1);
add_action('do_feed_rdf', 'gasap_disable_feed', 1);
add_action('do_feed_rss', 'gasap_disable_feed', 1);
add_action('do_feed_rss2', 'gasap_disable_feed', 1);
add_action('do_feed_atom', 'gasap_disable_feed', 1);
add_action('do_feed_rss2_comments', 'gasap_disable_feed', 1);
add_action('do_feed_atom_comments', 'gasap_disable_feed', 1);

remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );