| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical. |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
if ( ! $show_icon ) { |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
$category_icon_meta_key = empty( $term_icon_meta_key ) ? 'doc_category_image-id' : $term_icon_meta_key; |
| 12 |
$cat_icon_id = get_term_meta( $term_id, $category_icon_meta_key, true ); |
| 13 |
|
| 14 |
$attr['alt'] = 'betterdocs-category-icon'; |
| 15 |
|
| 16 |
if ( isset( $cat_icon_id ) && ( isset( $category_icon ) && ( $category_icon == 'folder' || $category_icon == 'folder-open' ) ) ) { |
| 17 |
$attr['class'] = [ 'betterdocs-category-folder-img' ]; |
| 18 |
} else { |
| 19 |
$attr['class'] = [ 'betterdocs-category-icon-img' ]; |
| 20 |
} |
| 21 |
|
| 22 |
if ( $cat_icon_id ) { |
| 23 |
$icon_url = wp_get_attachment_image_url( $cat_icon_id, 'thumbnail' ); |
| 24 |
$attr['alt'] = get_post_meta( $cat_icon_id, '_wp_attachment_image_alt', true ); |
| 25 |
} else { |
| 26 |
$icon_url = betterdocs()->assets->icon( 'betterdocs-cat-icon.svg', true ); |
| 27 |
} |
| 28 |
|
| 29 |
$attr['src'] = esc_url( $icon_url ); |
| 30 |
$image_attributes = betterdocs()->template_helper->get_html_attributes( $attr ); |
| 31 |
?> |
| 32 |
|
| 33 |
<div class="betterdocs-category-icon"> |
| 34 |
<?php |
| 35 |
if ( isset( $category_icon ) && $category_icon == 'folder' ) { |
| 36 |
if ( $cat_icon_id ) { |
| 37 |
echo '<span class="betterdocs-folder-icon">'; |
| 38 |
echo wp_kses_post( '<img ' . $image_attributes . ' />' ); |
| 39 |
echo '</span>'; |
| 40 |
} else { |
| 41 |
betterdocs()->template_helper->icon( 'folder', true ); |
| 42 |
} |
| 43 |
} elseif ( isset( $category_icon ) && $category_icon == 'folder-open' ) { |
| 44 |
if ( $cat_icon_id ) { |
| 45 |
echo '<span class="betterdocs-folder-icon">'; |
| 46 |
echo wp_kses_post( '<img ' . $image_attributes . ' />' ); |
| 47 |
echo '</span>'; |
| 48 |
} else { |
| 49 |
betterdocs()->template_helper->icon( 'folder-open', true ); |
| 50 |
} |
| 51 |
} else { |
| 52 |
echo wp_kses_post( '<img ' . $image_attributes . ' />' ); |
| 53 |
} |
| 54 |
?> |
| 55 |
</div> |
| 56 |
|