Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/inc/components/media/simple.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + /**
4 + * Generate an image container based on image URL.
5 + *
6 + * @param string $image_src URL to the image.
7 + * @param array $args various params that the function accepts.
8 + */
9 + if (! function_exists('blocksy_simple_image')) {
10 + function blocksy_simple_image($image_src, $args = []) {
11 + $args = wp_parse_args(
12 + $args,
13 + [
14 + 'ratio' => '1/1',
15 + 'class' => '',
16 + 'aspect_ratio' => true,
17 + 'tag_name' => 'div',
18 + 'html_atts' => [],
19 + 'img_atts' => [],
20 + 'inner_content' => '',
21 + 'lazyload' => true,
22 + 'size' => 'medium',
23 + 'suffix' => '',
24 + 'has_default_alt' => true,
25 + 'has_default_class' => true,
26 + ]
27 + );
28 + $original = '';
29 +
30 + if ($args['has_default_class']) {
31 + $original = 'ct-media-container';
32 + }
33 +
34 + if (! empty($args['suffix'])) {
35 + $original .= '-' . $args['suffix'];
36 + }
37 +
38 + if ($args['aspect_ratio']) {
39 + $args['img_atts']['style'] = isset($args['img_atts']['style'])
40 + ? $args['img_atts']['style'] . ';'
41 + : '';
42 + $args['img_atts']['style'] .= blocksy_generate_ratio($args['ratio']);
43 + }
44 +
45 + $other_img_atts = '';
46 +
47 + if (! isset($args['img_atts']['alt']) && $args['has_default_alt']) {
48 + $args['img_atts']['alt'] = __('Default image', 'blocksy');
49 + }
50 +
51 + foreach ($args['img_atts'] as $attr => $value) {
52 + $other_img_atts .= $attr . '="' . $value . '" ';
53 + }
54 +
55 + if (! isset($args['html_atts']['class'])) {
56 + $args['html_atts']['class'] = $original;
57 + } else {
58 + $args['html_atts']['class'] = join(' ', [$original, $args['html_atts']['class']]);
59 + }
60 +
61 + $image_content = blocksy_html_tag(
62 + 'img',
63 + array_merge(
64 + [
65 + 'src' => $image_src
66 + ],
67 + $args['img_atts']
68 + )
69 + );
70 +
71 + if (
72 + wp_lazy_loading_enabled('img', 'blocksy_simple_image')
73 + &&
74 + false === strpos($image_content, ' loading=')
75 + ) {
76 + if (function_exists('wp_img_tag_add_loading_optimization_attrs')) {
77 + $image_content = wp_img_tag_add_loading_optimization_attrs(
78 + $image_content,
79 + 'blocksy_simple_image'
80 + );
81 + } else {
82 + $image_content = wp_img_tag_add_loading_attr(
83 + $image_content,
84 + 'blocksy_simple_image'
85 + );
86 + }
87 + }
88 +
89 + return blocksy_html_tag(
90 + $args['tag_name'],
91 + $args['html_atts'],
92 + $image_content . $args['inner_content']
93 + );
94 + }
95 + }
96 +