next_tag()) { return $block_content; } $attrs = $block['attrs']; $classes = []; $styles = []; // Collect classes and styles from hover effect strategy $classes = array_merge($classes, HoverEffectsAttributes::get_classes($attrs)); $styles = array_merge($styles, HoverEffectsAttributes::get_styles($attrs)); // Apply collected classes to the block foreach ($classes as $class) { $tags->add_class($class); } // Merge and apply styles if (! empty($styles)) { $existing_style = $tags->get_attribute('style'); $merged_style = $this->merge_styles($existing_style, $styles); $tags->set_attribute('style', $merged_style); } return $tags->get_updated_html(); } /** * Merge existing styles with new inline styles. * * Combines existing inline styles with new styles, ensuring no duplicates. * * @param string $existing Existing inline style string. * @param array $new_styles New styles to be applied. * @return string Merged style string. */ private function merge_styles($existing, $new_styles) { $style_array = []; // Parse existing styles into array if (! empty($existing)) { $rules = explode(';', $existing); foreach ($rules as $rule) { if (strpos($rule, ':') !== false) { list($prop, $val) = explode(':', $rule, 2); $style_array[trim($prop)] = trim($val); } } } // Add or update with new styles foreach ($new_styles as $prop => $val) { $style_array[$prop] = $val; } // Convert back to string $final = ''; foreach ($style_array as $prop => $val) { $final .= $prop . ': ' . $val . '; '; } return trim($final); } } // Initialize the class new Blynex_Block_Attributes(); }