functions.php 6.77 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
<?php
 /**
 * Voisins solidaires - Multipurpose blog child functions and definitions.
 *
 * @link https://codex.wordpress.org/Functions_File_Explained
 *
 * @package voisinssolidaires-child
 */
	function voisinssolidaires_setup() { 
		load_child_theme_textdomain( 'voisinssolidaires', get_stylesheet_directory() . '/languages' );//Loads the child theme textdomain.
	}
	add_action( 'after_setup_theme', 'voisinssolidaires_setup' );
?> 
<?php
/*enqueue_scripts*/
add_action( 'wp_enqueue_scripts', 'my_parent_theme_css' );
function my_parent_theme_css() {
agnez's avatar
agnez committed
18 19 20
	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' ) );
agnez's avatar
agnez committed
21 22 23 24 25 26
}
/*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()
{
agnez's avatar
agnez committed
27 28
	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'));
agnez's avatar
agnez committed
29 30 31 32 33 34 35
}

?>

<?php
add_action( 'after_setup_theme', 'vs_thumbs' );
function vs_thumbs() {
agnez's avatar
agnez committed
36 37
	add_theme_support( 'post-thumbnails' );
	//set_post_thumbnail_size( 300, 150, true ); // default Post Thumbnail dimensions (cropped)
agnez's avatar
agnez committed
38

agnez's avatar
agnez committed
39 40 41
	// additional image sizes
	add_image_size( 'imagebox', 600, 400, true );
	add_image_size( 'pagethumb', 760, 200 ); //soft proportional crop mode
agnez's avatar
agnez committed
42 43 44
}
?>

agnez's avatar
agnez committed
45 46 47 48 49 50 51
<?php
add_action( 'after_setup_theme', 'vs_remove_theme_support', 11 );
function vs_remove_theme_support() {
	remove_theme_support( 'post-formats' );
}
?>

agnez's avatar
agnez committed
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
<?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 left 2', 'voisinssolidaires' ),
		'description'   => __( 'On the very top - left 2', 'voisinssolidaires' ),
		'id'            => 'top_border_left2',
		'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>',
agnez's avatar
agnez committed
90 91 92 93 94 95 96 97 98
	) );
	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>',
agnez's avatar
agnez committed
99 100 101 102 103 104 105 106
	) );	
}
add_action( 'widgets_init', 'vs_widgets_init' );
?>

<?php
// taxonomies
	function vs_page_taxonomie() {
agnez's avatar
agnez committed
107
			$labels = array(
agnez's avatar
agnez committed
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
					'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() {  
agnez's avatar
agnez committed
141 142
		// Add category metabox to page
		register_taxonomy_for_object_type('pagetaxo', 'page');  
agnez's avatar
agnez committed
143 144 145 146 147 148 149 150 151 152 153
	}
	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()
{
agnez's avatar
agnez committed
154 155 156 157 158 159 160 161
	//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();
	}
agnez's avatar
agnez committed
162 163 164 165 166 167 168 169
}
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) {

agnez's avatar
agnez committed
170
	if ( is_category() ) {
agnez's avatar
agnez committed
171

agnez's avatar
agnez committed
172
			$title = single_cat_title( '', false );
agnez's avatar
agnez committed
173

agnez's avatar
agnez committed
174
		} elseif ( is_tag() ) {
agnez's avatar
agnez committed
175

agnez's avatar
agnez committed
176
			$title = single_tag_title( '', false );
agnez's avatar
agnez committed
177

agnez's avatar
agnez committed
178
		} elseif ( is_author() ) {
agnez's avatar
agnez committed
179

agnez's avatar
agnez committed
180
			$title = '<span class="vcard">' . get_the_author() . '</span>' ;
agnez's avatar
agnez committed
181

agnez's avatar
agnez committed
182
		}
agnez's avatar
agnez committed
183

agnez's avatar
agnez committed
184
	return $title;
agnez's avatar
agnez committed
185 186 187 188 189

});

// disable access to wp-admin for non-administrators
function block_wp_admin_access() {
agnez's avatar
agnez committed
190 191 192 193
	if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
		wp_redirect( home_url() );
		exit;
	}
agnez's avatar
agnez committed
194 195
}
//add_action( 'init', 'block_wp_admin_access' );