| @@ -18,9 +18,9 @@ | ||
| 18 | 18 | /** |
| 19 | 19 | * @return false|string |
| 20 | 20 | */ |
| 21 | 21 | public function get_page_url() { |
| 22 | - $page_id = Fns::get_option( 'modules', 'compare', 'page' ); | |
| 22 | + $page_id = Fns::get_option( 'modules', 'compare', 'page' ); | |
| 23 | 23 | return get_permalink( $page_id ); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
| @@ -74,10 +74,10 @@ | ||
| 74 | 74 | * @return array Table Field list |
| 75 | 75 | */ |
| 76 | 76 | static function get_list_field_ids() { |
| 77 | 77 | |
| 78 | - $default_show = array_keys( self::get_list_default_fields() ); | |
| 79 | - $fields_settings = Fns::get_option( 'modules', 'compare', 'page_show_fields', [] ); | |
| 78 | + $default_show = array_keys( self::get_list_default_fields() ); | |
| 79 | + $fields_settings = Fns::get_option( 'modules', 'compare', 'page_show_fields', [] ); | |
| 80 | 80 | if ( isset( $fields_settings ) && ( is_array( $fields_settings ) ) && count( $fields_settings ) > 1 ) { |
| 81 | 81 | $fields = $fields_settings; |
| 82 | 82 | } else { |
| 83 | 83 | $fields = $default_show; |
| @@ -106,9 +106,8 @@ | ||
| 106 | 106 | $field_name = isset( $default[ $field ] ) ? $default[ $field ] : ''; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | return $field_name; |
| 110 | - | |
| 111 | 110 | } |
| 112 | 111 | |
| 113 | 112 | public function display_field( $field_id, $product ) { |
| 114 | 113 | |
| @@ -118,25 +117,25 @@ | ||
| 118 | 117 | } |
| 119 | 118 | switch ( $type ) { |
| 120 | 119 | case 'primary': |
| 121 | 120 | ?> |
| 122 | - <div class="rtsb-compare-primary-content-area"> | |
| 123 | - <a href="#" class="rtsb-compare-remove" data-product_id="<?php echo absint( $product['id'] ); ?>"> | |
| 124 | - <i class="rtsb-icon rtsb-icon-trash-empty"></i> | |
| 125 | - </a> | |
| 126 | - <a href="<?php echo get_permalink( $product['id'] ); ?>" class="rtsb-compare-product-image"> | |
| 121 | + <div class="rtsb-compare-primary-content-area"> | |
| 122 | + <a href="#" class="rtsb-compare-remove" data-product_id="<?php echo absint( $product['id'] ); ?>"> | |
| 123 | + <i class="rtsb-icon rtsb-icon-trash-empty"></i> | |
| 124 | + </a> | |
| 125 | + <a href="<?php echo esc_url( get_permalink( $product['id'] ) ); ?>" class="rtsb-compare-product-image"> | |
| 127 | 126 | <?php |
| 128 | 127 | if ( ! empty( $product['primary']['image'] ) ) { |
| 129 | 128 | echo wp_kses( $product['primary']['image'], Fns::allowedHtml( 'image' ) ); |
| 130 | 129 | } |
| 131 | 130 | ?> |
| 132 | - </a> | |
| 133 | - </div> | |
| 131 | + </a> | |
| 132 | + </div> | |
| 134 | 133 | <?php |
| 135 | 134 | break; |
| 136 | 135 | |
| 137 | 136 | case 'title': |
| 138 | - echo '<a href="' . get_permalink( $product['id'] ) . '" class="rtsb-compare-product-title">' . esc_html( $product[ $field_id ] ) . '</a>'; | |
| 137 | + echo '<a href="' . esc_url( get_permalink( $product['id'] ) ) . '" class="rtsb-compare-product-title">' . esc_html( $product[ $field_id ] ) . '</a>'; | |
| 139 | 138 | break; |
| 140 | 139 | |
| 141 | 140 | case 'rating': |
| 142 | 141 | echo '<span class="rtsb-compare-product-rating">' . wp_kses_post( $product[ $field_id ] ) . '</span>'; |
| @@ -146,22 +145,26 @@ | ||
| 146 | 145 | echo '<div class="rtsb-compare-product-price">' . wp_kses_post( $product[ $field_id ] ) . '</div>'; |
| 147 | 146 | break; |
| 148 | 147 | |
| 149 | 148 | case 'add_to_cart': |
| 150 | - echo apply_filters( 'rtsb/module/compare/add_to_cart_btn', $product[ $field_id ] ); | |
| 149 | + Fns::print_html( apply_filters( 'rtsb/module/compare/add_to_cart_btn', $product[ $field_id ] ), true ); | |
| 151 | 150 | break; |
| 152 | 151 | |
| 153 | 152 | case 'weight': |
| 154 | 153 | if ( $product[ $field_id ] ) { |
| 155 | 154 | $unit = $product[ $field_id ] !== '-' ? get_option( 'woocommerce_weight_unit' ) : ''; |
| 156 | - echo wc_format_localized_decimal( $product[ $field_id ] ) . ' ' . esc_attr( $unit ); | |
| 155 | + Fns::print_html( wc_format_localized_decimal( $product[ $field_id ] ) . ' ' . esc_attr( $unit ) ); | |
| 157 | 156 | } |
| 158 | 157 | break; |
| 159 | 158 | |
| 160 | 159 | case 'description': |
| 161 | - echo apply_filters( 'woocommerce_short_description', $product[ $field_id ] ); | |
| 160 | + Fns::print_html( apply_filters( 'woocommerce_short_description', $product[ $field_id ] ) ); | |
| 162 | 161 | break; |
| 163 | - | |
| 162 | + case 'attribute': | |
| 163 | + if ( isset( $product[ $field_id ] ) ) { | |
| 164 | + Fns::print_html( $product[ $field_id ] ); | |
| 165 | + } | |
| 166 | + break; | |
| 164 | 167 | default: |
| 165 | 168 | echo isset( $product[ $field_id ] ) ? wp_kses_post( $product[ $field_id ] ) : ''; |
| 166 | 169 | break; |
| 167 | 170 | } |
| @@ -182,16 +185,14 @@ | ||
| 182 | 185 | $products = wc_get_products( $args ); |
| 183 | 186 | |
| 184 | 187 | $products_data = []; |
| 185 | 188 | |
| 186 | - $field_ids = $this->get_list_field_ids(); | |
| 187 | - | |
| 189 | + $field_ids = $this->get_list_field_ids(); | |
| 188 | 190 | $tax_field_ids = array_filter( |
| 189 | 191 | $field_ids, |
| 190 | 192 | function ( $field_id ) { |
| 191 | - return 'pa_' === substr( $field_id, 0, 3 ); | |
| 192 | - }, | |
| 193 | - ARRAY_FILTER_USE_KEY | |
| 193 | + return str_starts_with( $field_id, 'pa_' ); | |
| 194 | + } | |
| 194 | 195 | ); |
| 195 | 196 | |
| 196 | 197 | $data_none = '-'; |
| 197 | 198 | |
| @@ -216,17 +217,16 @@ | ||
| 216 | 217 | 'weight' => $product->get_weight() ? $product->get_weight() : $data_none, |
| 217 | 218 | 'sku' => $product->get_sku() ? $product->get_sku() : $data_none, |
| 218 | 219 | 'availability' => $this->availability_html( $product ), |
| 219 | 220 | ]; |
| 220 | - | |
| 221 | 221 | if ( ! empty( $tax_field_ids ) ) { |
| 222 | 222 | foreach ( $tax_field_ids as $field_id ) { |
| 223 | 223 | if ( taxonomy_exists( $field_id ) ) { |
| 224 | 224 | $products_data[ $product->get_id() ][ $field_id ] = []; |
| 225 | - $terms = get_the_terms( $product->get_id(), $field_id ); | |
| 225 | + $terms = get_the_terms( $product->get_id(), $field_id ); | |
| 226 | 226 | if ( ! empty( $terms ) ) { |
| 227 | 227 | foreach ( $terms as $term ) { |
| 228 | - $term = sanitize_term( $term, $field_id ); | |
| 228 | + $term = sanitize_term( $term, $field_id ); | |
| 229 | 229 | $products_data[ $product->get_id() ][ $field_id ][] = $term->name; |
| 230 | 230 | } |
| 231 | 231 | } else { |
| 232 | 232 | $products_data[ $product->get_id() ][ $field_id ][] = '-'; |
| @@ -392,9 +392,12 @@ | ||
| 392 | 392 | |
| 393 | 393 | public function get_compared_product_ids() { |
| 394 | 394 | $cookie_name = $this->get_cookie_name(); |
| 395 | 395 | $ids = []; |
| 396 | + | |
| 397 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 396 | 398 | if ( isset( $_COOKIE[ $cookie_name ] ) && is_array( json_decode( wp_unslash( $_COOKIE[ $cookie_name ] ), true ) ) ) { |
| 399 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 397 | 400 | $ids = array_map( 'absint', json_decode( wp_unslash( $_COOKIE[ $cookie_name ] ), true ) ); |
| 398 | 401 | } |
| 399 | 402 | |
| 400 | 403 | return $ids; |
| @@ -402,15 +405,15 @@ | ||
| 402 | 405 | |
| 403 | 406 | public function reached_max_limit() { |
| 404 | 407 | |
| 405 | 408 | $product_ids = $this->get_compared_product_ids(); |
| 406 | - $max_limit = absint( Fns::get_option( 'modules', 'compare', 'max_limit', 10, 'checkbox' ) ); | |
| 409 | + $max_limit = absint( Fns::get_option( 'modules', 'compare', 'max_limit', 10, 'checkbox' ) ); | |
| 407 | 410 | |
| 408 | - // Remove if product is not exist. | |
| 411 | + // Remove if product is not exist. | |
| 409 | 412 | foreach ( $product_ids as $id ) { |
| 410 | - if( 'publish' !== get_post_status( $id )){ | |
| 413 | + if ( 'publish' !== get_post_status( $id ) ) { | |
| 411 | 414 | $this->remove_product( $id ); |
| 412 | - unset( $product_ids[$id] ); | |
| 415 | + unset( $product_ids[ $id ] ); | |
| 413 | 416 | } |
| 414 | 417 | } |
| 415 | 418 | |
| 416 | 419 | if ( $max_limit && count( $product_ids ) >= $max_limit ) { |
| @@ -418,6 +421,5 @@ | ||
| 418 | 421 | } |
| 419 | 422 | |
| 420 | 423 | return false; |
| 421 | 424 | } |
| 422 | - | |
| 423 | 425 | } |