PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.5.0
Easy Elements for Elementor – Addons & Website Templates v1.5.0
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / breadcrumb / helper.php

helper.php in Easy Elements for Elementor – Addons & Website Templates 1.5.0, at widgets/breadcrumb/helper.php

179 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3
4 /**
5 * Define SVG allowed HTML tags for wp_kses
6 *
7 * @return array Array of allowed tags and attributes for SVG
8 */
9 if (!function_exists('easyel_helper_svg_allowed_html')) {
10 function easyel_helper_svg_allowed_html() {
11 return array(
12 'svg' => array(
13 'xmlns' => true,
14 'fill' => true,
15 'viewbox' => true,
16 'role' => true,
17 'aria-hidden' => true,
18 'focusable' => true,
19 'class' => true,
20 'width' => true,
21 'height' => true,
22 ),
23 'path' => array(
24 'd' => true,
25 'fill' => true,
26 ),
27 'polygon' => array(
28 'fill' => true,
29 'points' => true,
30 ),
31 'circle' => array(
32 'cx' => true,
33 'cy' => true,
34 'r' => true,
35 'fill' => true,
36 ),
37 );
38 }
39 }
40
41 if (!function_exists('easyel_get_easyel_breadcrumb')) {
42 function easyel_get_easyel_breadcrumb(
43 $custom_title = '',
44 $custom_path = '',
45 $custom_separator = '',
46 $custom_home_title = '',
47 $search_custom_title = '',
48 $search_result_title = '',
49 $show_category_path = true,
50 $home_icon_url = '',
51 $home_icon_picker = ''
52 ) {
53 global $post;
54 $post = get_queried_object();
55 $object_id = get_queried_object_id();
56 $home_title = !empty($custom_home_title) ? $custom_home_title : 'Home';
57
58 // Separator
59 $separator = !empty($custom_separator) ? $custom_separator : '<span class="breadcrumb-separator">/</span>';
60
61 // Home icon
62 $home_icon = !empty($home_icon_picker) ? $home_icon_picker : '';
63 $home_link = '<a href="' . esc_url(home_url('/')) . '">' . $home_icon . (!empty($home_icon) ? ' ' : '') . '<span class="breadcrumb-home-text">' . esc_html($home_title) . '</span></a>';
64 $output = $home_link;
65
66 // Single Post
67 if (is_single()) {
68 $post_type = get_post_type();
69
70 if ($post_type != 'post') {
71 // Custom Post Type
72 $post_type_object = get_post_type_object($post_type);
73 if ($post_type_object && $post_type_object->has_archive) {
74 $output .= $separator . '<a href="' . esc_url(get_post_type_archive_link($post_type)) . '">' . esc_html($post_type_object->labels->name) . '</a>';
75 }
76 if ($show_category_path) {
77 $taxonomies = get_object_taxonomies($post_type, 'objects');
78 foreach ($taxonomies as $taxonomy) {
79 if ($taxonomy->hierarchical) {
80 $terms = get_the_terms($object_id, $taxonomy->name);
81 if ($terms && !is_wp_error($terms)) {
82 $main_term = $terms[0];
83 if ($main_term->parent != 0) {
84 $ancestors = get_ancestors($main_term->term_id, $taxonomy->name);
85 $ancestors = array_reverse($ancestors);
86 foreach ($ancestors as $ancestor) {
87 $ancestor_term = get_term($ancestor, $taxonomy->name);
88 $output .= $separator . '<a href="' . esc_url(get_term_link($ancestor_term)) . '">' . esc_html($ancestor_term->name) . '</a>';
89 }
90 }
91 $output .= $separator . '<a href="' . esc_url(get_term_link($main_term)) . '">' . esc_html($main_term->name) . '</a>';
92 }
93 }
94 }
95 }
96 }
97
98 // Categories for normal posts
99 if ($post_type == 'post' && $show_category_path) {
100 $categories = get_the_category($object_id);
101 if (!empty($categories) && !is_wp_error($categories)) {
102 $main_cat = $categories[0];
103
104 // Include parent categories
105 $parent_cats = get_ancestors($main_cat->term_id, 'category');
106 if (!empty($parent_cats)) {
107 $parent_cats = array_reverse($parent_cats);
108 foreach ($parent_cats as $parent_id) {
109 $parent_term = get_term($parent_id, 'category');
110 if ($parent_term && !is_wp_error($parent_term)) {
111 $output .= $separator . '<a href="' . esc_url(get_term_link($parent_term)) . '">' . esc_html($parent_term->name) . '</a>';
112 }
113 }
114 }
115
116 // Main category
117 $output .= $separator . '<a href="' . esc_url(get_term_link($main_cat)) . '">' . esc_html($main_cat->name) . '</a>';
118 }
119 }
120
121 // Post title
122 $output .= $separator . '<span class="breadcrumb-text">' . esc_html(get_the_title()) . '</span>';
123 }
124
125 // Page
126 elseif (is_page()) {
127 if ($post->post_parent) {
128 $ancestors = array_reverse(get_post_ancestors($post->ID));
129 foreach ($ancestors as $ancestor) {
130 $output .= $separator . '<a href="' . esc_url(get_permalink($ancestor)) . '">' . esc_html(get_the_title($ancestor)) . '</a>';
131 }
132 }
133 $output .= $separator . '<span class="breadcrumb-text">' . esc_html(get_the_title()) . '</span>';
134 }
135
136 // Category / Tag / Taxonomy
137 elseif (is_category() || is_tag() || is_tax()) {
138 $term = get_queried_object();
139 if ($term && !is_wp_error($term)) {
140 if ($term->parent != 0) {
141 $ancestors = array_reverse(get_ancestors($term->term_id, $term->taxonomy));
142 foreach ($ancestors as $ancestor) {
143 $ancestor_term = get_term($ancestor, $term->taxonomy);
144 $output .= $separator . '<a href="' . esc_url(get_term_link($ancestor_term)) . '">' . esc_html($ancestor_term->name) . '</a>';
145 }
146 }
147 $output .= $separator . '<span class="breadcrumb-text">' . esc_html(single_term_title('', false)) . '</span>';
148 }
149 }
150
151 // Post type archive
152 elseif (is_post_type_archive()) {
153 $output .= $separator . '<span class="breadcrumb-text">' . esc_html(post_type_archive_title('', false)) . '</span>';
154 }
155
156 // Blog page
157 elseif (is_home() && !is_front_page()) {
158 $blog_title = get_the_title(get_option('page_for_posts'));
159 $output .= $separator . '<span class="breadcrumb-text">' . esc_html($blog_title) . '</span>';
160 }
161
162 // Search
163 elseif (is_search()) {
164 $output .= $separator . '<span class="breadcrumb-text">' . esc_html__('Search Results for:', 'easy-elements') . ' ' . esc_html(get_search_query()) . '</span>';
165 }
166
167 // 404
168 elseif (is_404()) {
169 $output .= $separator . '<span class="breadcrumb-text">' . esc_html__('404 Not Found', 'easy-elements') . '</span>';
170 }
171
172 // Allowed tags
173 $allowed_tags = array_merge(wp_kses_allowed_html('post'), easyel_helper_svg_allowed_html());
174
175 // Elementor-friendly: return instead of echo
176 return '<div class="eel-breadcrumb"><div class="breadcrumb-path">' . wp_kses($output, $allowed_tags) . '</div></div>';
177 }
178 }
179