| @@ -1,243 +1,46 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * | |
| 4 | - * | |
| 5 | - * @link https://catchplugins.com/plugins | |
| 6 | - * @since 1.0.0 | |
| 7 | - * | |
| 8 | - * @package breadcrumb | |
| 9 | - * @subpackage Breadcrumb/includes | |
| 10 | - */ | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * | |
| 14 | - * | |
| 15 | - * @package Breadcrumb | |
| 16 | - * @subpackage Breadcrumb/includes | |
| 17 | - * @author Catch Plugins <info@catchplugins.com | |
| 18 | - */ | |
| 19 | - | |
| 20 | - | |
| 21 | -class Catch_Breadcrumb_Shortcode { | |
| 22 | - public function __construct() { | |
| 23 | - add_shortcode( 'catch-breadcrumb', array( $this, 'catch_breadcrumb_shortcode' ) ); | |
| 24 | - } | |
| 25 | - | |
| 26 | - public function catch_display_breadcrumb(){ | |
| 27 | - do_shortcode( '[catch-breadcrumb]' ); | |
| 28 | - } | |
| 29 | - | |
| 30 | - public function catch_breadcrumb_shortcode( $atts,$content ) { | |
| 31 | - if ( function_exists( 'woocommerce_breadcrumb' ) && ( is_woocommerce() || is_shop() ) ) : ?> | |
| 32 | - <div class="breadcrumb-area"> | |
| 33 | - <div class="section-wrapper"> | |
| 34 | - <?php | |
| 35 | - $catch_breadcrumb_options = catch_breadcrumb_get_options(); | |
| 36 | - $breadcrumb_separator = $catch_breadcrumb_options['breadcrumb_separator']; | |
| 37 | - | |
| 38 | - if ( $breadcrumb_separator ) { | |
| 39 | - $breadcrumb_separator = '<span class="sep">' . $breadcrumb_separator . '</span>'; | |
| 40 | - } | |
| 41 | - | |
| 42 | - $args = array( | |
| 43 | - 'delimiter' => $breadcrumb_separator, | |
| 44 | - 'before' => '<span class="breadcrumb">', | |
| 45 | - 'after' => '</span>', | |
| 46 | - ); | |
| 47 | - | |
| 48 | - woocommerce_breadcrumb( $args ); | |
| 49 | - ?> | |
| 50 | - </div><!-- .wrapper --> | |
| 51 | - </div><!-- .breadcrumb-area --> | |
| 52 | - <?php | |
| 53 | - else: | |
| 54 | - self::breadcrumb( $atts,$content ); | |
| 55 | - endif; | |
| 56 | - } | |
| 57 | - | |
| 58 | - public function breadcrumb( $atts,$content ) { | |
| 59 | - $defaults = array( | |
| 60 | - 'before' => '<span class="breadcrumb-current">',// code before the breadcrumb section | |
| 61 | - 'after' => '</span>', // code after the breadcrumb section | |
| 62 | - 'showCurrent'=> 1,// 1 - show current post/page title in breadcrumbs, 0 - don't show | |
| 63 | - //'echo' => true, | |
| 64 | - 'linkBefore' => '<span class="breadcrumb" typeof="v:Breadcrumb">', | |
| 65 | - 'linkAfter' => '</span>', | |
| 66 | - ); | |
| 67 | - $atts = wp_parse_args( $atts, $defaults ); | |
| 68 | - $content= $atts['before']; | |
| 69 | - $catch_breadcrumb_options = catch_breadcrumb_get_options(); | |
| 70 | - if ( $catch_breadcrumb_options['breadcrumb_separator'] ) { | |
| 71 | - $catch_breadcrumb_options['breadcrumb_separator'] = '<span class="sep">' . $catch_breadcrumb_options['breadcrumb_separator'] . '</span>'; | |
| 72 | - } | |
| 73 | - | |
| 74 | - /* === OPTIONS === */ | |
| 75 | - $text['home'] = esc_html__( 'Home', 'catch-breadcrumb' ); // text for the 'Home' link | |
| 76 | - /* translators: 1: before text/html, 2: after text/html. */ | |
| 77 | - $text['category'] = esc_html__( '%1$s Archive for %2$s', 'catch-breadcrumb' ); // text for a category page | |
| 78 | - /* translators: 1: before text/html, 2: after text/html. */ | |
| 79 | - $text['search'] = esc_html__( '%1$sSearch results for: %2$s', 'catch-breadcrumb' ); // text for a search results page | |
| 80 | - /* translators: 1: before text/html, 2: after text/html. */ | |
| 81 | - $text['tag'] = esc_html__( '%1$sPosts tagged %2$s', 'catch-breadcrumb' ); // text for a tag page | |
| 82 | - /* translators: 1: before text/html, 2: after text/html. */ | |
| 83 | - $text['author'] = esc_html__( '%1$sView all posts by %2$s', 'catch-breadcrumb' ); // text for an author page | |
| 84 | - $text['404'] = esc_html__( 'Error 404', 'catch-breadcrumb' ); // text for the 404 page | |
| 85 | - /* === END OF OPTIONS === */ | |
| 86 | - global $post, $paged, $page; | |
| 87 | - $homeLink = home_url( '/' ); | |
| 88 | - $style = ''; | |
| 89 | - if( $style ){ | |
| 90 | - echo '<style>' . $style . '</style>'; | |
| 91 | - } | |
| 92 | - $linkAttr = ' rel="v:url" property="v:title"'; | |
| 93 | - $home_icon = ''; | |
| 94 | - | |
| 95 | - if ( $catch_breadcrumb_options['breadcrumb_home_icon'] ){ | |
| 96 | - $home_icon = '<span class="fa fa-home"></span>'; | |
| 97 | - } | |
| 98 | - | |
| 99 | - $link_home = $atts['linkBefore'] . '<a' . $linkAttr . ' href="%1$s">'. $home_icon . '%2$s</a>' . wp_kses_post( $catch_breadcrumb_options['breadcrumb_separator'] ) . $atts['linkAfter']; | |
| 100 | - | |
| 101 | - $link = $atts['linkBefore'] . '<a' . $linkAttr . ' href="%1$s">' . '%2$s</a>' . wp_kses_post( $catch_breadcrumb_options['breadcrumb_separator'] ) . $atts['linkAfter']; | |
| 102 | - | |
| 103 | - if ( is_front_page() ) { | |
| 104 | - if ( $catch_breadcrumb_options['breadcrumb_display_home'] ) { | |
| 105 | - echo ' | |
| 106 | - <div class="catch-breadcrumb breadcrumb-area custom"> | |
| 107 | - <nav class="entry-breadcrumbs">'; | |
| 108 | - echo $atts['linkBefore'] . '<a href="' . esc_url( $homeLink ) . '">' . $home_icon . $text['home'] . '</a>' . $atts['linkAfter']; | |
| 109 | - echo '</nav><!-- .entry-breadcrumbs --> | |
| 110 | - </div><!-- .breadcrumb-area -->';$atts['linkAfter']; | |
| 111 | - } | |
| 112 | - } else { | |
| 113 | - | |
| 114 | - echo '<div class="catch-breadcrumb breadcrumb-area custom"> | |
| 115 | - <nav class="entry-breadcrumbs">'; | |
| 116 | - echo sprintf( $link_home, esc_url( $homeLink ), $text['home'] ); // WPCS: XSS OK. | |
| 117 | - | |
| 118 | - if ( is_home() ) { | |
| 119 | - echo $content . esc_html( get_the_title( get_option( 'page_for_posts', true ) ) ) . $atts['after']; // WPCS: XSS OK. | |
| 120 | - } elseif ( is_category() ) { | |
| 121 | - $thisCat = get_category( get_query_var( 'cat' ), false ); | |
| 122 | - if ( $thisCat->parent != 0 ) { | |
| 123 | - $cats = get_category_parents( $thisCat->parent, true, false ); | |
| 124 | - $cats = str_replace( '<a', $atts['linkBefore'] . '<a' . $linkAttr, $cats ); | |
| 125 | - $cats = str_replace( '</a>', '</a>' . wp_kses_post( $catch_breadcrumb_options['breadcrumb_separator']) . $atts['linkAfter'], $cats ); | |
| 126 | - echo $cats; | |
| 127 | - // WPCS: XSS OK. | |
| 128 | - } | |
| 129 | - | |
| 130 | - the_archive_title( $content . sprintf( $text['category'], '<span class="archive-text">', '</span>' , $atts['after'] )); | |
| 131 | - | |
| 132 | - } elseif ( is_search() ) { | |
| 133 | - echo $content . sprintf( $text['search'], '<span class="search-text">', '</span>' . get_search_query() ) . $atts['after']; | |
| 134 | - // WPCS: XSS OK. | |
| 135 | - } elseif ( is_day() ) { | |
| 136 | - echo sprintf( $link, esc_url( get_year_link( get_the_time( __( 'Y', 'catch-breadcrumb' ) ) ) ), esc_html( get_the_time( __( 'Y', 'catch-breadcrumb' ) ) ) ) ; | |
| 137 | - // WPCS: XSS OK. | |
| 138 | - echo sprintf( $link, esc_url( get_month_link( get_the_time( __( 'Y', 'catch-breadcrumb' ) ) ) ), esc_html(get_the_time( __( 'F', 'catch-breadcrumb' ) ) ) ); | |
| 139 | - // WPCS: XSS OK. | |
| 140 | - echo $content . esc_html( get_the_time( __( 'd', 'catch-breadcrumb' ) ) ) . $atts['after']; | |
| 141 | - // WPCS: XSS OK. | |
| 142 | - } elseif ( is_month() ) { | |
| 143 | - echo sprintf( $link, esc_url( get_year_link( get_the_time( __( 'Y', 'catch-breadcrumb' ) ) ) ), esc_html( get_the_time( __( 'Y', 'catch-breadcrumb' ) ) ) ) ; | |
| 144 | - // WPCS: XSS OK. | |
| 145 | - echo $content . esc_html( get_the_time( __( 'F', 'catch-breadcrumb' ) ) ) . $atts['after']; | |
| 146 | - // WPCS: XSS OK. | |
| 147 | - } elseif ( is_year() ) { | |
| 148 | - echo $content . esc_html( get_the_time( __( 'Y', 'catch-breadcrumb' ) ) ) . $atts['after']; | |
| 149 | - // WPCS: XSS OK. | |
| 150 | - } elseif ( is_single() && !is_attachment() ) { | |
| 151 | - if ( get_post_type() != 'post' ) { | |
| 152 | - $post_type = get_post_type_object( get_post_type() ); | |
| 153 | - $post_link = get_post_type_archive_link( $post_type->name ); | |
| 154 | - printf( $link, esc_url( $post_link ), esc_html( $post_type->labels->singular_name ) ); | |
| 155 | - // WPCS: XSS OK. | |
| 156 | - echo $content . esc_html( get_the_title() ) . $atts['after']; | |
| 157 | - // WPCS: XSS OK | |
| 158 | - } | |
| 159 | - else { | |
| 160 | - $cat = get_the_category(); | |
| 161 | - $cat = $cat[0]; | |
| 162 | - $cats = get_category_parents( $cat, true, '' ); | |
| 163 | - $cats = preg_replace( "#^(.+)$#", "$1", $cats ); | |
| 164 | - $cats = str_replace( '<a', $atts['linkBefore'] . '<a' . $linkAttr, $cats ); | |
| 165 | - $cats = str_replace( '</a>', '</a>' . wp_kses_post( $catch_breadcrumb_options['breadcrumb_separator'] ) . $atts['linkAfter'], $cats ); | |
| 166 | - echo $cats; | |
| 167 | - // WPCS: XSS OK. | |
| 168 | - | |
| 169 | - echo $content . esc_html( get_the_title() ) . $atts['after']; | |
| 170 | - // WPCS: XSS OK. | |
| 171 | - } | |
| 172 | - } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) { | |
| 173 | - $post_type = get_post_type_object( get_post_type() ); | |
| 174 | - echo isset( $post_type->labels->singular_name ) ? $content. esc_html( $post_type->labels->singular_name ) . $atts['after']: ''; | |
| 175 | - // WPCS: XSS OK. | |
| 176 | - } elseif ( is_attachment() ) { | |
| 177 | - $parent = get_post( $post->post_parent ); | |
| 178 | - $cat = get_the_category( $parent->ID ); | |
| 179 | - if ( isset( $cat[0] ) ) { | |
| 180 | - $cat = $cat[0]; | |
| 181 | - } | |
| 182 | - if ( $cat ) { | |
| 183 | - $cats = get_category_parents( $cat, true ); | |
| 184 | - $cats = str_replace( '<a', $atts['linkBefore'] . '<a' . $linkAttr, $cats ); | |
| 185 | - $cats = str_replace( '</a>', '</a>' . wp_kses_post( $catch_breadcrumb_options['breadcrumb_separator'] ) . $atts['linkAfter'], $cats ); | |
| 186 | - echo $cats; | |
| 187 | - // WPCS: XSS OK. | |
| 188 | - } | |
| 189 | - printf( $link, esc_url( get_permalink( $parent ) ), esc_html( $parent->post_title ) ); | |
| 190 | - // WPCS: XSS OK. | |
| 191 | - echo $content . esc_html( get_the_title() ) . $atts['after']; | |
| 192 | - // WPCS: XSS OK. | |
| 193 | - } elseif ( is_page() && ! $post->post_parent ) { | |
| 194 | - echo $content. esc_html( get_the_title() ) . $atts['after']; // WPCS: XSS O | |
| 195 | - } elseif ( is_page() && $post->post_parent ) { | |
| 196 | - $parent_id = $post->post_parent; | |
| 197 | - $breadcrumbs = array(); | |
| 198 | - while( $parent_id ) { | |
| 199 | - $page_child = get_post( $parent_id ); | |
| 200 | - $breadcrumbs[] = sprintf( $link, esc_url( get_permalink( $page_child->ID ) ), esc_html( get_the_title( $page_child->ID ) ) ); | |
| 201 | - $parent_id = $page_child->post_parent; | |
| 202 | - } | |
| 203 | - $breadcrumbs = array_reverse( $breadcrumbs ); | |
| 204 | - for( $i = 0; $i < count( $breadcrumbs ); $i++ ) { | |
| 205 | - echo $breadcrumbs[$i]; | |
| 206 | - // WPCS: XSS OK. | |
| 207 | - } | |
| 208 | - echo $content . esc_html( get_the_title() ) . $atts['after']; | |
| 209 | - // WPCS: XSS OK. | |
| 210 | - } elseif ( is_tag() ) { | |
| 211 | - the_archive_title( $content . sprintf( $text['tag'], '<span class="tag-text">', '</span>' ), $atts['after'] ); | |
| 212 | - // WPCS: XSS OK | |
| 213 | - } elseif ( is_author() ) { | |
| 214 | - global $author; | |
| 215 | - $userdata = get_userdata( $author ); | |
| 216 | - echo $content . sprintf( $text['author'], '<span class="author-text">', '</span>' . $userdata->display_name ) . $atts['after']; | |
| 217 | - // WPCS: XSS OK | |
| 218 | - } elseif ( is_404() ) { | |
| 219 | - echo $content . $text['404'] . $atts['after']; | |
| 220 | - // WPCS: XSS OK. | |
| 221 | - } | |
| 222 | - if ( get_query_var( 'paged' ) ) { | |
| 223 | - if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) { | |
| 224 | - echo ' ('; | |
| 225 | - } | |
| 226 | - | |
| 227 | - /* translators: %s: current page number. */ | |
| 228 | - echo sprintf( esc_html__( 'Page %s', 'catch-breadcrumb' ), absint( max( $paged, $page ) ) ); | |
| 229 | - if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) { | |
| 230 | - echo ')'; | |
| 231 | - } | |
| 232 | - | |
| 233 | - } | |
| 234 | - echo '</nav><!-- .entry-breadcrumbs --> | |
| 235 | - </div><!-- .breadcrumb-area -->'; | |
| 236 | - } | |
| 237 | - } | |
| 238 | - | |
| 239 | -} | |
| 240 | - | |
| 241 | -new Catch_Breadcrumb_Shortcode(); | |
| 242 | - | |
| 243 | - | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * | |
| 5 | + * | |
| 6 | + * @link https://catchplugins.com/plugins | |
| 7 | + * @since 1.0.0 | |
| 8 | + * | |
| 9 | + * @package breadcrumb | |
| 10 | + * @subpackage Breadcrumb/includes | |
| 11 | + */ | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * | |
| 15 | + * | |
| 16 | + * @package Breadcrumb | |
| 17 | + * @subpackage Breadcrumb/includes | |
| 18 | + * @author Catch Plugins <info@catchplugins.com | |
| 19 | + */ | |
| 20 | + | |
| 21 | + | |
| 22 | +class Catch_Breadcrumb_Shortcode | |
| 23 | +{ | |
| 24 | + | |
| 25 | + public function __construct() | |
| 26 | + { | |
| 27 | + | |
| 28 | + add_shortcode('catch-breadcrumb', array($this, 'catch_breadcrumb_shortcode')); | |
| 29 | + } | |
| 30 | + | |
| 31 | + public function catch_display_breadcrumb() | |
| 32 | + { | |
| 33 | + | |
| 34 | + do_shortcode('[catch-breadcrumb]'); | |
| 35 | + } | |
| 36 | + | |
| 37 | + public function catch_breadcrumb_shortcode($atts, $content) | |
| 38 | + { | |
| 39 | + | |
| 40 | + $catch_breadcrumb_public = new Catch_Breadcrumb_Public(CATCH_BREADCRUMB_BASENAME, CATCH_BREADCRUMB_VERSION); | |
| 41 | + $breadcrumb = $catch_breadcrumb_public->build_breadcrumb(); | |
| 42 | + echo wp_kses_post($breadcrumb); | |
| 43 | + } | |
| 44 | +} | |
| 45 | + | |
| 46 | +new Catch_Breadcrumb_Shortcode(); | |