Your IP : 216.73.216.1
<?php
/**
* Header Settings
*
* @package pally
* @since 1.0.0
*/
namespace Pally;
use WP_Customize_Manager;
/**
* Header Settings
*
* @since 1.0.0
*/
class Header {
/**
* Constructor.
*
* @since 1.0.0
* @access public
*/
public function __construct() {
add_action( 'customize_register', [ $this, 'action_register_customizer_control' ] );
add_action( 'wp_head', [ $this, 'action_headerimage_css' ], 999 );
}
/**
* Adds a Customizer setting and control
*
* @param WP_Customize_Manager $wp_customize Customizer manager instance.
* @since 1.0.0
* @access public
*/
public function action_register_customizer_control( WP_Customize_Manager $wp_customize ) {
$wp_customize->add_setting(
'header_image_opacity',
array(
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_text_field',
)
);
$wp_customize->add_control(
'header_image_opacity',
array(
'description' => __( 'Set header image opacity for better readability of text.', 'pally' ),
'section' => 'header_image',
'label' => __( 'Header image opacity', 'pally' ),
'type' => 'number',
'input_attrs' => array(
'min' => 0,
'max' => 1,
'step' => 0.1,
),
)
);
$wp_customize->selective_refresh->add_partial(
'header_image_opacity',
array(
'selector' => '.header-image',
'container_ally' => true,
)
);
$wp_customize->add_setting(
'header_image_text',
array(
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_text_field',
)
);
$wp_customize->add_control(
'header_image_text',
array(
'description' => __( 'Only use if image is not decorative. Try to describe the whole header image.', 'pally' ),
'section' => 'header_image',
'label' => __( 'Text for screen readers', 'pally' ),
'type' => 'text',
'input_attrs' => array(
'placeholder' => __( 'Image description', 'pally' )
),
)
);
}
/**
* Output custom header.
*
* @since 1.0.0
* @access public
*/
public static function header_image() {
if ( ! has_header_image() ) {
echo '<div class="site-branding">';
} else {
$aria_label="";
if( !empty(get_theme_mod( 'header_image_text' )) ){
$aria_label= "aria-label='".get_theme_mod( 'header_image_text' )."'";
}
echo '<div '.$aria_label.' class="site-branding bgimage">';
}
}
public function action_headerimage_css() {
$opacity = get_theme_mod( 'header_image_opacity');
if ( has_header_image() ) {
echo '<style id="pally-theme-headerimage-css">';
echo ':root{
--theheaderimage: url('. esc_url( get_header_image() ) .');
}';
echo '.site-branding.bgimage:before {
opacity: '.$opacity.';
}';
echo '</style>';
}
}
}