Browse Source

Make it possible to show the header, footer and page titles in Blank Canvas

Ben Dwyer 4 years ago
parent
commit
3eb34d4f69

+ 1 - 1
blank-canvas/assets/customizer.css

@@ -4,7 +4,7 @@
  * Adjusts the theme's message about the site branding display to appear like a notice.
  */
 
-#sub-accordion-section-title_tagline .customize-section-description {
+#sub-accordion-section-menu_locations .customize-section-description {
 	background: #FFF;
 	border: 1px solid #ccd0d4;
 	border-left: 4px solid #00a0d2;

+ 11 - 23
blank-canvas/functions.php

@@ -70,15 +70,9 @@ add_action( 'after_setup_theme', 'blank_canvas_setup', 11 );
  * Remove Seedlet theme features.
  */
 function blank_canvas_remove_parent_theme_features() {
-
 	// Theme Support.
 	remove_theme_support( 'custom-header' );
 	remove_theme_support( 'customize-selective-refresh-widgets' );
-
-	// Navigation Areas.
-	unregister_nav_menu( 'primary' );
-	unregister_nav_menu( 'footer' );
-	unregister_nav_menu( 'social' );
 }
 add_action( 'after_setup_theme', 'blank_canvas_remove_parent_theme_features', 11 );
 
