Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change sticky toggles #549

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/assets/js/customizer/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ const { __ } = wp.i18n;
$( '#masthead-sticky' ).css( 'display', 'none' );
} else if ( api( 'bgtfw_fixed_header' ) && api( 'bgtfw_fixed_header' )() ) {
$( '#masthead-sticky' ).css( 'display', 'block' );
} else if ( $( '#masthead-sticky' ).is('[class*="sticky-template"]' ) ) {
$( '#masthead-sticky' ).css( 'display', 'block' );
}
} );
},
Expand Down
30 changes: 23 additions & 7 deletions src/includes/class-boldgrid-framework-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public function body_classes( $classes ) {

$classes[] = 'custom-header';

if ( get_theme_mod( 'bgtfw_fixed_header' ) ) {
if ( get_theme_mod( 'bgtfw_fixed_header' ) || apply_filters( 'crio_premium_get_sticky_page_header', $post_id ) ) {
if ( 'header-top' === get_theme_mod( 'bgtfw_header_layout_position' ) ) {
$classes[] = 'header-slide-in';
} else {
Expand Down Expand Up @@ -1363,12 +1363,6 @@ public static function dynamic_header() {
* @return string Rendered HTML for dyanmic layout element.
*/
public static function dynamic_sticky_header( $preset = null ) {
$markup = '';
$markup .= '<header id="masthead-sticky" ' . BoldGrid::add_class( 'header', [ 'header', 'sticky' ], false ) . '>';
ob_start();
do_action( 'boldgrid_header_top' );
$markup .= ob_get_clean();

if ( ! is_front_page() && is_home() ) {
$id = get_option( 'page_for_posts' );
} else {
Expand All @@ -1377,8 +1371,30 @@ public static function dynamic_sticky_header( $preset = null ) {

$page_header = apply_filters( 'crio_premium_get_sticky_page_header', $id );

$sticky_template_class = get_theme_mod( 'bgtfw_sticky_page_headers_global_enabled' ) && ! empty( $page_header ) ? 'sticky-template-' . $page_header : '';

$header_classes = array(
'header',
'sticky',
);

if ( ! empty( $sticky_template_class ) ) {
$header_classes[] = $sticky_template_class;
}

$markup = '';
$markup .= '<header id="masthead-sticky" ' . BoldGrid::add_class( 'header', $header_classes, false ) . '>';
ob_start();
do_action( 'boldgrid_header_top' );
$markup .= ob_get_clean();

if ( get_theme_mod( 'bgtfw_sticky_page_headers_global_enabled' ) && ! empty( $page_header ) ) {
if ( 'disabled' !== $page_header ) {
error_log(
'page_header: ' . json_encode(
apply_filters( 'the_content', get_post_field( 'post_content', $page_header ) )
)
);
$markup .= apply_filters( 'the_content', get_post_field( 'post_content', $page_header ) );
}
} else {
Expand Down
31 changes: 27 additions & 4 deletions src/includes/class-boldgrid-framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,15 @@ private function define_theme_hooks() {
$this->loader->add_filter( 'boldgrid_site_identity', $boldgrid_theme, 'print_title_tagline' );

// Sticky Header - Removed template_redirect as it was unnecessary and caused duplication of the sticky header sometimes.
if ( is_customize_preview() || ( true === get_theme_mod( 'bgtfw_fixed_header' ) ) || ( true === get_theme_mod( 'bgtfw_fixed_header' ) && 'header-top' === get_theme_mod( 'bgtfw_header_layout_position', 'header-top' ) ) ) {
add_action( 'boldgrid_header_after', function() {
add_action( 'boldgrid_header_after', function( $id ) {
if ( $this->maybe_show_sticky_header( $id ) ) {
?>
<div <?php BoldGrid::add_class( 'sticky_header', [ 'bgtfw-sticky-header', 'site-header' ] ); ?>>
<?php echo BoldGrid::dynamic_sticky_header(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
<?php
}, 20 );
}
}
}, 20 );

// Password protected post/page form.
$this->loader->add_filter( 'the_password_form', $boldgrid_theme, 'password_form' );
Expand All @@ -472,6 +472,29 @@ private function define_theme_hooks() {
$this->custom_header();
}

/**
* Maybe Show Sticky Header
*
* @since SINCEVERSION
*/
public function maybe_show_sticky_header( $id ) {
if ( is_customize_preview() || true === get_theme_mod( 'bgtfw_fixed_header' ) ) {
return true;
}

if ( true === get_theme_mod( 'bgtfw_fixed_header' ) && 'header-top' === get_theme_mod( 'bgtfw_header_layout_position', 'header-top' ) ) {
return true;
}

$sticky_header_template = apply_filters( 'crio_premium_get_sticky_page_header', $id );

if ( ! empty( $sticky_header_template ) ) {
return true;
}

return false;
}

/**
* This contains hooks for our theme's custom header implementation.
*
Expand Down