Parcourir la source

Update of the documentation & improvement of the syntax of the functions

te2dy il y a 4 ans
Parent
commit
caa26c618b

+ 1 - 1
404.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * The template for displaying 404 pages (Not Found)
+ * The template for displaying the 404 (Not Found).
  *
  * @link https://codex.wordpress.org/Creating_an_Error_404_Page
  *

+ 104 - 72
assets/js/navigation.js

@@ -13,9 +13,9 @@
  * Collapse menu when the user clicks outside.
  */
 function marianneCollapseMenuOnClickOutside( event ) {
-	if ( ! document.getElementById( 'menu-primary' ).contains( event.target ) ) {
-		document.getElementById( 'menu-primary' ).querySelectorAll( '.sub-menu-toggle' ).forEach( function( button ) {
-			button.setAttribute( 'aria-expanded', 'false' );
+	if ( ! document.getElementById( "menu-primary" ).contains( event.target ) ) {
+		document.getElementById( "menu-primary" ).querySelectorAll( ".sub-menu-toggle" ).forEach( function( button ) {
+			button.setAttribute( "aria-expanded", "false" );
 		} );
 	}
 }
@@ -26,15 +26,17 @@ function marianneCollapseMenuOnClickOutside( event ) {
  * @param {Element} el - The element.
  */
 function marianneToggleAriaExpanded( el, withListeners ) {
-	if ( 'true' !== el.getAttribute( 'aria-expanded' ) ) {
-		el.setAttribute( 'aria-expanded', 'true' );
+	if ( "true" !== el.getAttribute( "aria-expanded" ) ) {
+		el.setAttribute( "aria-expanded", "true" );
+
 		if ( withListeners ) {
-			document.addEventListener( 'click', marianneCollapseMenuOnClickOutside );
+			document.addEventListener( "click", marianneCollapseMenuOnClickOutside );
 		}
 	} else {
-		el.setAttribute( 'aria-expanded', 'false' );
+		el.setAttribute( "aria-expanded", "false" );
+
 		if ( withListeners ) {
-			document.addEventListener( 'click', marianneCollapseMenuOnClickOutside );
+			document.addEventListener( "click", marianneCollapseMenuOnClickOutside );
 		}
 	}
 }
@@ -45,28 +47,27 @@ function marianneToggleAriaExpanded( el, withListeners ) {
  * @param {Element} el - The element.
  */
 function marianneExpandSubMenu( el ) {
-
 	if ( window.matchMedia( "(min-width: 500px)" ).matches ) {
 		// Close other expanded items.
-		el.closest( 'nav' ).querySelectorAll( '.sub-menu-toggle' ).forEach( function( button ) {
+		el.closest( "nav" ).querySelectorAll( ".sub-menu-toggle" ).forEach( function( button ) {
 			if ( button !== el ) {
-				button.setAttribute( 'aria-expanded', 'false' );
+				button.setAttribute( "aria-expanded", "false" );
 			}
-		});
+		} );
 
 		// Toggle aria-expanded on the button.
 		marianneToggleAriaExpanded( el, true );
 
 		// On tab-away collapse the menu.
-		el.parentNode.querySelectorAll( 'ul > li:last-child > a' ).forEach( function( linkEl ) {
-			linkEl.addEventListener( 'blur', function( event ) {
+		el.parentNode.querySelectorAll( "ul > li:last-child > a" ).forEach( function( linkEl ) {
+			linkEl.addEventListener( "blur", function( event ) {
 				if ( ! el.parentNode.contains( event.relatedTarget ) ) {
-					el.setAttribute( 'aria-expanded', 'false' );
+					el.setAttribute( "aria-expanded", "false" );
 				}
-			});
-		});
+			} );
+		} );
 	} else {
-		el.removeAttribute( 'aria-haspopup' ).removeAttribute( 'aria-expanded' );
+		el.removeAttribute( "aria-haspopup" ).removeAttribute( "aria-expanded" );
 	}
 }
 
@@ -76,19 +77,25 @@ function marianneExpandSubMenu( el ) {
  * @param {Element} el - The element.
  */
 function marianneExpandMobileMenu( el ) {
-	if ( 'true' !== el.getAttribute( 'aria-expanded' ) ) {
-		el.setAttribute( 'aria-expanded', 'true' );
+	if ( "true" !== el.getAttribute( "aria-expanded" ) ) {
+		el.setAttribute( "aria-expanded", "true" );
 	} else {
-		el.setAttribute( 'aria-expanded', 'false' );
+		el.setAttribute( "aria-expanded", "false" );
 	}
 }
 
-( function ( $ ) {
+( function( $ ) {
 	// Adds role and tabindex to menu links.
-	var menu_elements = $( '#menu-primary .menu-item' );
+	var menu_elements = $( "#menu-primary .menu-item" );
+
 	menu_elements.each( function ( el, item ) {
-		$( item ).children( 'a' ).attr( 'role', 'menu-item' );
-		$( item ).children( 'a' ).attr( 'tabindex', '0' );
+		$( item )
+			.children( "a" )
+			.attr( "role", "menu-item" );
+
+		$( item )
+			.children( "a" )
+			.attr( "tabindex", "0" );
 	});
 
 	/**
@@ -97,92 +104,117 @@ function marianneExpandMobileMenu( el ) {
 	 * @param $id - The id of the primary menu.
 	 */
 	function marianneAriaMenu( $id ) {
-		var id = $id + ' ';
+		var id = $id + " ";
 
 		// On screen wider than 500px.
-		if ( ! window.matchMedia( '(max-width: 500px)' ).matches && ! window.matchMedia( '(hover: none)' ).matches ) {
+		if ( ! window.matchMedia( "(max-width: 500px)" ).matches
+			&& ! window.matchMedia( "(hover: none)" ).matches
+		) {
 
 			// Reset if the mobile menu was first displayed.
-			if ( ! $( id + '.sub-menu-toggle' ).attr( 'aria-haspopup' ) || ! $( id + '.sub-menu-toggle' ).attr( 'aria-expended' ) ) {
-				$( id + '.sub-menu-toggle' ).attr( 'aria-haspopup', 'true' );
-				$( id + '.sub-menu-toggle' ).attr( 'aria-expanded', 'false' );
+			if ( ! $( id + ".sub-menu-toggle" ).attr( "aria-haspopup" )
+				|| ! $( id + ".sub-menu-toggle" ).attr( "aria-expended" )
+			) {
+				$( id + ".sub-menu-toggle" ).attr( "aria-haspopup", "true" );
+				$( id + ".sub-menu-toggle" ).attr( "aria-expanded", "false" );
 			}
 
 			// On hover, set the aria-expanded attribute to true.
-			$( id + '.menu-item-has-children' ).hover( function () {
-				if ( $( this ).find( '.sub-menu-toggle' ).attr( 'aria-expanded') ) {
-					$( this ).find( '.sub-menu-toggle' ).attr( 'aria-expanded', 'true' );
+			$( id + ".menu-item-has-children" ).hover( function() {
+				if ( $( this ).find( ".sub-menu-toggle" ).attr( "aria-expanded") ) {
+					$( this )
+						.find( ".sub-menu-toggle" )
+						.attr( "aria-expanded", "true" );
 				}
-			}, function(){
-				if ( $( this ).find( '.sub-menu-toggle' ).attr( 'aria-expanded') ) {
-					$( this ).find( '.sub-menu-toggle' ).attr( 'aria-expanded', 'false' );
+			}, function() {
+				if ( $( this ).find( ".sub-menu-toggle" ).attr( "aria-expanded") ) {
+					$( this )
+						.find( ".sub-menu-toggle" )
+						.attr( "aria-expanded", "false" );
 				}
-			});
+			} );
 
 			// On submenu element focus, set the aria-expanded attribute to true.
-			$( id + '.sub-menu a' ).focus( function( event ) {
-				$( this ).parents( '.menu-item-has-children' ).find( '.sub-menu-toggle' )
-				if ( $( this ).parents( '.menu-item-has-children' ).find( '.sub-menu-toggle' ).attr( 'aria-expanded' ) ) {
-					$( this ).parents( '.menu-item-has-children' ).find( '.sub-menu-toggle' ).attr( 'aria-expanded', 'true' );
+			$( id + ".sub-menu a" ).focus( function() {
+				if ( $( this ).parents( ".menu-item-has-children" ).find( ".sub-menu-toggle" ).attr( "aria-expanded" ) ) {
+					$( this )
+						.parents( ".menu-item-has-children" )
+						.find( ".sub-menu-toggle" )
+						.attr( "aria-expanded", "true" );
 				}
-			});
-			$( id + '.sub-menu a' ).blur(function() {
-				if( $( this ).parents( '.menu-item-has-children' ).find( '.sub-menu-toggle' ).attr( 'aria-expanded' ) ) {
-					$( this ).parents( '.menu-item-has-children' ).find( '.sub-menu-toggle' ).attr( 'aria-expanded', 'false' );
+			} );
+
+			$( id + ".sub-menu a" ).blur( function() {
+				if ( $( this ).parents( ".menu-item-has-children" ).find( ".sub-menu-toggle" ).attr( "aria-expanded" ) ) {
+					$( this )
+						.parents( ".menu-item-has-children" )
+						.find( ".sub-menu-toggle" )
+						.attr( "aria-expanded", "false" );
 				}
-			});
+			} );
 
 			// On submenu button focus, set the aria-expanded attribute to true.
-			$( id + '.sub-menu-toggle' ).focus( function( event ) {
-				if ( $( this ).closest( '.menu-item-has-children' ).find( '.sub-menu-toggle' ).attr( 'aria-expanded' ) ) {
-					$( this ).closest( '.menu-item-has-children' ).find( '.sub-menu-toggle' ).attr( 'aria-expanded', 'true' );
+			$( id + ".sub-menu-toggle" ).focus( function() {
+				if ( $( this ).closest( ".menu-item-has-children" ).find( ".sub-menu-toggle" ).attr( "aria-expanded" ) ) {
+					$( this )
+						.closest( ".menu-item-has-children" )
+						.find( ".sub-menu-toggle" )
+						.attr( "aria-expanded", "true" );
 				}
-			});
-			$( id + '.sub-menu-toggle' ).blur(function() {
-				if ( $( this ).closest( '.menu-item-has-children' ).find( '.sub-menu-toggle' ).attr( 'aria-expanded' ) ) {
-					$( this ).closest( '.menu-item-has-children' ).find( '.sub-menu-toggle' ).attr( 'aria-expanded', 'false' );
+			} );
+
+			$( id + ".sub-menu-toggle" ).blur( function() {
+				if ( $( this ).closest( ".menu-item-has-children" ).find( ".sub-menu-toggle" ).attr( "aria-expanded" ) ) {
+					$( this )
+						.closest( ".menu-item-has-children" )
+						.find( ".sub-menu-toggle" )
+						.attr( "aria-expanded", "false" );
 				}
-			});
+			} );
 
 			// When esc key is pressed, set the aria-expanded attribute to false.
-			document.addEventListener( 'keydown', function( event ) {
+			document.addEventListener( "keydown", function( event ) {
 				var escKey = event.keyCode === 27;
+
 				if ( escKey ) {
-					$( '.sub-menu-toggle' ).attr( 'aria-expanded', 'false' );
+					$( ".sub-menu-toggle" ).attr( "aria-expanded", "false" );
 				}
-			});
+			} );
 
 		// On small screen.
 		} else {
-			$( id + '.sub-menu-toggle' ).removeAttr( 'aria-haspopup' );
-			$( id + '.sub-menu-toggle' ).removeAttr( 'aria-expanded' );
+			$( id + ".sub-menu-toggle" ).removeAttr( "aria-haspopup" );
+			$( id + ".sub-menu-toggle" ).removeAttr( "aria-expanded" );
 
-			$( '#menu-mobile-button' ).attr( 'aria-haspopup', 'true' ).attr( 'aria-expanded', 'false' );
+			$( "#menu-mobile-button" )
+				.attr( "aria-haspopup", "true" )
+				.attr( "aria-expanded", "false" );
 
 			// When esc key is pressed, hide menu.
 			$( document ).keydown( function( e ) {
 				var escKey = e.keyCode === 27;
+
 				if ( escKey ) {
-					$( '#menu-mobile-button' ).attr( 'aria-expanded', 'false' );
+					$( "#menu-mobile-button" ).attr( "aria-expanded", "false" );
 				}
-			});
+			} );
 
 			$( document ).mouseup( function( e ) {
-				var container = $( '#menu-primary-container' );
+				var container = $( "#menu-primary-container" );
 
-				if ( ! container.is( e.target ) && container.has( e.target ).length === 0) {
-					$( '#menu-mobile-button' ).attr( 'aria-expanded', 'false' );
+				if ( ! container.is( e.target ) && container.has( e.target ).length === 0 ) {
+					$( "#menu-mobile-button" ).attr( "aria-expanded", "false" );
 				}
-			});
+			} );
 		}
 	}
 
-	$( window ).on( 'load', function() {
-		marianneAriaMenu( '#menu-primary' );
-	});
+	$( window ).on( "load", function() {
+		marianneAriaMenu( "#menu-primary" );
+	} );
 
-	$( window ).on( 'resize', function() {
-		marianneAriaMenu( '#menu-primary' );
-	});
+	$( window ).on( "resize", function() {
+		marianneAriaMenu( "#menu-primary" );
+	} );
 
 } )( jQuery );

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
assets/js/navigation.min.js


+ 6 - 7
comments.php

@@ -1,9 +1,9 @@
 <?php
 /**
- * The template for displaying comments
+ * The template for displaying comments.
  *
- * Displays an area that contains both the current comments
- * and the comment form.
+ * Displays an area that contains both
+ * the current comments and the comment form.
  *
  * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
  *
@@ -26,14 +26,12 @@ if ( post_password_required() ) {
 <?php if ( have_comments() ) : ?>
 	<div id="comments" class="comments-area">
 		<?php
-		$marianne_comments_number = absint( get_comments_number() );
-
 		$marianne_comment_title = sprintf(
 			esc_html(
 				/* translators: %d: comment count number. */
-				_n( '%d comment', '%d comments', $marianne_comments_number, 'marianne' )
+				_n( '%d comment', '%d comments', absint( get_comments_number() ), 'marianne' )
 			),
-			number_format_i18n( $marianne_comments_number )
+			number_format_i18n( get_comments_number() )
 		);
 		?>
 
@@ -45,6 +43,7 @@ if ( post_password_required() ) {
 			'prev_text' => esc_html__( 'Older comments &rsaquo;', 'marianne' ),
 			'next_text' => esc_html__( '&lsaquo; Newer comments', 'marianne' ),
 		);
+
 		the_comments_navigation( $marianne_nav_args );
 		?>
 

+ 20 - 31
footer.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * The template for displaying the footer
+ * The template for displaying the footer.
  *
  * Contains the closing of the #page div and all content after.
  *
@@ -14,42 +14,31 @@
 			<footer class="site-footer text-secondary" role="contentinfo">
 				<div class="site-footer-block">
 					<?php
-					$marianne_site_name = '<em>' . get_bloginfo( 'name', 'display' ) . '</em>';
-
-					$marianne_wp_link  = '<a href="' . esc_url( __( 'https://wordpress.org/', 'marianne' ) ) . '">';
-					$marianne_wp_link .= 'WordPress';
-					$marianne_wp_link .= '</a>';
-
-					$marianne_theme_info = wp_get_theme();
-					$marianne_theme_name = $marianne_theme_info->get( 'Name' );
-
 					printf(
-						/* translators: $1%s: WordPress. $2%s: Marianne */
+						/* translators: $1%s: Site name. $2%s: WordPress. $3%s: Marianne. */
 						esc_html_x( '%1$s is proudly powered by %2$s and %3$s', 'Site footer text', 'marianne' ),
-						$marianne_site_name,
-						$marianne_wp_link,
-						esc_html( $marianne_theme_name )
+						get_bloginfo( 'name', 'display' ),
+						'<a href="' . esc_url( __( 'https://wordpress.org/', 'marianne' ) ) . '">WordPress</a>',
+						esc_html( wp_get_theme()->get( 'Name' ) )
 					);
 					?>
 				</div>
 
-				<?php
-				if ( has_nav_menu( 'footer' ) ) {
-					echo '<nav id="menu-footer-container" class="site-footer-block" role="navigation" aria-label="' . esc_attr__( 'Footer Menu', 'marianne' ) . '">';
-
-					wp_nav_menu(
-						array(
-							'container'      => '',
-							'depth'          => 1,
-							'menu_class'     => 'navigation-menu',
-							'menu_id'        => 'menu-footer',
-							'theme_location' => 'footer',
-						)
-					);
-
-					echo '</nav>';
-				}
-				?>
+				<?php if ( has_nav_menu( 'footer' ) ) : ?>
+					<nav id="menu-footer-container" class="site-footer-block" role="navigation" aria-label="<?php echo esc_attr__( 'Footer Menu', 'marianne' ); ?>">
+						<?php
+						wp_nav_menu(
+							array(
+								'container'      => '',
+								'depth'          => 1,
+								'menu_class'     => 'navigation-menu',
+								'menu_id'        => 'menu-footer',
+								'theme_location' => 'footer',
+							)
+						);
+						?>
+					</nav>
+				<?php endif; ?>
 
 				<?php wp_footer(); ?>
 			</footer>

+ 36 - 41
functions.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * Functions and definitions
+ * Functions and definitions.
  *
  * @link https://developer.wordpress.org/themes/basics/theme-functions/
  *
@@ -109,16 +109,17 @@ if ( ! function_exists( 'marianne_environment_type' ) ) {
 
 if ( ! function_exists( 'marianne_minify' ) ) {
 	/**
-	 * Display ".min" if the environment is set to "production".
+	 * Displays ".min" if the environment is set to "production".
 	 *
 	 * @return string Returns ".min" or nothing.
 	 */
 	function marianne_minify() {
 		$environment_type = marianne_environment_type();
 
-		$min = '';
 		if ( 'production' === $environment_type ) {
 			$min = '.min';
+		} else {
+			$min = '';
 		}
 
 		return $min;
@@ -129,29 +130,20 @@ if ( ! function_exists( 'marianne_styles_scripts' ) ) {
 	/**
 	 * Enqueue scripts and styles.
 	 *
+	 * On production, minified files are enqueued.
+	 *
 	 * @return void
 	 */
 	function marianne_styles_scripts() {
-		$theme_info    = wp_get_theme();
-		$theme_version = $theme_info->get( 'Version' );
-		$min           = marianne_minify();
+		$theme_version = wp_get_theme()->get( 'Version' );
+		$min           = esc_attr( marianne_minify() );
 
-		/**
-		 * The main stylesheet.
-		 *
-		 * On production, the minified stylesheet is enqueued.
-		 *
-		 * @see marianne_minify()
-		 */
+		// The main stylesheet.
 		wp_enqueue_style( 'marianne-stylesheet', esc_url( get_template_directory_uri() . "/style$min.css" ), array(), esc_attr( $theme_version ) );
 
 		/**
 		 * The main menu navigation script.
 		 *
-		 * On production, the minified script is enqueued.
-		 *
-		 * @see marianne_minify()
-		 *
 		 * @since Marianne 1.2
 		 */
 		wp_enqueue_script( 'marianne-navigation', esc_url( get_template_directory_uri() . "/assets/js/navigation$min.js" ), array( 'jquery' ), esc_attr( $theme_version ), true );
@@ -203,32 +195,35 @@ if ( ! function_exists( 'marianne_widgets' ) ) {
 	add_action( 'widgets_init', 'marianne_widgets' );
 }
 
-/**
- * Add a button to top-level menu items that has sub-menus.
- * An icon is added using CSS depending on the value of aria-expanded.
- *
- * Based on the work of the WordPress team in the Twenty Twenty-One Theme.
- *
- * @param string $output Nav menu item start element.
- * @param object $item   Nav menu item.
- * @param int    $depth  Depth.
- * @param object $args   Nav menu args.
- *
- * @return string Nav menu item start element.
- */
-function marianne_add_sub_menu_toggle( $output, $item, $depth, $args ) {
-	if ( 0 === $depth && in_array( 'menu-item-has-children', $item->classes, true ) && 'primary' === $args->theme_location ) {
-
-		// Add toggle button.
-		$output .= '<button class="sub-menu-toggle" aria-haspopup="true" aria-expanded="false" onClick="marianneExpandSubMenu(this)">';
-		$output .= '+';
-		$output .= '<span class="screen-reader-text">' . esc_html__( 'Open submenu', 'marianne' ) . '</span>';
-		$output .= '</button>';
+if ( ! function_exists( 'marianne_add_sub_menu_toggle' ) ) {
+	/**
+	 * Add a button to top-level menu items that has sub-menus.
+	 * An icon is added using CSS depending on the value of aria-expanded.
+	 *
+	 * Based on the work of the WordPress team in the Twenty Twenty-One Theme.
+	 *
+	 * @param string $output Nav menu item start element.
+	 * @param object $item   Nav menu item.
+	 * @param int    $depth  Depth.
+	 * @param object $args   Nav menu args.
+	 *
+	 * @return string Nav menu item start element.
+	 */
+	function marianne_add_sub_menu_toggle( $output, $item, $depth, $args ) {
+		if ( 0 === $depth && in_array( 'menu-item-has-children', $item->classes, true ) && 'primary' === $args->theme_location ) {
+
+			// Add toggle button.
+			$output .= '<button class="sub-menu-toggle" aria-haspopup="true" aria-expanded="false" onClick="marianneExpandSubMenu(this)">';
+			$output .= '+';
+			$output .= '<span class="screen-reader-text">' . esc_html__( 'Open submenu', 'marianne' ) . '</span>';
+			$output .= '</button>';
+		}
+
+		return $output;
 	}
 
-	return $output;
+	add_filter( 'walker_nav_menu_start_el', 'marianne_add_sub_menu_toggle', 10, 4 );
 }
-add_filter( 'walker_nav_menu_start_el', 'marianne_add_sub_menu_toggle', 10, 4 );
 
 // Load required files.
-require_once get_template_directory() . '/inc/template-tags.php';
+require_once( get_template_directory() . '/inc/template-tags.php' );

+ 3 - 4
header.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * The header
+ * The template for displaying the header.
  *
  * This is the template that displays all of the <head> section,
  * the site branding (logo, title, description) and the main menu.
@@ -12,6 +12,7 @@
  */
 
 ?>
+
 <!DOCTYPE html>
 <html <?php language_attributes(); ?>>
 	<head>
@@ -25,9 +26,7 @@
 		}
 		?>
 
-		<a class="skip-link screen-reader-text" href="#content">
-			<?php esc_html_e( 'Skip to content', 'marianne' ); ?>
-		</a>
+		<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'marianne' ); ?></a>
 
 		<div id="page" class="site">
 			<header id="header" class="site-header" role="banner">

+ 95 - 80
inc/template-tags.php

@@ -16,20 +16,25 @@ if ( ! function_exists( 'marianne_logo' ) ) {
 	 */
 	function marianne_logo() {
 		if ( has_custom_logo() ) {
-			echo '<div class="site-logo">';
-			the_custom_logo();
-			echo '</div>';
+			?>
+				<div class="site-logo">
+					<?php the_custom_logo(); ?>
+				</div>
+			<?php
 		}
 	}
 }
 
 if ( ! function_exists( 'marianne_site_title' ) ) {
 	/**
-	 * The title of the site
+	 * The title of the site.
 	 *
 	 * Puts the title in a h1 or a p tag depending on the context.
 	 *
 	 * @param string $class The class of the title.
+	 *                      To set multiple classes,
+	 *                      separate them with a space.
+	 *                      Example: $class = "class-1 class-2".
 	 *
 	 * @return void
 	 */
@@ -65,6 +70,9 @@ if ( ! function_exists( 'marianne_site_description' ) ) {
 	 * Puts the description in a h2 or a p tag depending on the context.
 	 *
 	 * @param string $class The class of the description.
+	 *                      To set multiple classes,
+	 *                      separate them with a space.
+	 *                      Example: $class = "class-1 class-2".
 	 *
 	 * @return void
 	 */
@@ -93,38 +101,44 @@ if ( ! function_exists( 'marianne_menu_primary' ) ) {
 	 */
 	function marianne_menu_primary() {
 		if ( has_nav_menu( 'primary' ) ) {
-			echo '<nav id="menu-primary-container" role="navigation" aria-label="' . esc_attr__( 'Primary Menu', 'marianne' ) . '">';
-
-			echo '<button id="menu-mobile-button" onclick="marianneExpandMobileMenu(this)">' . esc_html__( 'Menu', 'marianne' ) . '</button>';
-
-			wp_nav_menu(
-				array(
-					'container'      => '',
-					'depth'          => 2,
-					'item_spacing'   => 'discard',
-					'menu_class'     => 'navigation-menu',
-					'menu_id'        => 'menu-primary',
-					'theme_location' => 'primary',
-				)
-			);
-
-			echo '</nav>';
+			?>
+				<nav id="menu-primary-container" role="navigation" aria-label="<?php echo esc_attr__( 'Primary Menu', 'marianne' ); ?>">
+					<button id="menu-mobile-button" onclick="marianneExpandMobileMenu(this)"><?php esc_html_e( 'Menu', 'marianne' ); ?></button>
+
+					<?php
+					wp_nav_menu(
+						array(
+							'container'      => '',
+							'depth'          => 2,
+							'item_spacing'   => 'discard',
+							'menu_class'     => 'navigation-menu',
+							'menu_id'        => 'menu-primary',
+							'theme_location' => 'primary',
+						)
+					);
+					?>
+				</nav>
+			<?php
 		}
 	}
 }
 
 if ( ! function_exists( 'marianne_the_date' ) ) {
 	/**
-	 * Displays the publish date of a post
 	 *
-	 * @param string $class If a class is set, the date will be displayed within a <div>.
+	 * The date on which the post was published.
+	 *
+	 * @param string $class The class of the date.
+	 *                      To set multiple classes,
+	 *                      separate them with a space.
+	 *                      Example: $class = "class-1 class-2".
 	 *
 	 * @return void
 	 */
 	function marianne_the_date( $class = 'entry-date' ) {
 		?>
 			<time class="<?php echo esc_attr( $class ); ?>" datetime="<?php echo esc_attr( get_the_date( 'c' ) ); ?>">
-				<?php echo esc_html( get_the_date() ); ?>
+				<?php the_date(); ?>
 			</time>
 		<?php
 	}
@@ -132,29 +146,34 @@ if ( ! function_exists( 'marianne_the_date' ) ) {
 
 if ( ! function_exists( 'marianne_loop_comments' ) ) {
 	/**
-	 * Link to comments
+	 * The link to comments.
 	 *
-	 * @param string $container Wrap the link in a 'div' or 'footer' block… or nothing (default).
-	 * @param string $class     The class added to the container.
+	 * @param string $container Wrap the link in a 'div' or 'footer' block.
+	 *                          This parameter can be empty.
+	 * @param string $class     The class of the container.
+	 *                          To set multiple classes,
+	 *                          separate them with a space.
+	 *                          Example: $class = "class-1 class-2".
 	 *
 	 * @return void
 	 */
 	function marianne_loop_comments( $container = '', $class = '' ) {
 		$comments_number = get_comments_number();
 
-		$allowed_containers = array( 'div', 'footer' );
-		$container_open     = '';
-		$container_close    = '';
-
+		// Displays the comment link it there is at least one comment.
 		if ( $comments_number && 0 < $comments_number ) :
-			?>
+			// 'div' and 'footer' are the only arguments that can be defined through $container.
+			$allowed_containers = array( 'div', 'footer' );
+			$container_open     = '';
+			$container_close    = '';
 
-			<?php
 			if ( $container && in_array( $container, $allowed_containers, true ) ) {
 				$container_open = '<' . esc_attr( $container );
+
 				if ( $class ) {
 					$container_open .= ' class="' . esc_attr( $class ) . '"';
 				}
+
 				$container_open .= '>';
 
 				$container_close = '</' . esc_attr( $container ) . '>';
@@ -165,7 +184,7 @@ if ( ! function_exists( 'marianne_loop_comments' ) ) {
 				<a href="<?php echo esc_url( get_comments_link() ); ?>">
 					<?php
 					printf(
-						/* translators: %d: comment count number. */
+						/* translators: %d: Comment count number. */
 						esc_html( _n( '%d comment', '%d comments', absint( $comments_number ), 'marianne' ) ),
 						absint( $comments_number )
 					);
@@ -207,7 +226,6 @@ if ( ! function_exists( 'marianne_loop_navigation' ) ) {
 							<?php esc_html_e( 'Next page &rsaquo;', 'marianne' ); ?>
 						</a>
 					<?php } ?>
-
 				</div>
 			<?php
 		}
@@ -216,14 +234,16 @@ if ( ! function_exists( 'marianne_loop_navigation' ) ) {
 
 if ( ! function_exists( 'marianne_the_categories' ) ) {
 	/**
-	 * The list of categories of a post
+	 * The list of categories of a post.
 	 *
-	 * @param string $class Add a class to the list.
+	 * @param string $class The class of the list of categories.
+	 *                      To set multiple classes,
+	 *                      separate them with a space.
+	 *                      Example: $class = "class-1 class-2".
 	 *
 	 * @return void
 	 */
 	function marianne_the_categories( $class = '' ) {
-		// If a class is set, create the attribute with its value.
 		$class = 'list-inline ' . $class;
 
 		$categories = get_the_category( get_the_ID() );
@@ -233,22 +253,19 @@ if ( ! function_exists( 'marianne_the_categories' ) ) {
 			$i         = 0;
 			?>
 				<ul class="<?php echo esc_attr( $class ); ?>">
-					<?php
-					foreach ( $categories as $category ) {
-						$i++;
-						?>
-							<li>
-								<a href="<?php echo esc_url( get_category_link( $category->cat_ID ) ); ?>"><?php echo esc_html( $category->cat_name ); ?></a>
-
-								<?php
-								if ( $i !== $cat_count ) {
-									' &middot;';
-								}
-								?>
-							</li>
-						<?php
-					}
-					?>
+					<?php foreach ( $categories as $category ) : ?>
+						<li>
+							<a href="<?php echo esc_url( get_category_link( $category->cat_ID ) ); ?>"><?php echo esc_html( $category->cat_name ); ?></a>
+
+							<?php
+							$i++;
+
+							if ( $i !== $cat_count ) {
+								' &middot;';
+							}
+							?>
+						</li>
+					<?php endforeach; ?>
 				</ul>
 			<?php
 		}
@@ -259,55 +276,53 @@ if ( ! function_exists( 'marianne_the_post_thumbnail' ) ) {
 	/**
 	 * The post thumbnail.
 	 *
-	 * @param string       $class The class of the figure.
-	 * @param string|array $args  Options to activate.
-	 *                            'link' adds a clickable permalink to the image.
-	 *                            'caption' displays the caption below the image.
+	 * @param string $class The class of the list of categories.
+	 *                      To set multiple classes,
+	 *                      separate them with a space.
+	 *                      Example: $class = "class-1 class-2".
+	 * @param array  $args  Options to activate:
+	 *                          - 'link' adds a clickable permalink to the image.
+	 *                          - 'caption' displays the caption below the image.
 	 *
 	 * @return void
 	 */
-	function marianne_the_post_thumbnail( $class = '', $args = '' ) {
-		if ( has_post_thumbnail() ) :
+	function marianne_the_post_thumbnail( $class = '', $args = array() ) {
+		if ( has_post_thumbnail() ) {
 
 			// If a class is set, create the attribute with its value.
-			if ( esc_attr( $class ) ) {
+			if ( $class ) {
 				$class = ' class="' . esc_attr( $class ) . '"';
 			}
 
 			// Options available.
-			$allowed_args = array( 'link', 'caption' );
+			$allowed_options = array( 'link', 'caption' );
+
+			$before = '';
+			$after  = '';
+			if ( in_array( 'link', $allowed_options, true ) ) {
+				$before = '<a href="' . esc_url( get_the_permalink() ) . '">';
+				$after  = '</a>';
+			}
 
 			// Put the option(s) defined with $args in the array $options.
 			$options = array();
-
-			if ( ! is_array( $args ) ) {
-				if ( in_array( $args, $allowed_args, true ) ) {
-					$options[] = $args;
-				}
-			} else {
-				foreach ( $args as $option ) {
-					$options[] = $option;
-				}
-			}
 			?>
 				<figure<?php echo $class; ?>>
-					<?php if ( in_array( 'link', $options, true ) ) : ?>
-						<a href="<?php the_permalink(); ?>">
-					<?php endif; ?>
+					<?php
+					echo $before;
 
-					<?php the_post_thumbnail( 'marianne-thumbnails' ); ?>
+					the_post_thumbnail( 'marianne-thumbnails' );
 
-					<?php if ( in_array( 'link', $options, true ) ) : ?>
-						</a>
-					<?php endif; ?>
+					echo $after;
+					?>
 
-					<?php if ( in_array( 'caption', $options, true ) && wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
+					<?php if ( in_array( 'caption', $allowed_options, true ) && wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
 						<figcaption class="wp-caption-text text-secondary">
 							<?php echo wp_kses_post( wp_get_attachment_caption( get_post_thumbnail_id() ) ); ?>
 						</figcaption>
 					<?php endif; ?>
 				</figure>
 			<?php
-		endif;
+		}
 	}
 }

+ 4 - 4
index.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * The main template file
+ * The main template file.
  *
  * This is the most generic template file in a WordPress theme
  * and one of the two required files for a theme (the other being style.css).
@@ -23,11 +23,11 @@ get_header();
 				<?php
 				the_archive_title( '<h1 class="page-title">', '</h1>' );
 
-				$marianne_archive_description = get_the_archive_description();
-				if ( $marianne_archive_description ) {
+				$description = get_the_archive_description();
+				if ( $description ) {
 					?>
 						<div class="archive-description">
-							<?php echo wp_kses_post( wpautop( $marianne_archive_description ) ); ?>
+							<?php echo wp_kses_post( wpautop( $description ) ); ?>
 						</div>
 					<?php
 				}

BIN
languages/fr_FR.mo


+ 23 - 21
languages/fr_FR.po

@@ -1,8 +1,8 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: Marianne\n"
-"POT-Creation-Date: 2021-03-17 12:57+0100\n"
-"PO-Revision-Date: 2021-03-17 12:57+0100\n"
+"POT-Creation-Date: 2021-03-17 20:28+0100\n"
+"PO-Revision-Date: 2021-03-17 20:29+0100\n"
 "Last-Translator: \n"
 "Language-Team: Français\n"
 "Language: fr_FR\n"
@@ -21,45 +21,46 @@ msgstr ""
 "X-Poedit-SearchPathExcluded-0: *.js\n"
 
 #. translators: %d: comment count number.
-#: comments.php:34 inc/template-tags.php:169
+#. translators: %d: Comment count number.
+#: comments.php:32 inc/template-tags.php:188
 #, php-format
 msgid "%d comment"
 msgid_plural "%d comments"
 msgstr[0] "%d commentaire"
 msgstr[1] "%d commentaires"
 
-#: comments.php:45
+#: comments.php:43
 msgid "Older comments &rsaquo;"
 msgstr "Commentaires plus anciens &rsaquo;"
 
-#: comments.php:46
+#: comments.php:44
 msgid "&lsaquo; Newer comments"
 msgstr "&lsaquo; Commentaires plus récents"
 
+#. translators: $1%s: Site name. $2%s: WordPress. $3%s: Marianne.
 #: footer.php:19
-msgid "https://wordpress.org/"
-msgstr "https://fr.wordpress.org/"
-
-#. translators: $1%s: WordPress. $2%s: Marianne
-#: footer.php:28
 #, php-format
 msgctxt "Site footer text"
 msgid "%1$s is proudly powered by %2$s and %3$s"
 msgstr "%1$s est fièrement propulsé par %2$s et %3$s"
 
-#: footer.php:38 functions.php:55
+#: footer.php:21
+msgid "https://wordpress.org/"
+msgstr "https://fr.wordpress.org/"
+
+#: footer.php:28 functions.php:55
 msgid "Footer Menu"
 msgstr "Menu du pied de page"
 
-#: functions.php:54 inc/template-tags.php:96
+#: functions.php:54 inc/template-tags.php:105
 msgid "Primary Menu"
 msgstr "Menu principal"
 
-#: functions.php:193
+#: functions.php:185
 msgid "Widgets"
 msgstr "Widgets"
 
-#: functions.php:225
+#: functions.php:218
 msgid "Open submenu"
 msgstr "Ouvrir le sous-menu"
 
@@ -67,36 +68,37 @@ msgstr "Ouvrir le sous-menu"
 msgid "Skip to content"
 msgstr "Aller au contenu"
 
-#: inc/template-tags.php:98
+#: inc/template-tags.php:106
 msgid "Menu"
 msgstr "Menu"
 
-#: inc/template-tags.php:201
+#: inc/template-tags.php:220
 msgid "&lsaquo; Previous page"
 msgstr "&lsaquo; Page précédente"
 
-#: inc/template-tags.php:207
+#: inc/template-tags.php:226
 msgid "Next page &rsaquo;"
 msgstr "Page suivante &rsaquo;"
 
 #. translators: %s: search term.
-#: search.php:22 search.php:65
+#: search.php:22 search.php:64
 #, php-format
 msgid "Search for \"%s\""
 msgstr "Recherche de «&nbsp;%s&nbsp;»"
 
 #: search.php:35
 #, php-format
+msgctxt "Search results"
 msgid "%d result found:"
 msgid_plural "%d results found:"
 msgstr[0] "%d résultat trouvé&nbsp;:"
 msgstr[1] "%d résultats trouvés&nbsp;:"
 
-#: search.php:73
+#: search.php:71
 msgid "No results."
 msgstr "Aucun résultat."
 
-#: search.php:81
+#: search.php:77
 msgid "Maybe try a search?"
 msgstr "Peut-être devriez-vous tenter une recherche&nbsp;?"
 
@@ -108,7 +110,7 @@ msgstr "Article sélectionné"
 msgid "Nothing here"
 msgstr "Il n’y a rien ici"
 
-#: template-parts/content-none.php:22
+#: template-parts/content-none.php:21
 msgid "It looks like nothing was found at this location. Maybe try a search?"
 msgstr ""
 "On dirait que rien n’a été trouvé ici. Essayez peut-être une recherche&nbsp;?"

+ 22 - 21
languages/marianne.pot

@@ -4,7 +4,7 @@ msgstr ""
 "Project-Id-Version: "
 "Marianne\n"
 "POT-Creation-Date: "
-"2021-03-17 12:57+0100\n"
+"2021-03-17 20:28+0100\n"
 "PO-Revision-Date: \n"
 "Last-Translator: Teddy\n"
 "Language-Team: Teddy\n"
@@ -41,30 +41,25 @@ msgstr ""
 "X-Poedit-"
 "SearchPath-0: .\n"
 
-#: comments.php:34
-#: inc/template-tags.php:169
+#: comments.php:32
+#: inc/template-tags.php:188
 #, php-format
 msgid "%d comment"
 msgid_plural "%d comments"
 msgstr[0] ""
 msgstr[1] ""
 
-#: comments.php:45
+#: comments.php:43
 msgid ""
 "Older comments &rsaquo;"
 msgstr ""
 
-#: comments.php:46
+#: comments.php:44
 msgid ""
 "&lsaquo; Newer comments"
 msgstr ""
 
 #: footer.php:19
-msgid ""
-"https://wordpress.org/"
-msgstr ""
-
-#: footer.php:28
 #, php-format
 msgctxt "Site footer text"
 msgid ""
@@ -72,21 +67,26 @@ msgid ""
 "by %2$s and %3$s"
 msgstr ""
 
-#: footer.php:38
+#: footer.php:21
+msgid ""
+"https://wordpress.org/"
+msgstr ""
+
+#: footer.php:28
 #: functions.php:55
 msgid "Footer Menu"
 msgstr ""
 
 #: functions.php:54
-#: inc/template-tags.php:96
+#: inc/template-tags.php:105
 msgid "Primary Menu"
 msgstr ""
 
-#: functions.php:193
+#: functions.php:185
 msgid "Widgets"
 msgstr ""
 
-#: functions.php:225
+#: functions.php:218
 msgid "Open submenu"
 msgstr ""
 
@@ -94,38 +94,39 @@ msgstr ""
 msgid "Skip to content"
 msgstr ""
 
-#: inc/template-tags.php:98
+#: inc/template-tags.php:106
 msgid "Menu"
 msgstr ""
 
-#: inc/template-tags.php:201
+#: inc/template-tags.php:220
 msgid ""
 "&lsaquo; Previous page"
 msgstr ""
 
-#: inc/template-tags.php:207
+#: inc/template-tags.php:226
 msgid "Next page &rsaquo;"
 msgstr ""
 
 #: search.php:22
-#: search.php:65
+#: search.php:64
 #, php-format
 msgid "Search for \"%s\""
 msgstr ""
 
 #: search.php:35
 #, php-format
+msgctxt "Search results"
 msgid "%d result found:"
 msgid_plural ""
 "%d results found:"
 msgstr[0] ""
 msgstr[1] ""
 
-#: search.php:73
+#: search.php:71
 msgid "No results."
 msgstr ""
 
-#: search.php:81
+#: search.php:77
 msgid "Maybe try a search?"
 msgstr ""
 
@@ -138,7 +139,7 @@ msgstr ""
 msgid "Nothing here"
 msgstr ""
 
-#: template-parts/content-none.php:22
+#: template-parts/content-none.php:21
 msgid ""
 "It looks like nothing "
 "was found at this "

+ 1 - 1
loop.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * The loop
+ * The loop.
  *
  * The loop displays the list of posts.
  *

+ 1 - 1
page.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * The template for displaying all single pages
+ * The template for displaying all single pages.
  *
  * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-page
  *

+ 8 - 14
search.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * The template for displaying search results pages
+ * The template for displaying search results pages.
  *
  * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
  *
@@ -28,17 +28,18 @@ get_header();
 				<div class="archive-description">
 					<p>
 						<?php
-						printf(
+						$description = sprintf(
 							esc_html(
 								/* translators: %d: the number of search results. */
-								_n(
+								_nx(
 									'%d result found:',
 									'%d results found:',
-									absint( $wp_query->found_posts ),
+									(int) $wp_query->found_posts,
+									'Search results',
 									'marianne'
 								)
 							),
-							absint( $wp_query->found_posts )
+							(int) $wp_query->found_posts
 						);
 						?>
 					</p>
@@ -54,9 +55,7 @@ get_header();
 
 			marianne_loop_navigation();
 			?>
-
 		<?php else : ?>
-
 			<header class="archive-header">
 				<h1 class="page-title">
 					<?php
@@ -69,22 +68,17 @@ get_header();
 				</h1>
 
 				<div class="archive-description">
-					<p>
-						<?php esc_html_e( 'No results.', 'marianne' ); ?>
-					</p>
+					<p><?php esc_html_e( 'No results.', 'marianne' ); ?></p>
 				</div>
 			</header>
 
 			<article <?php post_class( 'entry-page' ); ?>>
 				<section class="entry-content page-content">
-					<p>
-						<?php esc_html_e( 'Maybe try a search?', 'marianne' ); ?>
-					</p>
+					<p><?php esc_html_e( 'Maybe try a search?', 'marianne' ); ?></p>
 
 					<?php get_search_form(); ?>
 				</section>
 			</article>
-
 		<?php endif; ?>
 	</main>
 

+ 1 - 1
sidebar.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * The sidebar
+ * The template for displaying the sidebar.
  *
  * Displays the sidebar at the bottom of the page,
  * in the #content div and before the footer.

+ 1 - 1
single.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * The template for displaying all single posts
+ * The template for displaying all single posts.
  *
  * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
  *

+ 4 - 8
template-parts/content-loop.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * Template part for displaying posts in the loop
+ * Template part for displaying posts in the loop.
  *
  * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
  *
@@ -19,20 +19,16 @@
 		<?php endif; ?>
 
 		<div class="entry-meta text-secondary">
-			<a href="<?php the_permalink(); ?>">
-				<?php marianne_the_date(); ?>
-			</a>
+			<a href="<?php the_permalink(); ?>"><?php marianne_the_date(); ?></a>
 		</div>
 
 		<?php marianne_the_categories( 'entry-meta text-secondary' ); ?>
 
 		<h3 class="entry-title loop-title">
-			<a href="<?php the_permalink(); ?>">
-				<?php the_title(); ?>
-			</a>
+			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
 		</h3>
 
-		<?php marianne_the_post_thumbnail( 'entry-thumbnail loop-thumbnail', 'link' ); ?>
+		<?php marianne_the_post_thumbnail( 'entry-thumbnail loop-thumbnail', array( 'link' ) ); ?>
 	</header>
 
 	<section class="entry-content loop-content">

+ 2 - 4
template-parts/content-none.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * Template part for displaying a message that posts cannot be found
+ * Template part for displaying a message that posts cannot be found.
  *
  * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
  *
@@ -18,9 +18,7 @@
 	</header>
 
 	<section class="entry-content page-content">
-		<p>
-			<?php esc_html_e( 'It looks like nothing was found at this location. Maybe try a search?', 'marianne' ); ?>
-		</p>
+		<p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try a search?', 'marianne' ); ?></p>
 
 		<?php get_search_form(); ?>
 	</section>

+ 1 - 1
template-parts/content-page.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * Template part for displaying pages
+ * Template part for displaying pages.
  *
  * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
  *

+ 2 - 2
template-parts/content-single.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * Template part for displaying posts
+ * Template part for displaying posts.
  *
  * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
  *
@@ -25,7 +25,7 @@
 
 		the_title( '<h1 class="entry-title post-title">', '</h1>' );
 
-		marianne_the_post_thumbnail( 'entry-thumbnail post-thumbnail', 'caption' );
+		marianne_the_post_thumbnail( 'entry-thumbnail post-thumbnail', array( 'caption' ) );
 		?>
 	</header>
 

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff