class-wc-widget-brand-description.php
1 year ago
class-wc-widget-brand-nav.php
7 months ago
class-wc-widget-brand-thumbnails.php
1 year ago
class-wc-widget-cart.php
3 years ago
class-wc-widget-layered-nav-filters.php
2 years ago
class-wc-widget-layered-nav.php
3 months ago
class-wc-widget-price-filter.php
7 months ago
class-wc-widget-product-categories.php
7 months ago
class-wc-widget-product-search.php
5 years ago
class-wc-widget-product-tag-cloud.php
5 years ago
class-wc-widget-products.php
1 year ago
class-wc-widget-rating-filter.php
5 years ago
class-wc-widget-recent-reviews.php
2 months ago
class-wc-widget-recently-viewed.php
1 year ago
class-wc-widget-top-rated-products.php
5 years ago
class-wc-widget-brand-description.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1); |
| 4 | |
| 5 | /** |
| 6 | * Brand Description Widget |
| 7 | * |
| 8 | * When viewing a brand archive, show the current brands description + image |
| 9 | * |
| 10 | * Important: For internal use only by the Automattic\WooCommerce\Internal\Brands package. |
| 11 | * |
| 12 | * @package WooCommerce\Widgets |
| 13 | * @version 9.4.0 |
| 14 | */ |
| 15 | class WC_Widget_Brand_Description extends WP_Widget { |
| 16 | |
| 17 | /** |
| 18 | * Widget class. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | public $woo_widget_cssclass; |
| 23 | |
| 24 | /** |
| 25 | * Widget description. |
| 26 | * |
| 27 | * @var string |
| 28 | */ |
| 29 | public $woo_widget_description; |
| 30 | |
| 31 | /** |
| 32 | * Widget idbase. |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | public $woo_widget_idbase; |
| 37 | |
| 38 | /** |
| 39 | * Widget name. |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | public $woo_widget_name; |
| 44 | |
| 45 | /** Constructor */ |
| 46 | public function __construct() { |
| 47 | |
| 48 | /* Widget variable settings. */ |
| 49 | $this->woo_widget_name = __( 'WooCommerce Brand Description', 'woocommerce' ); |
| 50 | $this->woo_widget_description = __( 'When viewing a brand archive, show the current brands description.', 'woocommerce' ); |
| 51 | $this->woo_widget_idbase = 'wc_brands_brand_description'; |
| 52 | $this->woo_widget_cssclass = 'widget_brand_description'; |
| 53 | |
| 54 | /* Widget settings. */ |
| 55 | $widget_ops = array( |
| 56 | 'classname' => $this->woo_widget_cssclass, |
| 57 | 'description' => $this->woo_widget_description, |
| 58 | ); |
| 59 | |
| 60 | /* Create the widget. */ |
| 61 | parent::__construct( $this->woo_widget_idbase, $this->woo_widget_name, $widget_ops ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Echoes the widget content. |
| 66 | * |
| 67 | * @see WP_Widget |
| 68 | * |
| 69 | * @param array $args Display arguments including 'before_title', 'after_title', |
| 70 | * 'before_widget', and 'after_widget'. |
| 71 | * @param array $instance The settings for the particular instance of the widget. |
| 72 | */ |
| 73 | public function widget( $args, $instance ) { |
| 74 | extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
| 75 | |
| 76 | if ( ! is_tax( 'product_brand' ) ) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if ( ! get_query_var( 'term' ) ) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | $thumbnail = ''; |
| 85 | $term = get_term_by( 'slug', get_query_var( 'term' ), 'product_brand' ); |
| 86 | |
| 87 | $thumbnail = wc_get_brand_thumbnail_url( $term->term_id, 'large' ); |
| 88 | |
| 89 | echo $before_widget . $before_title . $term->name . $after_title; // phpcs:ignore WordPress.Security.EscapeOutput |
| 90 | |
| 91 | wc_get_template( |
| 92 | 'widgets/brand-description.php', |
| 93 | array( |
| 94 | 'thumbnail' => $thumbnail, |
| 95 | 'brand' => $term, |
| 96 | ), |
| 97 | 'woocommerce', |
| 98 | WC()->plugin_path() . '/templates/brands/' |
| 99 | ); |
| 100 | |
| 101 | echo $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Updates widget instance. |
| 106 | * |
| 107 | * @see WP_Widget->update |
| 108 | * |
| 109 | * @param array $new_instance New widget instance. |
| 110 | * @param array $old_instance Old widget instance. |
| 111 | */ |
| 112 | public function update( $new_instance, $old_instance ) { |
| 113 | $instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) ); |
| 114 | return $instance; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Outputs the settings update form. |
| 119 | * |
| 120 | * @param array $instance Current settings. |
| 121 | */ |
| 122 | public function form( $instance ) { |
| 123 | ?> |
| 124 | <p> |
| 125 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'woocommerce' ); ?></label> |
| 126 | <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?>" /> |
| 127 | </p> |
| 128 | <?php |
| 129 | } |
| 130 | } |
| 131 |