-
Notifications
You must be signed in to change notification settings - Fork 0
/
RepeaterMetaCallback.php
72 lines (67 loc) · 2.72 KB
/
RepeaterMetaCallback.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
<?php
/**
* @package DwqPlugin
*/
class RepeaterMetaCallback
{
public function single_repeatable_meta_box_callback($post)
{
$single_repeater_group = get_post_meta($post->ID, 'single_repeater_group', true);
wp_nonce_field(
'single_repeater_meta_boxes_data',
'single_repeater_meta_boxes_nonce'
);
?>
<script type="text/javascript">
function addSelect() {
const tbody = document.querySelector("#repeatable-fieldset-one > tbody");
const row = document.querySelectorAll(
"tbody > .empty-row.custom-repeater-text"
)[0];
const clone = row.cloneNode(true);
new_row = tbody.appendChild(clone);
const my_class = new_row.classList;
my_class.remove("empty-row", "custom-repeater-text");
my_class.add("table-row");
}
function deleteRow(r) {
let i = r.parentNode.parentNode.rowIndex;
document.getElementById("repeatable-fieldset-one").deleteRow(i);
}
</script>
<table id="repeatable-fieldset-one" width="100%">
<tbody>
<?php
if ($single_repeater_group) :
foreach ($single_repeater_group as $field) {
?>
<tr>
<td>
<input type="text" style="width:98%;" name="title[]" value="<?php if ($field['title'] != '') echo esc_attr($field['title']); ?>" placeholder="Heading" />
</td>
<td>
<input type="text" style="width:98%;" name="tdesc[]" value="<?php if ($field['tdesc'] != '') echo esc_attr($field['tdesc']); ?>" placeholder="Description" />
</td>
<td>
<button onclick="deleteRow(this)">Remove</button>
</td>
</tr>
<?php }
endif; ?>
<tr class="empty-row custom-repeter-text">
<td>
<input type="text" style="width:98%;" name="title[]" placeholder="Heading" />
</td>
<td>
<input type="text" style="width:98%;" name="tdesc[]" value="" placeholder="Description" />
</td>
<td>
<button onclick="deleteRow(this)">Remove</button>
</td>
</tr>
</tbody>
</table>
<button onclick="addSelect()">Add Row</button>
<?php
}
}