/** * Get post specific CSS styles and paste it to head. * * @since 4.0.0 */ function cherry_post_inline_styles() { $post_id = get_queried_object_id(); $post_type = get_post_type($post_id); if (!$post_type || !post_type_supports($post_type, 'cherry-post-style')) { return; } if (wp_style_is(CHERRY_DYNAMIC_CSS_HANDLE, 'enqueued')) { $handle = CHERRY_DYNAMIC_CSS_HANDLE; } else { $cherry_styles = cherry_get_styles(); $handle = isset($cherry_styles['style']) ? $cherry_styles['style']['handle'] : false; } if (!$handle) { return; } $header_bg = cherry_current_page()->get_property('background', 'header'); if (!$header_bg) { return; } $custom_bg = cherry_get_background_css('.site-header', $header_bg); /** * Filter a custom background style. * * @since 4.0.0 * @param string $custom_bg Background style. * @param int $post_id The post ID. */ $custom_bg = apply_filters('cherry_post_inline_styles', $custom_bg, $post_id); if (!$custom_bg) { return; } wp_add_inline_style($handle, sanitize_text_field($custom_bg)); }
/** * Print dynamic CSS inline * * @since 4.0.0 */ function print_dynamic_css_inline() { $data = $this->prepare_dynamic_css(); $cherry_styles = cherry_get_styles(); if (wp_style_is(CHERRY_DYNAMIC_CSS_HANDLE, 'enqueued')) { $handle = CHERRY_DYNAMIC_CSS_HANDLE; } else { $handle = isset($cherry_styles['style']) ? $cherry_styles['style']['handle'] : false; } if (!$handle) { return; } wp_add_inline_style($handle, sanitize_text_field($data)); }
/** * Get post specific CSS styles and paste it to head * * @since 4.0.0 */ function cherry_post_inline_styles() { $cherry_styles = cherry_get_styles(); $post_id = get_the_id(); $post_type = get_post_type($post_id); if (!$post_type || !post_type_supports($post_type, 'cherry-post-style')) { return; } if (wp_style_is(CHERRY_DYNAMIC_CSS_HANDLE, 'enqueued')) { $handle = CHERRY_DYNAMIC_CSS_HANDLE; } else { $handle = isset($cherry_styles['style']) ? $cherry_styles['style']['handle'] : false; } if (!$handle) { return; } $object_id = apply_filters('cherry_current_object_id', $post_id); $styles = get_post_meta($object_id, 'cherry_style', true); if (!$styles) { return; } $custom_bg = ''; if (isset($styles['header-background'])) { $custom_bg .= cherry_get_background_css('.site-header', $styles['header-background']); } $custom_bg = apply_filters('cherry_post_inline_styles', $custom_bg, $post_id); if (!$custom_bg) { return; } wp_add_inline_style($handle, sanitize_text_field($custom_bg)); }