-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
157 lines (119 loc) · 4.55 KB
/
admin.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
*
* @since 1.0.0
* @author David Costa <davidcostadev@gmail.com>
* @version 1.0.0
*/
class DVDPagseguroParcelas_admin {
public $page = 'dvdwoo';
public $option_group = 'dvdwoo_settings';
public $option_name = 'dvdwoo_settings';
public $settings;
public $default;
public function __construct() {
add_action('admin_menu', array($this, 'add_menu'), 100);
add_action('admin_init', array($this, 'dvdwoo_page_settings'));
$this->default = [
'show_products' => 0,
'show_product' => 0
];
$this->get_settings();
}
public function get_settings() {
$this->settings = get_option($this->option_name);
if(!empty($this->settings)) {
$this->settings = array_merge($this->default, $this->settings);
} else {
$this->settings = $this->default;
}
}
public function add_menu() {
add_submenu_page(
'woocommerce',
__('DVD Woo Pagseguro Installment', 'dvd-woo-pagseguro-parcelas'),
__('Pagseguro Installment', 'dvd-woo-pagseguro-parcelas'),
apply_filters('dvdwoo_page_view_permission', 'manage_options'),
$this->page,
array($this, 'dvdwoo_page_callback')
);
}
public function dvdwoo_page_callback() {
include_once 'html-settings-page.php';
}
public function dvdwoo_page_settings() {
add_settings_field(
'show_products',
__('Mostrar na Listagem', 'dvd-woo-pagseguro-parcelas'),
array($this, 'dvdwoo_checkbox_callback'),
$this->page,
'section_general-base',
array(
'id' => 'show_products',
'desc' => __('Para mostrar na listagem dos produtos', 'dvd-woo-pagseguro-parcelas'),
'default' => ''
)
);
add_settings_field(
'show_product',
__('Mostrar no Produto', 'dvd-woo-pagseguro-parcelas'),
array($this, 'dvdwoo_checkbox_callback'),
$this->page,
'section_general-base',
array(
'id' => 'show_product',
'desc' => __('Para mostrar na listagem dos produtos', 'dvd-woo-pagseguro-parcelas'),
'default' => ''
)
);
register_setting(
$this->option_group,
$this->option_name,
array($this, 'dvdwoo_options_sanitize')
);
}
public function dvdwoo_checkbox_callback($args) {
extract($args);
$value = isset($this->settings[$id]) ? $this->settings[$id] : 0;
echo "<input type='checkbox' id='".$id."-0' name='".$this->option_name."[$id]' value='1'".checked('1', $value, false)." />";
echo isset($desc) ? "<span class='description'> $desc</span>" : '';
}
public function dvdwoo_text_callback($args) {
extract($args);
$value = isset($this->settings[$id]) ? $this->settings[$id] : $default;
echo "<input class='$class' type='text' id='$id' name='".$this->option_name."[$id]' value='$value' placeholder='$placeholder' />";
echo isset($desc) ? "<br /><span class='description'>$desc</span>" : '';
}
public function dvdwoo_number_callback($args) {
extract($args);
$value = isset($this->settings[$id]) ? $this->settings[$id] : $default;
echo "<input class='$class' type='number' id='$id' name='".$this->option_name."[$id]' value='$value' />";
echo isset($desc) ? "<br /><span class='description'>$desc</span>" : '';
}
public function dvdwoo_select_callback($args) {
extract($args);
$value = isset($this->settings[$id]) ? $this->settings[$id] : $default;
echo "<select name='".$this->option_name."[$id]'>";
foreach($options as $k => $option) {
echo "<option value='$k'".selected($k, $value, false).">".$option."</option>";
}
echo "</select>";
echo isset($desc) ? "<br /><span class='description'>$desc</span>" : '';
}
public function dvdwoo_options_sanitize($input) {
foreach($input as $k => $v) {
if($k == 'installment_qty') {
// if($v < 2 || empty($v)) {
// $v = 2;
// }
} else if($k == 'installment_minimum_value') {
// if($v < 0 || empty($v)) {
// $v = 0;
// }
}
$newinput[$k] = trim($v);
}
return $newinput;
}
}
new DVDPagseguroParcelas_admin();