public ) { return $post_templates; } // Variables $registered_post_templates = $theme->get_post_templates(); if ( isset( $registered_post_templates['public-post-types'] ) ) { $registered_post_templates = $registered_post_templates['public-post-types']; } else { $registered_post_templates = array(); } // Output return array_filter( array_merge( $post_templates, $registered_post_templates ) ); } // /post_templates /** * HTML body classes. * * Allows setting up page template custom body class(es). * * To set body class(es) for the page template, put similar code * before actual page template content output: * @example * if ( doing_filter( 'body_class' ) ) { * $body_classes = array( 'template-body-class-name' ); * return; * } * * @since 1.0.10 * * @param array $classes * * @return array */ public static function body_class( array $classes ): array { // Processing if ( is_singular() && is_page_template() ) { $template = get_page_template_slug( get_the_ID() ); $template_classes = array_filter( (array) get_transient( self::$transient_cache_body_class ) ); if ( ! isset( $template_classes[ $template ] ) ) { // This variable should be set in the page template file! $body_classes = array(); // Using buffer to prevent page content rendering. ob_start(); include_once get_theme_file_path( $template ); $_not_used = ob_get_clean(); $template_classes[ $template ] = array_filter( (array) $body_classes ); // Caching classes to speed things up. set_transient( self::$transient_cache_body_class, $template_classes ); } // Why bother if the page template has no body classes set. if ( empty( $template_classes[ $template ] ) ) { return $classes; } foreach ( $template_classes[ $template ] as $class ) { $classes[] = sanitize_html_class( $class ); } } // Output return array_unique( $classes ); } // /body_class /** * Flush templates body classes transient cache. * * @since 1.0.10 * * @return void */ public static function body_class_cache_flush() { // Processing delete_transient( self::$transient_cache_body_class ); } // /body_class_cache_flush // Page templates with content only. /** * Is page template: Content only? * * @since 1.0.0 * * @param mixed $body_classes Optional forced array of body classes when using the method within `body_class` hook. * * @return bool */ public static function is_content_only( $body_classes = array() ): bool { // Variables $check_body_class = stripos( implode( ' ', Body_Class::get_body_class( $body_classes ) ), '-content-only' ); // Output /** * Filters whether we should display only page content. * * @since 1.0.0 * * @param bool $check_body_class By default it checks for a specific body class name portion. */ return (bool) apply_filters( 'michelle/entry/page_template/is_content_only', (bool) $check_body_class ); } // /is_content_only // Overlaid header templates. /** * Add new custom logo options for overlaid header templates. * * @since 1.0.0 * * @param WP_Customize_Manager $wp_customize * * @return void */ public static function customize_register( WP_Customize_Manager $wp_customize ) { // Variables $custom_logo_args = get_theme_support( 'custom-logo' ); // Processing // Light logo. $wp_customize->add_setting( 'custom_logo_light', array( 'theme_supports' => array( 'custom-logo' ), 'transport' => 'postMessage', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'custom_logo_light', array( 'active_callback' => function() { return stripos( implode( ' ', Body_Class::get_body_class() ), '-header-overlaid-light' ); }, 'label' => esc_html__( 'Logo variation: light', 'michelle' ), 'description' => esc_html__( 'This logo image will be displayed in overlaid header with light color.', 'michelle' ), 'section' => 'title_tagline', 'priority' => 8, 'height' => isset( $custom_logo_args[0]['height'] ) ? $custom_logo_args[0]['height'] : null, 'width' => isset( $custom_logo_args[0]['width'] ) ? $custom_logo_args[0]['width'] : null, 'flex_height' => isset( $custom_logo_args[0]['flex-height'] ) ? $custom_logo_args[0]['flex-height'] : null, 'flex_width' => isset( $custom_logo_args[0]['flex-width'] ) ? $custom_logo_args[0]['flex-width'] : null, 'button_labels' => array( 'select' => esc_html__( 'Select logo', 'michelle' ), 'change' => esc_html__( 'Change logo', 'michelle' ), 'remove' => esc_html__( 'Remove', 'michelle' ), 'default' => esc_html__( 'Default', 'michelle' ), 'placeholder' => esc_html__( 'No logo selected', 'michelle' ), 'frame_title' => esc_html__( 'Select logo', 'michelle' ), 'frame_button' => esc_html__( 'Choose logo', 'michelle' ), ), ) ) ); $wp_customize->selective_refresh->add_partial( 'custom_logo_light', array( 'selector' => 'body[class*="-header-overlaid-light"] .custom-logo-link', 'render_callback' => array( $wp_customize, '_render_custom_logo_partial' ), 'container_inclusive' => true, ) ); // Dark logo. $wp_customize->add_setting( 'custom_logo_dark', array( 'theme_supports' => array( 'custom-logo' ), 'transport' => 'postMessage', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'custom_logo_dark', array( 'active_callback' => function() { return stripos( implode( ' ', Body_Class::get_body_class() ), '-header-overlaid-dark' ); }, 'label' => esc_html__( 'Logo variation: dark', 'michelle' ), 'description' => esc_html__( 'This logo image will be displayed in overlaid header with dark color.', 'michelle' ), 'section' => 'title_tagline', 'priority' => 8, 'height' => isset( $custom_logo_args[0]['height'] ) ? $custom_logo_args[0]['height'] : null, 'width' => isset( $custom_logo_args[0]['width'] ) ? $custom_logo_args[0]['width'] : null, 'flex_height' => isset( $custom_logo_args[0]['flex-height'] ) ? $custom_logo_args[0]['flex-height'] : null, 'flex_width' => isset( $custom_logo_args[0]['flex-width'] ) ? $custom_logo_args[0]['flex-width'] : null, 'button_labels' => array( 'select' => esc_html__( 'Select logo', 'michelle' ), 'change' => esc_html__( 'Change logo', 'michelle' ), 'remove' => esc_html__( 'Remove', 'michelle' ), 'default' => esc_html__( 'Default', 'michelle' ), 'placeholder' => esc_html__( 'No logo selected', 'michelle' ), 'frame_title' => esc_html__( 'Select logo', 'michelle' ), 'frame_button' => esc_html__( 'Choose logo', 'michelle' ), ), ) ) ); $wp_customize->selective_refresh->add_partial( 'custom_logo_dark', array( 'selector' => 'body[class*="-header-overlaid-dark"] .custom-logo-link', 'render_callback' => array( $wp_customize, '_render_custom_logo_partial' ), 'container_inclusive' => true, ) ); } // /customize_register /** * Set custom logo variation in header only. * * @since 1.0.0 * * @param mixed $value * * @return mixed */ public static function set_custom_logo() { // Requirements check if ( ! stripos( implode( ' ', Body_Class::get_body_class() ), '-header-overlaid-' ) ) { return; } // Processing if ( doing_action( 'tha_header_before' ) ) { add_filter( 'theme_mod_custom_logo', __CLASS__ . '::custom_logo' ); } else { remove_filter( 'theme_mod_custom_logo', __CLASS__ . '::custom_logo' ); } } // /set_custom_logo /** * Display custom logo variation. * * @since 1.0.0 * * @param mixed $value * * @return mixed */ public static function custom_logo( $value ) { // Variables $body_classes = implode( ' ', Body_Class::get_body_class() ); // Processing if ( stripos( $body_classes, '-header-overlaid-light' ) && $logo_light = get_theme_mod( 'custom_logo_light' ) ) { return $logo_light; } elseif ( stripos( $body_classes, '-header-overlaid-dark' ) && $logo_dark = get_theme_mod( 'custom_logo_dark' ) ) { return $logo_dark; } // Output return $value; } // /custom_logo }