Browse Source

Move functions to Varia add customizer control

Enej Bajgoric 4 years ago
parent
commit
11cbcc675b
8 changed files with 104 additions and 98 deletions
  1. 10 14
      alves/functions.php
  2. 9 14
      barnsbury/functions.php
  3. 9 14
      dalston/functions.php
  4. 9 14
      hever/functions.php
  5. 9 14
      mayland/functions.php
  6. 9 14
      morden/functions.php
  7. 9 14
      rivington/functions.php
  8. 40 0
      varia/functions.php

+ 10 - 14
alves/functions.php

@@ -102,8 +102,11 @@ if ( ! function_exists( 'alves_setup' ) ) :
 				),
 			)
 		);
+
 		// Add .mobile-nav-side body class.
-		add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		if ( function_exists( 'varia_mobile_nav_on_side' ) ) {
+			add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		}
 	}
 endif;
 add_action( 'after_setup_theme', 'alves_setup', 12 );
@@ -234,19 +237,12 @@ function alves_editor_styles() {
 }
 add_action( 'enqueue_block_editor_assets', 'alves_editor_styles' );
 
-// This makes it possible to define the function in earlier to alter if the class should be applied or not.
-if ( ! function_exists( 'varia_mobile_nav_on_side' ) ) {
-	function varia_mobile_nav_on_side( $classes ) {
-		if ( get_theme_mod( 'enable_side_menu' ) === 1 || ( isset( $_GET['customize_theme'] ) && get_stylesheet() === $_GET['customize_theme'] ) ) {
-			return array_merge( $classes, array( 'mobile-nav-side' ) );
-		}
-		return $classes;
-	}
+// Enable the mobile nav on side on theme switch.
+if ( function_exists( 'varia_enable_mobile_nav_on_side' ) ) {
+	add_action( 'after_switch_theme', 'varia_enable_mobile_nav_on_side' );
 }
 
-add_action( 'after_switch_theme', 'varia_enable_side_menu_on_mobile' );
-if ( ! function_exists( 'varia_enable_side_menu_on_mobile' ) ) {
-	function varia_enable_side_menu_on_mobile() {
-		set_theme_mod( 'enable_side_menu', 1 );
-	}
+// Enable the customizer control toggle for the mobile nav on the side.
+if ( function_exists( 'varia_register_mobile_nav_on_side_customizer_control' ) ) {
+	add_action( 'customize_register' , 'varia_register_mobile_nav_on_side_customizer_control' );
 }

+ 9 - 14
barnsbury/functions.php

@@ -104,7 +104,9 @@ if ( ! function_exists( 'barnsbury_setup' ) ) :
 		);
 
 		// Add .mobile-nav-side body class.
-		add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		if ( function_exists( 'varia_mobile_nav_on_side' ) ) {
+			add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		}
 	}
 endif;
 add_action( 'after_setup_theme', 'barnsbury_setup', 12 );
@@ -190,19 +192,12 @@ function barnsbury_editor_styles() {
 }
 add_action( 'enqueue_block_editor_assets', 'barnsbury_editor_styles' );
 
