Преглед на файлове

Begin refactor to more closely match #2985

Kjell Reigstad преди 4 години
родител
ревизия
007f935b85

+ 21 - 16
varia/footer.php

@@ -21,24 +21,29 @@
 		$template = new A8C\FSE\WP_Template();
 		$template->output_template_content( A8C\FSE\WP_Template::FOOTER );
 	else : // Otherwise we'll fallback to the default Varia footer below. ?>
+
 	<footer id="colophon" class="site-footer responsive-max-width">
-	<?php
-		get_template_part( 'template-parts/footer/footer', 'widgets' );
+			<?php
+			if ( ! ( true === get_theme_mod( 'hide_site_footer', false ) && is_front_page() && is_page() ) ) : // If this is the homepage and the footer elements are set to hide, don't load this part.
+
+				get_template_part( 'template-parts/footer/footer', 'widgets' );
+
+				if ( has_nav_menu( 'menu-2' ) ) : ?>
+					<nav class="footer-navigation" aria-label="<?php esc_attr_e( 'Footer Menu', 'varia' ); ?>">
+						<?php
+						wp_nav_menu(
+							array(
+								'theme_location' => 'menu-2',
+								'menu_class'     => 'footer-menu',
+								'depth'          => 1,
+							)
+						);
+						?>
+					</nav><!-- .footer-navigation -->
+				<?php endif;
+			endif; ?>
 
-		if ( has_nav_menu( 'menu-2' ) ) : ?>
-			<nav class="footer-navigation" aria-label="<?php esc_attr_e( 'Footer Menu', 'varia' ); ?>">
-				<?php
-				wp_nav_menu(
-					array(
-						'theme_location' => 'menu-2',
-						'menu_class'     => 'footer-menu',
-						'depth'          => 1,
-					)
-				);
-				?>
-			</nav><!-- .footer-navigation -->
-		<?php endif;
-	endif; ?>
+		<?php endif; ?>
 
 		<div class="site-info">
 			<?php $blog_info = get_bloginfo( 'name' ); ?>

+ 48 - 0
varia/functions.php

@@ -357,6 +357,54 @@ function varia_mobile_nav_on_side_setup() {
 	add_action( 'wp_enqueue_scripts', 'varia_add_mobile_nav_on_side_scripts' );
 }
 
+/**
+ * Add ability to show or hide header and footer elements on the homepage.
+ */
+function varia_customize_header_footer( $wp_customize ) {
+
+	// Add setting to hide the site header on the homepage.
+	$wp_customize->add_setting( 'hide_site_header', array(
+		'default'              => false,
+		'type'                 => 'theme_mod',
+		'transport'            => 'refresh',
+		'sanitize_callback'    => 'varia_sanitize_checkbox',
+	) );
+
+	// Add control to hide the site header on the homepage.
+	$wp_customize->add_control( 'hide_site_header', array(
+		'label'		  => esc_html__( 'Hide the Site Header', 'seedlet' ),
+		'description' => esc_html__( 'Check to hide the site header, if your homepage is set to display a static page.', 'seedlet' ),
+		'section'	  => 'static_front_page',
+		'priority'	  => 10,
+		'type'		  => 'checkbox',
+		'settings'	  => 'hide_site_header',
+	) );
+
+	// Add setting to hide footer elements on the homepage.
+	$wp_customize->add_setting( 'hide_site_footer', array(
+		'default'              => false,
+		'type'                 => 'theme_mod',
+		'transport'            => 'refresh',
+		'sanitize_callback'    => 'varia_sanitize_checkbox',
+	) );
+
+	// Add control to hide footer elements on the homepage.
+	$wp_customize->add_control( 'hide_site_footer', array(
+		'label'		  => esc_html__( 'Hide the Site Footer Menu & Widgets', 'seedlet' ),
+		'description' => esc_html__( 'Check to hide the site menu & widgets in the footer, if your homepage is set to display a static page.', 'seedlet' ),
+		'section'	  => 'static_front_page',
+		'priority'	  => 10,
+		'type'		  => 'checkbox',
+		'settings'	  => 'hide_site_footer',
+	) );
+
+	// Sanitize checkboxes.
+	function varia_sanitize_checkbox( $checked = null ) {
+		return (bool) isset( $checked ) && true === $checked;
+	}
+}
+add_action( 'customize_register', 'varia_customize_header_footer' );
+
 /**
  * SVG Icons class.
  */

