Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Blocks/Utils
File: StyleAttributesUtils.php
public static function get_link_color_class_and_style( $attributes ) {
[500] Fix | Delete
$link_color = self::array_get_value_by_path( $attributes, 'style.elements.link.color.text' );
[501] Fix | Delete
[502] Fix | Delete
if ( empty( $link_color ) ) {
[503] Fix | Delete
return self::EMPTY_STYLE;
[504] Fix | Delete
}
[505] Fix | Delete
[506] Fix | Delete
// If the link color is selected from the theme color picker, the value of $link_color is var:preset|color|slug.
[507] Fix | Delete
// If the link color is selected from the core color picker, the value of $link_color is an hex value.
[508] Fix | Delete
// When the link color is a string var:preset|color|slug we parsed it for get the slug, otherwise we use the hex value.
[509] Fix | Delete
if ( strstr( $link_color, '|' ) ) {
[510] Fix | Delete
$link_color_parts = explode( '|', $link_color );
[511] Fix | Delete
$link_color = self::get_preset_value( end( $link_color_parts ) );
[512] Fix | Delete
}
[513] Fix | Delete
[514] Fix | Delete
return array(
[515] Fix | Delete
'class' => 'has-link-color',
[516] Fix | Delete
'style' => sprintf( 'color: %s;', $link_color ),
[517] Fix | Delete
'value' => $link_color,
[518] Fix | Delete
);
[519] Fix | Delete
}
[520] Fix | Delete
[521] Fix | Delete
/**
[522] Fix | Delete
* Get class and style for link-hover-color from attributes.
[523] Fix | Delete
*
[524] Fix | Delete
* @param array $attributes Block attributes.
[525] Fix | Delete
* @return array
[526] Fix | Delete
*/
[527] Fix | Delete
public static function get_link_hover_color_class_and_style( $attributes ) {
[528] Fix | Delete
$link_color = self::array_get_value_by_path( $attributes, 'style.elements.link.:hover.color.text' );
[529] Fix | Delete
[530] Fix | Delete
if ( empty( $link_color ) ) {
[531] Fix | Delete
return self::EMPTY_STYLE;
[532] Fix | Delete
}
[533] Fix | Delete
[534] Fix | Delete
// If the link color is selected from the theme color picker, the value of $link_color is var:preset|color|slug.
[535] Fix | Delete
// If the link color is selected from the core color picker, the value of $link_color is an hex value.
[536] Fix | Delete
// When the link color is a string var:preset|color|slug we parsed it for get the slug, otherwise we use the hex value.
[537] Fix | Delete
if ( strstr( $link_color, '|' ) ) {
[538] Fix | Delete
$link_color_parts = explode( '|', $link_color );
[539] Fix | Delete
$link_color = self::get_preset_value( end( $link_color_parts ) );
[540] Fix | Delete
}
[541] Fix | Delete
[542] Fix | Delete
return array(
[543] Fix | Delete
'class' => 'has-link-color',
[544] Fix | Delete
'style' => sprintf( 'color: %s;', $link_color ),
[545] Fix | Delete
'value' => $link_color,
[546] Fix | Delete
);
[547] Fix | Delete
}
[548] Fix | Delete
[549] Fix | Delete
/**
[550] Fix | Delete
* Get class and style for margin from attributes.
[551] Fix | Delete
*
[552] Fix | Delete
* @param array $attributes Block attributes.
[553] Fix | Delete
* @return array
[554] Fix | Delete
*/
[555] Fix | Delete
public static function get_margin_class_and_style( $attributes ) {
[556] Fix | Delete
$margin = $attributes['style']['spacing']['margin'] ?? null;
[557] Fix | Delete
[558] Fix | Delete
if ( ! $margin ) {
[559] Fix | Delete
return self::EMPTY_STYLE;
[560] Fix | Delete
}
[561] Fix | Delete
[562] Fix | Delete
$spacing_values_css = '';
[563] Fix | Delete
[564] Fix | Delete
foreach ( $margin as $margin_side => $margin_value ) {
[565] Fix | Delete
$spacing_values_css .= 'margin-' . $margin_side . ':' . self::get_spacing_value( $margin_value ) . ';';
[566] Fix | Delete
}
[567] Fix | Delete
[568] Fix | Delete
return array(
[569] Fix | Delete
'class' => null,
[570] Fix | Delete
'style' => $spacing_values_css,
[571] Fix | Delete
);
[572] Fix | Delete
}
[573] Fix | Delete
[574] Fix | Delete
/**
[575] Fix | Delete
* Get class and style for padding from attributes.
[576] Fix | Delete
*
[577] Fix | Delete
* @param array $attributes Block attributes.
[578] Fix | Delete
*
[579] Fix | Delete
* @return array
[580] Fix | Delete
*/
[581] Fix | Delete
public static function get_padding_class_and_style( $attributes ) {
[582] Fix | Delete
$padding = $attributes['style']['spacing']['padding'] ?? null;
[583] Fix | Delete
[584] Fix | Delete
if ( ! $padding ) {
[585] Fix | Delete
return self::EMPTY_STYLE;
[586] Fix | Delete
}
[587] Fix | Delete
[588] Fix | Delete
$spacing_values_css = '';
[589] Fix | Delete
[590] Fix | Delete
foreach ( $padding as $padding_side => $padding_value ) {
[591] Fix | Delete
$spacing_values_css .= 'padding-' . $padding_side . ':' . self::get_spacing_value( $padding_value ) . ';';
[592] Fix | Delete
}
[593] Fix | Delete
[594] Fix | Delete
return array(
[595] Fix | Delete
'class' => null,
[596] Fix | Delete
'style' => $spacing_values_css,
[597] Fix | Delete
);
[598] Fix | Delete
}
[599] Fix | Delete
[600] Fix | Delete
/**
[601] Fix | Delete
* Get class and style for shadow from attributes.
[602] Fix | Delete
*
[603] Fix | Delete
* @param array $attributes Block attributes.
[604] Fix | Delete
* @return array
[605] Fix | Delete
*/
[606] Fix | Delete
public static function get_shadow_class_and_style( $attributes ) {
[607] Fix | Delete
$shadow = $attributes['style']['shadow'] ?? null;
[608] Fix | Delete
[609] Fix | Delete
if ( ! $shadow ) {
[610] Fix | Delete
return self::EMPTY_STYLE;
[611] Fix | Delete
}
[612] Fix | Delete
[613] Fix | Delete
return array(
[614] Fix | Delete
'class' => null,
[615] Fix | Delete
'style' => sprintf( 'box-shadow: %s;', self::get_shadow_value( $shadow ) ),
[616] Fix | Delete
);
[617] Fix | Delete
}
[618] Fix | Delete
[619] Fix | Delete
/**
[620] Fix | Delete
* Get space-separated style rules from block attributes.
[621] Fix | Delete
*
[622] Fix | Delete
* @param array $attributes Block attributes.
[623] Fix | Delete
* @param array $properties Properties to get styles from.
[624] Fix | Delete
*
[625] Fix | Delete
* @return string Space-separated style rules.
[626] Fix | Delete
*/
[627] Fix | Delete
public static function get_styles_by_attributes( $attributes, $properties = array() ) {
[628] Fix | Delete
$classes_and_styles = self::get_classes_and_styles_by_attributes( $attributes, $properties );
[629] Fix | Delete
[630] Fix | Delete
return $classes_and_styles['styles'];
[631] Fix | Delete
}
[632] Fix | Delete
[633] Fix | Delete
/**
[634] Fix | Delete
* Get class and style for text align from attributes.
[635] Fix | Delete
*
[636] Fix | Delete
* @param array $attributes Block attributes.
[637] Fix | Delete
* @return array
[638] Fix | Delete
*/
[639] Fix | Delete
public static function get_text_align_class_and_style( $attributes ) {
[640] Fix | Delete
// Check if the text align is set in the attributes manually (legacy) or in the global styles.
[641] Fix | Delete
$text_align = $attributes['textAlign'] ?? $attributes['style']['typography']['textAlign'] ?? null;
[642] Fix | Delete
[643] Fix | Delete
if ( $text_align ) {
[644] Fix | Delete
return array(
[645] Fix | Delete
'class' => 'has-text-align-' . $text_align,
[646] Fix | Delete
'style' => null,
[647] Fix | Delete
);
[648] Fix | Delete
}
[649] Fix | Delete
return self::EMPTY_STYLE;
[650] Fix | Delete
}
[651] Fix | Delete
[652] Fix | Delete
/**
[653] Fix | Delete
* Get class and style for text-color from attributes.
[654] Fix | Delete
*
[655] Fix | Delete
* @param array $attributes Block attributes.
[656] Fix | Delete
* @return array
[657] Fix | Delete
*/
[658] Fix | Delete
public static function get_text_color_class_and_style( $attributes ) {
[659] Fix | Delete
[660] Fix | Delete
$text_color = $attributes['textColor'] ?? '';
[661] Fix | Delete
[662] Fix | Delete
$custom_text_color = $attributes['style']['color']['text'] ?? '';
[663] Fix | Delete
[664] Fix | Delete
if ( ! $text_color && ! $custom_text_color ) {
[665] Fix | Delete
return self::EMPTY_STYLE;
[666] Fix | Delete
}
[667] Fix | Delete
[668] Fix | Delete
if ( $text_color ) {
[669] Fix | Delete
return array(
[670] Fix | Delete
'class' => sprintf( 'has-text-color has-%s-color', $text_color ),
[671] Fix | Delete
'style' => null,
[672] Fix | Delete
'value' => self::get_preset_value( $text_color ),
[673] Fix | Delete
);
[674] Fix | Delete
} elseif ( $custom_text_color ) {
[675] Fix | Delete
return array(
[676] Fix | Delete
'class' => null,
[677] Fix | Delete
'style' => sprintf( 'color: %s;', $custom_text_color ),
[678] Fix | Delete
'value' => $custom_text_color,
[679] Fix | Delete
);
[680] Fix | Delete
}
[681] Fix | Delete
[682] Fix | Delete
return self::EMPTY_STYLE;
[683] Fix | Delete
}
[684] Fix | Delete
[685] Fix | Delete
/**
[686] Fix | Delete
* Get class and style for text-decoration from attributes.
[687] Fix | Delete
*
[688] Fix | Delete
* @param array $attributes Block attributes.
[689] Fix | Delete
*
[690] Fix | Delete
* @return array
[691] Fix | Delete
*/
[692] Fix | Delete
public static function get_text_decoration_class_and_style( $attributes ) {
[693] Fix | Delete
[694] Fix | Delete
$custom_text_decoration = $attributes['style']['typography']['textDecoration'] ?? '';
[695] Fix | Delete
[696] Fix | Delete
if ( '' !== $custom_text_decoration ) {
[697] Fix | Delete
return array(
[698] Fix | Delete
'class' => null,
[699] Fix | Delete
'style' => sprintf( 'text-decoration: %s;', $custom_text_decoration ),
[700] Fix | Delete
);
[701] Fix | Delete
}
[702] Fix | Delete
[703] Fix | Delete
return self::EMPTY_STYLE;
[704] Fix | Delete
}
[705] Fix | Delete
[706] Fix | Delete
/**
[707] Fix | Delete
* Get class and style for text-transform from attributes.
[708] Fix | Delete
*
[709] Fix | Delete
* @param array $attributes Block attributes.
[710] Fix | Delete
* @return array
[711] Fix | Delete
*/
[712] Fix | Delete
public static function get_text_transform_class_and_style( $attributes ) {
[713] Fix | Delete
[714] Fix | Delete
$custom_text_transform = $attributes['style']['typography']['textTransform'] ?? '';
[715] Fix | Delete
[716] Fix | Delete
if ( '' !== $custom_text_transform ) {
[717] Fix | Delete
return array(
[718] Fix | Delete
'class' => null,
[719] Fix | Delete
'style' => sprintf( 'text-transform: %s;', $custom_text_transform ),
[720] Fix | Delete
);
[721] Fix | Delete
}
[722] Fix | Delete
return self::EMPTY_STYLE;
[723] Fix | Delete
}
[724] Fix | Delete
[725] Fix | Delete
/**
[726] Fix | Delete
* Get extra CSS classes from attributes.
[727] Fix | Delete
*
[728] Fix | Delete
* @param array $attributes Block attributes.
[729] Fix | Delete
* @return array
[730] Fix | Delete
*/
[731] Fix | Delete
public static function get_classes_from_attributes( $attributes ) {
[732] Fix | Delete
[733] Fix | Delete
$extra_css_classes = $attributes['className'] ?? '';
[734] Fix | Delete
[735] Fix | Delete
if ( '' !== $extra_css_classes ) {
[736] Fix | Delete
return array(
[737] Fix | Delete
'class' => esc_attr( $extra_css_classes ),
[738] Fix | Delete
'style' => null,
[739] Fix | Delete
);
[740] Fix | Delete
}
[741] Fix | Delete
return self::EMPTY_STYLE;
[742] Fix | Delete
}
[743] Fix | Delete
[744] Fix | Delete
/**
[745] Fix | Delete
* Get classes and styles from attributes.
[746] Fix | Delete
*
[747] Fix | Delete
* Excludes link_color and link_hover_color since those should not apply to the container.
[748] Fix | Delete
*
[749] Fix | Delete
* @param array $attributes Block attributes.
[750] Fix | Delete
* @param array $properties Properties to get classes/styles from.
[751] Fix | Delete
* @param array $exclude Properties to exclude.
[752] Fix | Delete
* @return array
[753] Fix | Delete
*/
[754] Fix | Delete
public static function get_classes_and_styles_by_attributes( $attributes, $properties = array(), $exclude = array() ) {
[755] Fix | Delete
$classes_and_styles = array(
[756] Fix | Delete
'align' => self::get_align_class_and_style( $attributes ),
[757] Fix | Delete
'background_color' => self::get_background_color_class_and_style( $attributes ),
[758] Fix | Delete
'border_color' => self::get_border_color_class_and_style( $attributes ),
[759] Fix | Delete
'border_radius' => self::get_border_radius_class_and_style( $attributes ),
[760] Fix | Delete
'border_width' => self::get_border_width_class_and_style( $attributes ),
[761] Fix | Delete
'border_style' => self::get_border_style_class_and_style( $attributes ),
[762] Fix | Delete
'font_family' => self::get_font_family_class_and_style( $attributes ),
[763] Fix | Delete
'font_size' => self::get_font_size_class_and_style( $attributes ),
[764] Fix | Delete
'font_style' => self::get_font_style_class_and_style( $attributes ),
[765] Fix | Delete
'font_weight' => self::get_font_weight_class_and_style( $attributes ),
[766] Fix | Delete
'letter_spacing' => self::get_letter_spacing_class_and_style( $attributes ),
[767] Fix | Delete
'line_height' => self::get_line_height_class_and_style( $attributes ),
[768] Fix | Delete
'margin' => self::get_margin_class_and_style( $attributes ),
[769] Fix | Delete
'padding' => self::get_padding_class_and_style( $attributes ),
[770] Fix | Delete
'shadow' => self::get_shadow_class_and_style( $attributes ),
[771] Fix | Delete
'text_align' => self::get_text_align_class_and_style( $attributes ),
[772] Fix | Delete
'text_color' => self::get_text_color_class_and_style( $attributes ),
[773] Fix | Delete
'text_decoration' => self::get_text_decoration_class_and_style( $attributes ),
[774] Fix | Delete
'text_transform' => self::get_text_transform_class_and_style( $attributes ),
[775] Fix | Delete
'extra_classes' => self::get_classes_from_attributes( $attributes ),
[776] Fix | Delete
);
[777] Fix | Delete
[778] Fix | Delete
if ( ! empty( $properties ) ) {
[779] Fix | Delete
foreach ( $classes_and_styles as $key => $value ) {
[780] Fix | Delete
if ( ! in_array( $key, $properties, true ) ) {
[781] Fix | Delete
unset( $classes_and_styles[ $key ] );
[782] Fix | Delete
}
[783] Fix | Delete
}
[784] Fix | Delete
}
[785] Fix | Delete
[786] Fix | Delete
if ( ! empty( $exclude ) ) {
[787] Fix | Delete
foreach ( $classes_and_styles as $key => $value ) {
[788] Fix | Delete
if ( in_array( $key, $exclude, true ) ) {
[789] Fix | Delete
unset( $classes_and_styles[ $key ] );
[790] Fix | Delete
}
[791] Fix | Delete
}
[792] Fix | Delete
}
[793] Fix | Delete
[794] Fix | Delete
$classes_and_styles = array_filter( $classes_and_styles );
[795] Fix | Delete
[796] Fix | Delete
$classes = array_map(
[797] Fix | Delete
function ( $item ) {
[798] Fix | Delete
return $item['class'];
[799] Fix | Delete
},
[800] Fix | Delete
$classes_and_styles
[801] Fix | Delete
);
[802] Fix | Delete
[803] Fix | Delete
$styles = array_map(
[804] Fix | Delete
function ( $item ) {
[805] Fix | Delete
return $item['style'];
[806] Fix | Delete
},
[807] Fix | Delete
// Exclude link color styles from parent to avoid conflict with text color.
[808] Fix | Delete
array_diff_key(
[809] Fix | Delete
$classes_and_styles,
[810] Fix | Delete
array_flip( array( 'link_color' ) )
[811] Fix | Delete
)
[812] Fix | Delete
);
[813] Fix | Delete
[814] Fix | Delete
$classes = array_filter( $classes );
[815] Fix | Delete
$styles = array_filter( $styles );
[816] Fix | Delete
[817] Fix | Delete
return array(
[818] Fix | Delete
'classes' => implode( ' ', $classes ),
[819] Fix | Delete
'styles' => implode( ' ', $styles ),
[820] Fix | Delete
);
[821] Fix | Delete
}
[822] Fix | Delete
}
[823] Fix | Delete
[824] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function