PluginProbe
Tiered Pricing Table for WooCommerce / trunk
Tiered Pricing Table for WooCommerce vtrunk
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
tier-pricing-table / src / Settings / CustomOptions / TPTIntegrationOption.php

TPTIntegrationOption.php in Tiered Pricing Table for WooCommerce trunk, at src/Settings/CustomOptions/TPTIntegrationOption.php

123 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Settings\CustomOptions;
2
3 class TPTIntegrationOption {
4
5 const FIELD_TYPE = 'tpt_integration_option';
6
7 public function __construct() {
8 add_action( 'woocommerce_admin_field_' . self::FIELD_TYPE, array( $this, 'render' ) );
9
10 add_action( 'woocommerce_admin_settings_sanitize_option', function ( $value, $option, $rawValue ) {
11
12 if ( self::FIELD_TYPE === $option['type'] ) {
13 $value = in_array( $value, array( 1, 'yes' ) ) ? 'yes' : 'no';
14 }
15
16 return $value;
17 }, 10, 3 );
18 }
19
20 public function render( $value ) {
21 if ( ! isset( $value['id'] ) ) {
22 $value['id'] = '';
23 }
24
25 if ( ! isset( $value['title'] ) ) {
26 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
27 }
28 if ( ! isset( $value['default'] ) ) {
29 $value['default'] = '';
30 }
31
32 if ( ! isset( $value['value'] ) ) {
33 $value['value'] = \WC_Admin_Settings::get_option( $value['id'], $value['default'] );
34 }
35
36 if ( ! isset( $value['on_label'] ) ) {
37 $value['on_label'] = __( 'On', 'role-and-customer-based-pricing-for-woocommerce' );
38 }
39
40 if ( ! isset( $value['off_label'] ) ) {
41 $value['off_label'] = __( 'Off', 'role-and-customer-based-pricing-for-woocommerce' );
42 }
43 if ( ! isset( $value['desc'] ) ) {
44 $value['desc'] = '';
45 }
46
47 $option_value = $value['value'];
48 $is_official = ! empty( $value['official'] );
49 $action_links = isset( $value['action_links'] ) && is_array( $value['action_links'] ) ? $value['action_links'] : array();
50 $meta_pills = isset( $value['meta_pills'] ) && is_array( $value['meta_pills'] ) ? $value['meta_pills'] : array();
51 ?>
52 <tr class="tpt-integration-item <?php echo $is_official ? 'tpt-integration-item--official' : ''; ?>">
53 <td>
54 <div class="tpt-integration-wrapper <?php echo $is_official ? 'tpt-integration-wrapper--official' : ''; ?>">
55 <div class="tpt-integration-item__image">
56 <img src="<?php echo esc_attr( $value['icon_url'] ); ?>"
57 alt="<?php echo esc_attr( $value['title'] ); ?>">
58 </div>
59 <div class="tpt-integration-item__description">
60 <div class="tpt-integration-item__content">
61
62 <?php $official_badge = $is_official ? ' <span class="tpt-integration-item__official-badge">' . esc_html__( 'By U2Code', 'tier-pricing-table' ) . '</span>' : ''; ?>
63 <?php if ( $value['author_url'] ) : ?>
64 <a target="_blank" href="<?php echo esc_attr( $value['author_url'] ); ?>">
65 <h4><?php echo esc_html( $value['title'] ) . wp_kses_post( $official_badge ); ?></h4>
66 </a>
67 <?php else : ?>
68 <h4><?php echo esc_html( $value['title'] ) . wp_kses_post( $official_badge ); ?></h4>
69 <?php endif; ?>
70
71 <?php if ( $meta_pills ) : ?>
72 <div class="tpt-integration-item__pills">
73 <?php foreach ( $meta_pills as $pill ) : ?>
74 <span class="tpt-integration-item__pill"><?php echo esc_html( $pill ); ?></span>
75 <?php endforeach; ?>
76 </div>
77 <?php endif; ?>
78
79 <p class="description">
80 <?php
81 echo wp_kses_post( $value['desc'] ); // audit.php.wp.security.xss.shortcode-attr ignore
82 ?>
83 </p>
84
85 </div>
86
87 <div class="tpt-integration-item__actions">
88 <?php if ( $action_links ) : ?>
89 <div class="tpt-integration-item__action-links">
90 <?php foreach ( $action_links as $action_link ) : ?>
91 <?php if ( empty( $action_link['url'] ) || empty( $action_link['label'] ) ) { continue; } ?>
92 <a class="tpt-integration-item__action-link"
93 target="<?php echo esc_attr( $action_link['target'] ?? '_blank' ); ?>"
94 <?php echo ( $action_link['target'] ?? '_blank' ) === '_blank' ? 'rel="noopener"' : ''; ?>
95 href="<?php echo esc_url( $action_link['url'] ); ?>">
96 <?php echo esc_html( $action_link['label'] ); ?> &rarr;
97 </a>
98 <?php endforeach; ?>
99 </div>
100 <?php endif; ?>
101 <div class="tpt-integration-item-checkbox">
102 <input
103 name="<?php echo esc_attr( $value['id'] ); ?>"
104 id="<?php echo esc_attr( $value['id'] ); ?>"
105 type="checkbox"
106 value="1"
107 <?php checked( $option_value, 'yes' ); ?>
108 class="tpt-toggle-switch"
109 />
110 <label for="<?php echo esc_attr( $value['id'] ); ?>">
111 <span data-tpt-toggle-switch-on><?php echo esc_attr( $value['on_label'] ); ?></span>
112 <span data-tpt-toggle-switch-off><?php echo esc_attr( $value['off_label'] ); ?></span>
113 </label>
114 </div>
115 </div>
116 </div>
117 </div>
118 </td>
119 </tr>
120 <?php
121 }
122 }
123