/** * Outputs post specific CSS for post background image, color and opacity. * * @param int $post_id Post ID. * @param string $sel1 CSS Selector 1. * @param string $sel2 CSS Selector 1. * @return mixed */ function stag_post_background_css($post_id = null, $sel1 = '.article-cover--', $sel2 = '.article-cover__background') { if (0 === absint($post_id)) { $post_id = get_the_ID(); } $thumb_id = get_post_thumbnail_id($post_id); if ($thumb_id != '') { $thumb_url = wp_get_attachment_image_src($thumb_id, 'full', true); $background_image = $thumb_url[0]; } else { $background_image = ''; } $background_color = stag_get_post_meta('settings', $post_id, 'post-background-color'); $background_opacity = stag_get_post_meta('settings', $post_id, 'post-background-opacity'); $text_color = stag_get_post_meta('settings', $post_id, 'post-text-color'); $link_color = stag_get_post_meta('settings', $post_id, 'post-link-color'); // Set a default background opacity if (empty($background_opacity)) { $background_opacity = 40; } ob_start(); ?> <style type="text/css" scoped> <?php if (!empty($background_color)) { ?> <?php echo $sel1 . $post_id; ?> { background-color: <?php echo stag_maybe_hash_hex_color($background_color); ?> ; } <?php } ?> .background-video { opacity: <?php echo absint($background_opacity) / 100; ?> ; } <?php if (!empty($background_image)) { ?> <?php echo $sel2; ?> { background-image: url(<?php echo esc_url($background_image); ?> ); opacity: <?php echo absint($background_opacity) / 100; ?> ; } <?php } ?> <?php if (is_page()) { ?> <?php if (!empty($text_color)) { ?> <?php echo $sel1 . $post_id; ?> { color: <?php echo stag_maybe_hash_hex_color($text_color); ?> ; } <?php echo $sel1 . $post_id; ?> input { color: <?php echo stag_maybe_hash_hex_color($text_color); ?> ; border-color: <?php echo stag_maybe_hash_hex_color($text_color); ?> ; } <?php } ?> <?php if (!empty($link_color)) { ?> <?php echo $sel1 . $post_id; ?> a:not(.stag-button):not(.ui-tabs-anchor) { color: <?php echo stag_maybe_hash_hex_color($link_color); ?> ; } <?php } ?> <?php } ?> </style> <?php echo ob_get_clean(); }
} // Set a default background opacity if (empty($background_opacity)) { $background_opacity = 40; } ?> <style type="text/css"> <?php if (!empty($background_color)) { ?> .post-<?php echo $id; ?> { background-color: <?php echo stag_maybe_hash_hex_color($background_color); ?> !important; } <?php } ?> <?php if (!empty($background_image)) { ?> .post-cover-<?php echo $id; ?> { background-image: url(<?php echo esc_url($background_image); ?>