-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.php
55 lines (47 loc) · 2.03 KB
/
utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace MRW\Accordion;
/**
* generate the full string for all classes that may appear on the accordion
*
* @param boolean $font_size whether there is a custom font size
* @param boolean $bg_color whether there is a custom background color
* @param boolean $text_color whether there is a custom text color
* @return string full space-separated list of classes for accordion heading
*/
function get_accordion_heading_classes( $font_size = false, $bg_color = false, $text_color = false ) {
$theme_settings = wp_get_global_settings();
$classes = 'mrw-accordion__heading';
if( $font_size ) {
$font_sizes = wp_list_pluck( array_merge( ...array_values( $theme_settings['typography']['fontSizes'] ) ), 'slug', 'size' );
$heading_font_size_slug = $font_sizes[$font_size] ?? false;
if( $heading_font_size_slug ) {
$classes .= ' has-' . esc_attr( $heading_font_size_slug ) . '-font-size';
}
}
/* merge all default, theme, and user colors into single array of format '#hex' => 'slug' */
$colors = wp_list_pluck( array_merge( ...array_values( $theme_settings['color']['palette'] ) ), 'slug', 'color' );
$primary_color_slug = $colors[$bg_color] ?? false;
$text_color_slug = $colors[$text_color] ?? false;
if( $primary_color_slug ) {
$classes .= ' has-' . esc_attr( $primary_color_slug ) . '-background-color';
$classes .= ' has-background';
}
if( $text_color_slug ) {
$classes .= ' has-' . esc_attr( $text_color_slug ) . '-color';
$classes .= ' has-text-color';
}
return $classes;
}
/**
* Remove a heading and its content from an HTML string
*
* @param int $level level of heading
* @param string $heading heading content
* @param string $content content to replace heading in
* @return string $content with heading removed
*/
function strip_heading( $level, $heading, $content ) {
/* Due to current "Hybrid Block" strategy, I now need to filter out the first block which is the heading */
$search_string = "<h{$level}>{$heading}</h{$level}>";
return trim( str_replace( $search_string, '', html_entity_decode( $content ) ) );
}