TemplateOption.php
2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php namespace MeowCrew\RoleAndCustomerBasedPricing\Settings\CustomOptions;
use MeowCrew\RoleAndCustomerBasedPricing\Core\ServiceContainerTrait;
use WC_Admin_Settings;
class TemplateOption {
const FIELD_TYPE = 'rcbp_template';
use ServiceContainerTrait;
public function __construct() {
add_action( 'woocommerce_admin_field_' . self::FIELD_TYPE, array( $this, 'render' ) );
add_action( 'woocommerce_admin_settings_sanitize_option', function ( $value, $option, $rawValue ) {
if ( self::FIELD_TYPE === $option['type'] ) {
return wp_kses_post( $rawValue );
}
return $value;
}, 10, 3 );
}
public function render( $value ) {
if ( ! isset( $value['id'] ) ) {
$value['id'] = '';
}
if ( ! isset( $value['title'] ) ) {
$value['title'] = isset( $value['name'] ) ? $value['name'] : '';
}
if ( ! isset( $value['default'] ) ) {
$value['default'] = '';
}
if ( ! isset( $value['desc'] ) ) {
$value['desc'] = '';
}
if ( ! isset( $value['desc_tip'] ) ) {
$value['desc_tip'] = false;
}
if ( ! isset( $value['placeholder'] ) ) {
$value['placeholder'] = '';
}
if ( ! isset( $value['value'] ) ) {
$value['value'] = WC_Admin_Settings::get_option( $value['id'], $value['default'] );
}
$option_value = $value['value'];
$value['description'] = isset( $value['description'] ) ? $value['description'] : '';
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
</th>
<td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
<?php
wp_editor( $option_value, $value['id'], array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => $value['id'],
'textarea_rows' => 5,
'tabindex' => null,
'editor_class' => 'sp-message-template-mce',
'tinymce' => array(
'resize' => 'vertical',
'menubar' => false,
'wpautop' => true,
'toolbar2' => '',
'toolbar1' => implode( ',', array(
'bold',
'italic',
'strikethrough',
'link',
'spellchecker',
) ),
),
'quicktags' => array(
'id' => $value['id'],
'buttons' => 'strong,del',
),
'drag_drop_upload' => false
) );
?>
<p class="description"><?php echo esc_attr( $value['description'] ); ?></p>
</td>
</tr>
<?php
}
}