-// This makes it possible to define the function in earlier to alter if the class should be applied or not.
-if ( ! function_exists( 'varia_mobile_nav_on_side' ) ) {
-	function varia_mobile_nav_on_side( $classes ) {
-		if ( get_theme_mod( 'enable_side_menu' ) === 1 || ( isset( $_GET['customize_theme'] ) && get_stylesheet() === $_GET['customize_theme'] ) ) {
-			return array_merge( $classes, array( 'mobile-nav-side' ) );
-		}
-		return $classes;
-	}
+// Enable the mobile nav on side on theme switch.
+if ( function_exists( 'varia_enable_mobile_nav_on_side' ) ) {
+	add_action( 'after_switch_theme', 'varia_enable_mobile_nav_on_side' );
 }
 
-add_action( 'after_switch_theme', 'varia_enable_side_menu_on_mobile' );
-if ( ! function_exists( 'varia_enable_side_menu_on_mobile' ) ) {
-	function varia_enable_side_menu_on_mobile() {
-		set_theme_mod( 'enable_side_menu', 1 );
-	}
+// Enable the customizer control toggle for the mobile nav on the side.
+if ( function_exists( 'varia_register_mobile_nav_on_side_customizer_control' ) ) {
+	add_action( 'customize_register' , 'varia_register_mobile_nav_on_side_customizer_control' );
 }

+ 9 - 14
dalston/functions.php

@@ -121,7 +121,9 @@ if ( ! function_exists( 'dalston_setup' ) ) :
 		);
 
 		// Add .mobile-nav-side body class.
-		add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		if ( function_exists( 'varia_mobile_nav_on_side' ) ) {
+			add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		}
 	}
 endif;
 add_action( 'after_setup_theme', 'dalston_setup', 12 );
@@ -260,19 +262,12 @@ function dalston_is_amp() {
 	return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint();
 }
 
-// This makes it possible to define the function in earlier to alter if the class should be applied or not.
-if ( ! function_exists( 'varia_mobile_nav_on_side' ) ) {
-	function varia_mobile_nav_on_side( $classes ) {
-		if ( get_theme_mod( 'enable_side_menu' ) === 1 || ( isset( $_GET['customize_theme'] ) && get_stylesheet() === $_GET['customize_theme'] ) ) {
-			return array_merge( $classes, array( 'mobile-nav-side' ) );
-		}
-		return $classes;
-	}
+// Enable the mobile nav on side on theme switch.
+if ( function_exists( 'varia_enable_mobile_nav_on_side' ) ) {
+	add_action( 'after_switch_theme', 'varia_enable_mobile_nav_on_side' );
 }
 
-add_action( 'after_switch_theme', 'varia_enable_side_menu_on_mobile' );
-if ( ! function_exists( 'varia_enable_side_menu_on_mobile' ) ) {
-	function varia_enable_side_menu_on_mobile() {
-		set_theme_mod( 'enable_side_menu', 1 );
-	}
+// Enable the customizer control toggle for the mobile nav on the side.
+if ( function_exists( 'varia_register_mobile_nav_on_side_customizer_control' ) ) {
+	add_action( 'customize_register' , 'varia_register_mobile_nav_on_side_customizer_control' );
 }

+ 9 - 14
hever/functions.php

@@ -101,7 +101,9 @@ if ( ! function_exists( 'hever_setup' ) ) :
 		);
 
 		// Add .mobile-nav-side body class.
-		add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		if ( function_exists( 'varia_mobile_nav_on_side' ) ) {
+			add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		}
 	}
 endif;
 add_action( 'after_setup_theme', 'hever_setup', 12 );
@@ -183,19 +185,12 @@ function hever_editor_styles() {
 }
 add_action( 'enqueue_block_editor_assets', 'hever_editor_styles' );
 
-// This makes it possible to define the function in earlier to alter if the class should be applied or not.
-if ( ! function_exists( 'varia_mobile_nav_on_side' ) ) {
-	function varia_mobile_nav_on_side( $classes ) {
-		if ( get_theme_mod( 'enable_side_menu' ) === 1 || ( isset( $_GET['customize_theme'] ) && get_stylesheet() === $_GET['customize_theme'] ) ) {
-			return array_merge( $classes, array( 'mobile-nav-side' ) );
-		}
-		return $classes;
-	}
+// Enable the mobile nav on side on theme switch.
+if ( function_exists( 'varia_enable_mobile_nav_on_side' ) ) {
+	add_action( 'after_switch_theme', 'varia_enable_mobile_nav_on_side' );
 }
 
-add_action( 'after_switch_theme', 'varia_enable_side_menu_on_mobile' );
-if ( ! function_exists( 'varia_enable_side_menu_on_mobile' ) ) {
-	function varia_enable_side_menu_on_mobile() {
-		set_theme_mod( 'enable_side_menu', 1 );
-	}
+// Enable the customizer control toggle for the mobile nav on the side.
+if ( function_exists( 'varia_register_mobile_nav_on_side_customizer_control' ) ) {
+	add_action( 'customize_register' , 'varia_register_mobile_nav_on_side_customizer_control' );
 }

+ 9 - 14
mayland/functions.php

@@ -104,7 +104,9 @@ if ( ! function_exists( 'mayland_setup' ) ) :
 		);
 
 		// Add .mobile-nav-side body class.
-		add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		if ( function_exists( 'varia_mobile_nav_on_side' ) ) {
+			add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		}
 	}
 endif;
 add_action( 'after_setup_theme', 'mayland_setup', 12 );
