hooks(); $this->run_adds(); } public function hooks() { // WordPress hooks $this->add_filter( 'body_class', $this, 'body_class_modyficator' ); // Theme hooks $this->add_action( 'canvi_get_sidebar', $this, 'get_sidebar' ); $this->add_action( 'canvi_action_get_template_part', $this, 'action_get_template_part', 1, 2 ); $this->add_action( 'canvi_action_get_template_area', $this, 'action_get_template_area', 1, 2 ); $this->add_action( 'canvi_action_site_logo', $this, 'action_site_logo' ); $this->add_action( 'canvi_action_site_blog_info', $this, 'action_site_blog_info' ); $this->add_action( 'canvi_action_site_description', $this, 'action_site_description' ); $this->add_action( 'canvi_action_full_search_navbar', $this, 'action_full_search_navbar' ); $this->add_filter( 'canvi_filter_content_header_styles', $this, 'filter_content_header_styles', 1, 2 ); $this->add_filter( 'canvi_filter_content_header_class', $this, 'filter_content_header_class', 1, 2 ); $this->add_filter( 'canvi_filter_header_lead_class', $this, 'filter_header_lead_class', 1, 2 ); $this->add_filter( 'canvi_layout_class', $this, 'filter_layout_class', 1, 2 ); $this->add_filter( 'canvi_filter_get_settings_text', $this, 'filter_get_settings_text', 1, 2 ); $this->add_filter( 'canvi_filter_header_class', $this, 'filter_header_class', 1, 2 ); $this->add_filter( 'canvi_filter_archive_articles_class', $this, 'filter_archive_articles_class', 1, 2 ); $this->add_filter( 'canvi_filter_page_layout_class', $this, 'filter_page_layout_class', 1, 2 ); } public function body_class_modyficator( $classes ) { $classes[] = 'canvi-body-has-topbar'; return $classes; } public function filter_layout_class( $default, $type = 'main' ) { $class = 'class="' . $default; $type = apply_filters( 'canvi_get_sidebar_type', $type ); $type_sidebar = Canvi_Settings::get( $type . '_sidebar', '1' ); if ( is_active_sidebar( $type . '_sidebar' ) && ! is_page_template( array( 'templates/template-full-width.php', 'templates/template-gutenberg-layout.php' ) ) ) { switch ( $type_sidebar ) { case 1: $class .= ' -sidebar'; break; case 2: $class .= ' -sidebar -left-sidebar'; break; } } $class .= '"'; return $class; } /** * Displays Search navbar */ function action_full_search_navbar() { $main_menu_search_display = esc_attr( Canvi_Settings::get( 'main_menu_search_display', TRUE ) ); if ( $main_menu_search_display ) { get_template_part( 'template-parts/header/navbar-search' ); } } /** * Returns style & attributes string for Page Header * * @param $default * * @return string */ function filter_content_header_styles( $default, $type = 'page' ) { $attributes_string = $default; $style_string = ''; $image = esc_attr( Canvi_Settings::get( $type . '_header_background' ) ); $color = esc_attr( Canvi_Settings::get( $type . '_header_background_overlay' ) ); if ( strlen( $image ) > 0 || strlen( $color ) > 0 ) { $style_string = 'style="'; if ( strlen( $image ) > 0 ) { $background_image = wp_get_attachment_image_src( $image, 'full' ); $style_string .= 'background-image: url(' . $background_image[0] . ');'; } if ( strlen( $color ) > 0 ) { $style_string .= 'background-color: ' . $color . ';'; } $style_string .= '"'; if ( strlen( $image ) > 0 && strlen( $color ) > 0 ) { $attributes_string = 'data-type="background" data-overlay-color="' . $color . '"'; } } return $style_string . ' ' . $attributes_string; } /** * Get Content Header Class * * @param $default * @param $dark_section * * @return string */ function filter_content_header_class( $default, $type = 'page' ) { $header_class = 'class="' . $default; $dark_section = esc_attr( Canvi_Settings::get( $type . '_header_invert_section' ) ); $paralax_section = esc_attr( Canvi_Settings::get( $type . '_header_background_paralax' ) ); $overlay = esc_attr( Canvi_Settings::get( $type . '_header_background_overlay' ) ); if ( $dark_section ) { $header_class .= ' -invert'; } if ( $paralax_section ) { $header_class .= ' u-paralax-section'; } if ( strlen( $overlay ) > 0 ) { $header_class .= ' u-overlay-section'; } return $header_class . '"'; } /** * Displays text from theme settings * * @param $default * @param $settings_key * * @return mixed */ public function filter_get_settings_text( $default, $settings_key ) { $text = esc_attr( Canvi_Settings::get( $settings_key ) ); if ( is_string( $text ) && strlen( $text ) > 0 ) { return $text; } if ( is_user_logged_in() && current_user_can( 'edit_theme_options' ) ) { return $default; } } /** * Get Header Lead Class * * @param $default * * @return string */ function filter_header_lead_class( $default, $sidebar = 'main' ) { $lead_class = 'class="' . $default; if ( ! has_post_thumbnail() ) { $lead_class .= ' -no-image'; } if ( is_active_sidebar( $sidebar . '_sidebar' ) ) { $sidebar_type = esc_attr( Canvi_Settings::get( $sidebar . '_sidebar', '1' ) ); switch ( $sidebar_type ) { case 1: $lead_class .= ' -sidebar'; break; case 2: $lead_class .= ' -sidebar -left-sidebar'; break; } } return $lead_class . '"'; } /** * Includes sidebar * * @param string $type */ public function get_sidebar( $type = 'main' ) { $type = apply_filters( 'canvi_get_sidebar_type', $type ); $type_sidebar = esc_attr( Canvi_Settings::get( $type . '_sidebar', '1' ) ); if ( $type_sidebar == '1' || $type_sidebar == '2' ) { get_template_part( 'views/sidebar', $type ); } } /** * Load template part based on customizer option * * @param $partial_name * @param $option_name */ public function action_get_template_part( $partial_name, $option_name ) { $option_value = esc_attr( Canvi_Settings::get( $option_name, FALSE ) ); if ( $option_value == '1' ) { get_template_part( $partial_name ); } } /** * Load main template area * * @param $directory * @param $area_name */ public function action_get_template_area( $directory, $area_name ) { // Elementor location if ( ! function_exists( 'elementor_theme_do_location' ) || ! elementor_theme_do_location( $area_name ) ) { get_template_part( $directory . '/' . apply_filters( 'canvi_filter_area_version', $area_name ) ); } } /** * Displays brand theme logo */ function action_site_logo() { $show_title = (bool) esc_attr( Canvi_Settings::get( 'display_title_and_tagline', TRUE ) ); if ( has_custom_logo() && ! $show_title ) { Canvi_Component_Layout::brand_logo(); } } /** * Displays site tagline */ function action_site_description() { $description = get_bloginfo( 'description', 'display' ); $show_title = (bool) esc_attr( Canvi_Settings::get( 'display_title_and_tagline', TRUE ) ); if ( $description && $show_title === TRUE ) { Canvi_Component_Layout::site_description( $description ); } } /** * Displays site info Site title */ function action_site_blog_info() { $blog_info = get_bloginfo( 'name' ); $show_title = (bool) esc_attr( Canvi_Settings::get( 'display_title_and_tagline', TRUE ) ); $header_class = $show_title ? 'site-title canvi-s-main-header__title' : 'screen-reader-text'; if ( $blog_info && $show_title ) { Canvi_Component_Layout::site_blog_info( $blog_info, $header_class ); } } public function filter_header_class( $default ) { $wrapper_classes = $default; $wrapper_classes .= 'site-header'; $wrapper_classes .= has_custom_logo() ? ' has-logo' : ''; $wrapper_classes .= TRUE === Canvi_Settings::get( 'display_title_and_tagline', TRUE ) ? ' has-title-and-tagline' : ''; $wrapper_classes .= has_nav_menu( 'primary' ) ? ' has-menu' : ''; return $wrapper_classes; } /** * Infinite scroll switcher * * @param $default * * @return string */ public function filter_archive_articles_class( $default ) { $container_classes = $default; $infinite_scroll_on = (bool) esc_attr( Canvi_Settings::get( 'infinite_scroll_on', TRUE ) ); if ( $infinite_scroll_on ) { $container_classes .= 'js-infinite-scroll'; } return $container_classes; } public function filter_page_layout_class( $default ) { $container_classes = $default; if ( is_active_sidebar( 'main_sidebar' ) ) { $container_classes .= ' has-sidebar'; } else { $container_classes .= ' no-sidebar'; } return $container_classes; } } }