-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepeaterCustomeFields.php
72 lines (56 loc) · 1.65 KB
/
RepeaterCustomeFields.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
*/
use RepeaterMetaCallback;
/**
*
*/
class RepeaterCustomeFields
{
public $repeater_callback;
public function register()
{
$this->repeater_callback = new RepeaterMetaCallback();
add_action('admin_init', [$this, 'single_repeater_meta_boxes'], 2);
add_action('save_post', [$this, 'single_repeatable_meta_box_save']);
}
public function single_repeater_meta_boxes()
{
add_meta_box(
'single-repeater-data',
'Single Rapeater',
[$this, 'single_repeatable_meta_box_callback'],
'cursos',
'normal',
'default'
);
}
public function single_repeatable_meta_box_save($post_id)
{
if (!isset($_POST['single_repeater_meta_boxes_nonce'])) return $post_id;
$nonce = $_POST['single_repeater_meta_boxes_nonce'];
$data = 'single_repeater_meta_boxes_data';
if (!wp_verify_nonce($nonce, $data)) return $post_id;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
if (!current_user_can('edit_post', $post_id)) return $post_id;
$old = get_post_meta($post_id, 'single_repeater_group', true);
$new = [];
$titles = $_POST['title'];
$tdescs = $_POST['tdesc'];
$count = count($titles);
for ($i = 0; $i < $count; $i++) {
if ($titles[$i] != '') {
$new[$i]['title'] = stripslashes(strip_tags($titles[$i]));
$new[$i]['tdesc'] = stripslashes($tdescs[$i]);
}
}
if (!empty($new) && $new != $old) {
update_post_meta($post_id, 'single_repeater_group', $new);
} elseif (empty($new) && $old) {
delete_post_meta($post_id, 'single_repeater_group', $old);
}
$repeter_status = $_REQUEST['repeter_status'];
update_post_meta($post_id, 'repeter_status', $repeter_status);
}
}