@@ -86,29 +80,19 @@ add_action( 'after_setup_theme', 'blank_canvas_remove_parent_theme_features', 11
  * Dequeue Seedlet scripts.
  */
 function blank_canvas_dequeue_parent_scripts() {
-
-	// Naviation assets.
-	wp_dequeue_script( 'seedlet-primary-navigation-script' );
-	wp_dequeue_style( 'seedlet-style-navigation' );
+	if ( false === get_theme_mod( 'show_site_header', false ) ) {
+		// Naviation assets.
+		wp_dequeue_script( 'seedlet-primary-navigation-script' );
+		wp_dequeue_style( 'seedlet-style-navigation' );
+	}
 }
 add_action( 'wp_enqueue_scripts', 'blank_canvas_dequeue_parent_scripts', 11 );
 
-/**
- * Remove Seedlet's widget area.
- */
-function blank_canvas_remove_widgets_area() {
-	unregister_sidebar( 'sidebar-1' );
-}
-add_action( 'widgets_init', 'blank_canvas_remove_widgets_area', 11 );
-
 /**
  * Remove unused custmizer settings.
  */
 function blank_canvas_remove_customizer_settings( $wp_customize ) {
 
-	// Remove the navigation menus Customizer panel.
-	$wp_customize->get_panel( 'nav_menus' )->active_callback = '__return_false';
-
 	// Remove Jetpack's Author Bio setting.
 	if ( function_exists( 'jetpack_author_bio' ) ) {
 		$wp_customize->remove_control( 'jetpack_content_author_bio_title' );
@@ -120,9 +104,8 @@ function blank_canvas_remove_customizer_settings( $wp_customize ) {
 	$wp_customize->remove_control( 'hide_site_header' );
 	$wp_customize->remove_control( 'hide_site_footer' );
 
-
 	// Add a Customizer message about the site title & tagline options.
-	$wp_customize->get_section( 'title_tagline' )->description = __( 'This theme is designed to hide the site logo, site title, and tagline on all single posts and pages.', 'blank-canvas' );
+	$wp_customize->get_section( 'menu_locations' )->description = __( 'Menus will only be displayed on this theme if the header or footer is enabled. This can be done in the Content Options section.', 'blank-canvas' );
 }
 add_action( 'customize_register', 'blank_canvas_remove_customizer_settings', 11 );
 
@@ -175,3 +158,8 @@ function blank_canvas_customizer_enqueue() {
 	wp_enqueue_style( 'blank-canvas-customizer-style', get_stylesheet_directory_uri() . '/assets/customizer.css', array(), wp_get_theme()->get( 'Version' ) );
 }
 add_action( 'customize_controls_enqueue_scripts', 'blank_canvas_customizer_enqueue' );
+
+/**
+ * Customizer additions.
+ */
+require get_stylesheet_directory() . '/inc/customizer.php';

+ 140 - 0
blank-canvas/inc/customizer.php

@@ -0,0 +1,140 @@
+<?php
+/**
+ * Blank Canvas Theme: Customizer
+ *
+ * @package Blank Canvas
+ * @since 1.0.0
+ */
+
+if ( ! class_exists( 'Blank_Canvas_Customize' ) ) {
+	/**
+	 * Customizer Settings.
+	 *
+	 * @since 1.0.0
+	 */
+	class Blank_Canvas_Customize {
+
+		/**
+		 * Constructor. Instantiate the object.
+		 *
+		 * @access public
+		 *
+		 * @since 1.0.0
+		 */
+		public function __construct() {
+			add_action( 'customize_register', array( $this, 'register' ) );
+		}
+
+		/**
+		 * Register customizer options.
+		 *
+		 * @access public
+		 *
+		 * @since 1.0.0
+		 *
+		 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
+		 *
+		 * @return void
+		 */
+		public function register( $wp_customize ) {
+
+			// Add Content section.
+			$wp_customize->add_section(
+				'jetpack_content_options',
+				array(
+					'title'    => esc_html__( 'Content Options', 'blank-canvas' ),
+					'priority' => 100,
+				)
+			);
+
+			// Add setting to show post and page titles.
+			$wp_customize->add_setting(
+				'show_post_and_page_titles',
+				array(
+					'default'           => false,
+					'type'              => 'theme_mod',
+					'transport'         => 'refresh',
+					'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
+				)
+			);
+
+			// Add control to show the site header on the homepage.
+			$wp_customize->add_control(
+				'show_post_and_page_titles',
+				array(
+					'label'       => esc_html__( 'Show post and page titles', 'blank-canvas' ),
+					'description' => esc_html__( 'Check to show titles at the top of single posts and pages.', 'blank-canvas' ),
+					'section'     => 'jetpack_content_options',
+					'priority'    => 10,
+					'type'        => 'checkbox',
+					'settings'    => 'show_post_and_page_titles',
+				)
+			);
+
+			// Add setting to show the site header.
+			$wp_customize->add_setting(
+				'show_site_header',
+				array(
+					'default'           => false,
+					'type'              => 'theme_mod',
+					'transport'         => 'refresh',
+					'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
+				)
+			);
+
+			// Add control to show the site header.
+			$wp_customize->add_control(
+				'show_site_header',
+				array(
+					'label'       => esc_html__( 'Enable site header and navigation', 'blank-canvas' ),
+					'description' => esc_html__( 'Check to show a standard site header, navigation menu and social links menu on the top of every page.', 'blank-canvas' ),
+					'section'     => 'jetpack_content_options',
+					'priority'    => 10,
+					'type'        => 'checkbox',
+					'settings'    => 'show_site_header',
+				)
+			);
+
+			// Add setting to show the site footer.
+			$wp_customize->add_setting(
+				'show_site_footer',
+				array(
+					'default'           => false,
+					'type'              => 'theme_mod',
+					'transport'         => 'refresh',
+					'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
+				)
+			);
+
+			// Add control to show the site footer.
+			$wp_customize->add_control(
+				'show_site_footer',
+				array(
+					'label'       => esc_html__( 'Enable footer menu and widgets', 'blank-canvas' ),
+					'description' => esc_html__( "Check to show a navigation menu and widgets in your site's footer area.", 'blank-canvas' ),
+					'section'     => 'jetpack_content_options',
+					'priority'    => 10,
+					'type'        => 'checkbox',
+					'settings'    => 'show_site_footer',
+				)
+			);
+		}
+
+		/**
+		 * Sanitize boolean for checkbox.
+		 *
+		 * @access public
+		 *
+		 * @since 1.0.0
+		 *
+		 * @param bool $checked Whether or not a box is checked.
+		 *
+		 * @return bool
+		 */
+		public static function sanitize_checkbox( $checked = null ) {
+			return (bool) isset( $checked ) && true === $checked;
+		}
+	}
+
+	new Blank_Canvas_Customize();
+}

+ 11 - 0
blank-canvas/template-parts/content/content-singular.php

@@ -11,6 +11,17 @@
 ?>
 
 <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
+	<?php if ( true === get_theme_mod( 'show_post_and_page_titles', false ) ) : ?>
+		<header class="entry-header default-max-width">
+			<?php
+			if ( is_singular() ) :
+				the_title( '<h1 class="entry-title">', '</h1>' );
+			else :
+				the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
+			endif;
+			?>
+		</header><!-- .entry-header -->
+	<?php endif; ?>
 
 	<?php seedlet_post_thumbnail(); ?>
 

+ 7 - 1
blank-canvas/template-parts/footer/footer-content.php

@@ -1 +1,7 @@
-<?php get_template_part( 'template-parts/footer/footer-info' );
+<?php if ( true === get_theme_mod( 'show_site_footer', false ) ) : ?>
+	<?php get_template_part( 'template-parts/footer/footer-widgets' ); ?>
+	<?php get_template_part( 'template-parts/footer/footer-menu' ); ?>
+<?php endif; ?>
+
+<?php
+get_template_part( 'template-parts/footer/footer-info' );

+ 6 - 1
blank-canvas/template-parts/header/header-content.php

@@ -3,7 +3,12 @@
 	$header_class = $show_title ? 'site-title' : 'screen-reader-text';
 ?>
 
-<?php if ( ! is_singular() ) : ?>
+<?php if ( true === get_theme_mod( 'show_site_header', false ) ) : ?>
+	<header id="masthead" class="<?php echo $header_classes; ?>" role="banner">
+		<?php get_template_part( 'template-parts/header/site-branding' ); ?>
+		<?php get_template_part( 'template-parts/header/navigation' ); ?>
+	</header><!-- #masthead -->
+<?php elseif ( ! is_singular() ) : ?>
 	<header id="masthead" class="<?php echo $header_classes; ?>" role="banner">
 		<?php get_template_part( 'template-parts/header/site-branding' ); ?>
 	</header><!-- #masthead -->