@@ -188,19 +190,12 @@ function mayland_editor_styles() {
 }
 add_action( 'enqueue_block_editor_assets', 'mayland_editor_styles' );
 
-// This makes it possible to define the function in earlier to alter if the class should be applied or not.
-if ( ! function_exists( 'varia_mobile_nav_on_side' ) ) {
-	function varia_mobile_nav_on_side( $classes ) {
-		if ( get_theme_mod( 'enable_side_menu' ) === 1 || ( isset( $_GET['customize_theme'] ) && get_stylesheet() === $_GET['customize_theme'] ) ) {
-			return array_merge( $classes, array( 'mobile-nav-side' ) );
-		}
-		return $classes;
-	}
+// Enable the mobile nav on side on theme switch.
+if ( function_exists( 'varia_enable_mobile_nav_on_side' ) ) {
+	add_action( 'after_switch_theme', 'varia_enable_mobile_nav_on_side' );
 }
 
-add_action( 'after_switch_theme', 'varia_enable_side_menu_on_mobile' );
-if ( ! function_exists( 'varia_enable_side_menu_on_mobile' ) ) {
-	function varia_enable_side_menu_on_mobile() {
-		set_theme_mod( 'enable_side_menu', 1 );
-	}
+// Enable the customizer control toggle for the mobile nav on the side.
+if ( function_exists( 'varia_register_mobile_nav_on_side_customizer_control' ) ) {
+	add_action( 'customize_register' , 'varia_register_mobile_nav_on_side_customizer_control' );
 }

+ 9 - 14
morden/functions.php

@@ -101,7 +101,9 @@ if ( ! function_exists( 'morden_setup' ) ) :
 		);
 
 		// Add .mobile-nav-side body class.
-		add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		if ( function_exists( 'varia_mobile_nav_on_side' ) ) {
+			add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		}
 	}
 endif;
 add_action( 'after_setup_theme', 'morden_setup', 12 );
@@ -182,19 +184,12 @@ function morden_editor_styles() {
 }
 add_action( 'enqueue_block_editor_assets', 'morden_editor_styles' );
 