+ 2 - 0
varia/header.php

@@ -51,6 +51,8 @@ if ( function_exists( 'wp_body_open' ) ) {
 			?>
 		</header>
 
+	<?php elseif ( ( true === get_theme_mod( 'hide_site_header', false ) && is_front_page() && is_page() ) ) : return; // Return if this is the homepage and the hide-header setting is active. ?>
+
 	<?php else : // Otherwise we'll fallback to the default Varia header below. ?>
 		<header id="masthead" class="<?php echo $header_classes; ?>" role="banner">
 			<?php get_template_part( 'template-parts/header/site', 'branding' ); ?>

+ 0 - 24
varia/inc/customize-preview-wpcom.js

@@ -18,28 +18,4 @@
 			}
 		} );
 	} );
-
-	// Hide Site Header
-	wp.customize( 'hide_site_header', function( value ) {
-		value.bind( function( to ) {
-			if ( true === to ) {
-				$( 'body' ).addClass( 'hide-homepage-header' );
-
-			} else {
-				$( 'body' ).removeClass( 'hide-homepage-header' );
-			}
-		} );
-	} );
-
-	// Hide Site Footer Menu
-	wp.customize( 'hide_site_footer', function( value ) {
-		value.bind( function( to ) {
-			if ( true === to ) {
-				$( 'body' ).addClass( 'hide-homepage-footer' );
-
-			} else {
-				$( 'body' ).removeClass( 'hide-homepage-footer' );
-			}
-		} );
-	} );
 } )( jQuery );

+ 0 - 20
varia/inc/style-wpcom.css

@@ -9,26 +9,6 @@
 	display: none;
 }
 
- /**
- * Hide site header on the homepage
- */
-.home.page.hide-homepage-header .site-header {
-	display: none;
-}
-
-.home.page.hide-homepage-header .entry-content {
-	margin-top: 0;
-	padding-top: 0;
-}
-
- /**
- * Hide footer navigation on the homepage
- */
-.home.page.hide-homepage-footer .footer-navigation,
-.home.page.hide-homepage-footer .widget-area {
-	display: none;
-}
-
 /**
  * Fix Direct Manipulation icons in the Customizer
  */

+ 14 - 0
varia/inc/template-functions.php

@@ -40,6 +40,20 @@ function varia_body_classes( $classes ) {
 		$classes[] = 'image-filters-enabled';
 	}
 
+	// Add a body class if the site header is hidden on the homepage.
+	$hide_site_header = get_theme_mod( 'hide_site_header', false );
+
+	if ( true === $hide_site_header && is_front_page() && is_page() ) {
+		$classes[] = 'hide-homepage-header';
+	}
+
+	// Add a body class if the footer elements are hidden on the homepage.
+	$hide_site_footer = get_theme_mod( 'hide_site_footer', false );
+
+	if ( true === $hide_site_footer && is_front_page() && is_page() ) {
+		$classes[] = 'hide-homepage-footer';
+	}
+
 	return $classes;
 }
 add_filter( 'body_class', 'varia_body_classes' );

+ 0 - 32
varia/inc/wpcom.php

@@ -53,38 +53,6 @@ function varia_wpcom_customize_update( $wp_customize ) {
 		'settings'	  => 'hide_front_page_title',
 	) );
 
