'desktop', 'screen_size' => '' ]; private $media_tab = [ 'name' => 'tab', 'screen_size' => 1024 ]; private $media_mobile = [ 'name' => 'mobile', 'screen_size' => 767 ]; public static function init() { if (null === self::$instance) { self::$instance = new self; } return self::$instance; } public function __construct() { add_action('wp_head', [$this, 'enqueue_frontend_css']); } /** * Enqueue frontend css for post if have one * @return void * @since 1.0.2 */ public function enqueue_frontend_css() { global $post; if(!empty($post) && !empty($post->ID)){ $blocks = parse_blocks($post->post_content); $style_object = []; if(!empty($blocks)){ foreach ($blocks as $block){ if(!empty($block['attrs']) && !empty($block['attrs']['blockMeta'])){ $style_object[] = $block['attrs']['blockMeta']; } } } if(!empty($style_object)){ echo ''; } } } /** * Enqueue frontend css for post if have one * @param string * @return string * @since 1.0.2 */ private function build_css($style_objects) { $css = ''; $mobile_style = ''; $tab_style = ''; foreach ($style_objects as $block_style) { if (!empty($block_css = (array) $block_style)) { foreach ($block_css as $media => $style) { switch ($media){ case $this->media_desktop['name'] : $css .= preg_replace('/\s+/', ' ', $style); break; case $this->media_tab['name']: $tab_style .= preg_replace('/\s+/', ' ', $style); break; case $this->media_mobile['name']: $mobile_style .= preg_replace('/\s+/', ' ', $style); break; } } } } if(!empty($tab_style)){ $css .= ' @media(max-width: 1024px){' . $tab_style . '}'; } if(!empty($mobile_style)){ $css .= ' @media(max-width: 767px){' . $mobile_style . '}'; } return trim($css); } } EbStyleHandlerInline::init(); }