| 1 |
<?php namespace TierPricingTable\Settings\CustomOptions; |
| 2 |
|
| 3 |
class TPTLinkButton { |
| 4 |
|
| 5 |
const FIELD_TYPE = 'tpt_link_button'; |
| 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 |
|
| 29 |
?> |
| 30 |
<tr valign="top"> |
| 31 |
<th scope="row" class="titledesc"> |
| 32 |
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label> |
| 33 |
</th> |
| 34 |
<td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>"> |
| 35 |
<a href="<?php echo esc_attr( $value['button_link'] ); ?>" |
| 36 |
class="<?php echo esc_attr( $value['button_class'] ); ?>"> |
| 37 |
<?php echo esc_html( $value['button_text'] ); ?> |
| 38 |
</a> |
| 39 |
</td> |
| 40 |
</tr> |
| 41 |
<?php |
| 42 |
} |
| 43 |
} |