-	$wp_customize->add_setting( 'hide_site_header', array(
-		'default'              => false,
-		'type'                 => 'theme_mod',
-		'transport'            => 'postMessage',
-		'sanitize_callback'    => 'varia_sanitize_checkbox',
-	) );
-
-	$wp_customize->add_control( 'hide_site_header', array(
-		'label'		  => esc_html__( 'Hide the Site Header', 'varia' ),
-		'description' => esc_html__( 'Check to hide the site header, if your homepage is set to display a static page.', 'varia' ),
-		'section'	  => 'static_front_page',
-		'priority'	  => 10,
-		'type'		  => 'checkbox',
-		'settings'	  => 'hide_site_header',
-	) );
-
-	$wp_customize->add_setting( 'hide_site_footer', array(
-		'default'              => false,
-		'type'                 => 'theme_mod',
-		'transport'            => 'postMessage',
-		'sanitize_callback'    => 'varia_sanitize_checkbox',
-	) );
-
-	$wp_customize->add_control( 'hide_site_footer', array(
-		'label'		  => esc_html__( 'Hide the Site Footer Menu & Widgets', 'varia' ),
-		'description' => esc_html__( 'Check to hide the site menu & widgets in the footer, if your homepage is set to display a static page.', 'varia' ),
-		'section'	  => 'static_front_page',
-		'priority'	  => 10,
-		'type'		  => 'checkbox',
-		'settings'	  => 'hide_site_footer',
-	) );
-
     $wp_customize->add_setting( 'color_a11y_warning' );
     $wp_customize->add_control( 'color_a11y_warning', array(
         'id'          => 'id',

+ 1 - 1
varia/package-lock.json

@@ -1,6 +1,6 @@
 {
   "name": "varia",
-  "version": "1.5.10",
+  "version": "1.5.11",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {

+ 14 - 0
varia/sass/components/content/_entry-content.scss

@@ -56,6 +56,20 @@
 	.wp-audio-shortcode {
 		@extend %responsive-aligndefault;
 	}
+
+	// If the homepage header and page title are both configured to be hidden.
+	.home.page.hide-homepage-header.hide-homepage-title & {
+		margin-top: 0;
+		padding-top: 0;
+
+		// Move some full-width blocks up to the top of the screen.
+		> .wp-block-image.alignfull:first-child,
+		> .wp-block-cover.alignfull:first-child,
+		> .wp-block-media-text.alignfull:first-child,
+		> .wp-block-group.has-background.alignfull:first-child {
+			margin-top: #{-1 * map-deep-get($config-global, "spacing", "vertical")};
+		}
+	}
 }
 
 .entry-attachment {

+ 12 - 0
varia/style-rtl.css

@@ -3203,6 +3203,18 @@ body:not(.fse-enabled) .footer-menu a {
 	overflow: scroll;
 }
 
+.home.page.hide-homepage-header.hide-homepage-title .entry-content {
+	margin-top: 0;
+	padding-top: 0;
+}
+
+.home.page.hide-homepage-header.hide-homepage-title .entry-content > .wp-block-image.alignfull:first-child,
+.home.page.hide-homepage-header.hide-homepage-title .entry-content > .wp-block-cover.alignfull:first-child,
+.home.page.hide-homepage-header.hide-homepage-title .entry-content > .wp-block-media-text.alignfull:first-child,
+.home.page.hide-homepage-header.hide-homepage-title .entry-content > .wp-block-group.has-background.alignfull:first-child {
+	margin-top: -32px;
+}
+
 .entry-attachment {
 	text-align: center;
 }

+ 12 - 0
varia/style.css

@@ -3222,6 +3222,18 @@ body:not(.fse-enabled) .footer-menu a {
 	overflow: scroll;
 }
 
+.home.page.hide-homepage-header.hide-homepage-title .entry-content {
+	margin-top: 0;
+	padding-top: 0;
+}
+
+.home.page.hide-homepage-header.hide-homepage-title .entry-content > .wp-block-image.alignfull:first-child,
+.home.page.hide-homepage-header.hide-homepage-title .entry-content > .wp-block-cover.alignfull:first-child,
+.home.page.hide-homepage-header.hide-homepage-title .entry-content > .wp-block-media-text.alignfull:first-child,
+.home.page.hide-homepage-header.hide-homepage-title .entry-content > .wp-block-group.has-background.alignfull:first-child {
+	margin-top: -32px;
+}
+
 .entry-attachment {
 	text-align: center;
 }