-// This makes it possible to define the function in earlier to alter if the class should be applied or not.
-if ( ! function_exists( 'varia_mobile_nav_on_side' ) ) {
-	function varia_mobile_nav_on_side( $classes ) {
-		if ( get_theme_mod( 'enable_side_menu' ) === 1 || ( isset( $_GET['customize_theme'] ) && get_stylesheet() === $_GET['customize_theme'] ) ) {
-			return array_merge( $classes, array( 'mobile-nav-side' ) );
-		}
-		return $classes;
-	}
+// Enable the mobile nav on side on theme switch.
+if ( function_exists( 'varia_enable_mobile_nav_on_side' ) ) {
+	add_action( 'after_switch_theme', 'varia_enable_mobile_nav_on_side' );
 }
 
-add_action( 'after_switch_theme', 'varia_enable_side_menu_on_mobile' );
-if ( ! function_exists( 'varia_enable_side_menu_on_mobile' ) ) {
-	function varia_enable_side_menu_on_mobile() {
-		set_theme_mod( 'enable_side_menu', 1 );
-	}
+// Enable the customizer control toggle for the mobile nav on the side.
+if ( function_exists( 'varia_register_mobile_nav_on_side_customizer_control' ) ) {
+	add_action( 'customize_register' , 'varia_register_mobile_nav_on_side_customizer_control' );
 }

+ 9 - 14
rivington/functions.php

@@ -113,7 +113,9 @@ if ( ! function_exists( 'rivington_setup' ) ) :
 		unregister_nav_menu( 'menu-2' );
 
 		// Add .mobile-nav-side body class.
-		add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		if ( function_exists( 'varia_mobile_nav_on_side' ) ) {
+			add_filter( 'body_class', 'varia_mobile_nav_on_side' );
+		}
 	}
 endif;
 add_action( 'after_setup_theme', 'rivington_setup', 12 );
@@ -197,19 +199,12 @@ function rivington_editor_styles() {
 }
 add_action( 'enqueue_block_editor_assets', 'rivington_editor_styles' );
 
-// This makes it possible to define the function in earlier to alter if the class should be applied or not.
-if ( ! function_exists( 'varia_mobile_nav_on_side' ) ) {
-	function varia_mobile_nav_on_side( $classes ) {
-		if ( get_theme_mod( 'enable_side_menu' ) === 1 || ( isset( $_GET['customize_theme'] ) && get_stylesheet() === $_GET['customize_theme'] ) ) {
-			return array_merge( $classes, array( 'mobile-nav-side' ) );
-		}
-		return $classes;
-	}
+// Enable the mobile nav on side on theme switch.
+if ( function_exists( 'varia_enable_mobile_nav_on_side' ) ) {
+	add_action( 'after_switch_theme', 'varia_enable_mobile_nav_on_side' );
 }
 
-add_action( 'after_switch_theme', 'varia_enable_side_menu_on_mobile' );
-if ( ! function_exists( 'varia_enable_side_menu_on_mobile' ) ) {
-	function varia_enable_side_menu_on_mobile() {
-		set_theme_mod( 'enable_side_menu', 1 );
-	}
+// Enable the customizer control toggle for the mobile nav on the side.
+if ( function_exists( 'varia_register_mobile_nav_on_side_customizer_control' ) ) {
+	add_action( 'customize_register' , 'varia_register_mobile_nav_on_side_customizer_control' );
 }

+ 40 - 0
varia/functions.php

@@ -285,6 +285,46 @@ function varia_editor_content_width() {
 }
 add_action( 'enqueue_block_editor_assets', 'varia_editor_content_width' );
 
+// This makes it possible to define the function in earlier to alter in one way or another.
+if ( ! function_exists( 'varia_mobile_nav_on_side' ) ) {
+	function varia_mobile_nav_on_side( $classes ) {
+		if ( get_theme_mod( 'enable_side_menu' ) === 1 ) {
+			return array_merge( $classes, array( 'mobile-nav-side' ) );
+		}
+		return $classes;
+	}
+}
+
+if ( ! function_exists( 'varia_enable_side_menu_on_mobile' ) ) {
+	function varia_enable_side_menu_on_mobile() {
+		set_theme_mod( 'enable_side_menu', 1 );
+	}
+}
+
+if ( ! function_exists( 'varia_register_mobile_nav_on_side_customizer_control' ) ) {
+	function varia_register_mobile_nav_on_side_customizer_control( $wp_customize ) {
+
+		$wp_customize->add_setting(
+			'enable_side_menu',
+			array(
+				'default'           => 1,
+				'sanitize_callback' => 'absint',
+			)
+		);
+
+		$wp_customize->add_control(
+			'enable_side_menu',
+			array(
+				'label'    => __( 'Display mobile menu on the side', 'varia' ),
+				'section'  => 'title_tagline',
+				'settings' => 'enable_side_menu',
+				'type'     => 'checkbox',
+			)
+		);
+
+	}
+}
+
 /**
  * SVG Icons class.
  */