Repository navigation
Expand file tree
/
Copy pathomiHooks.php
More file actions
executable file
·171 lines (147 loc) · 4.92 KB
/
Copy pathomiHooks.php
File metadata and controls
executable file
·171 lines (147 loc) · 4.92 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* @author omibeaver
* Booking Hoos list
*/
class omiHooks
{
public static function booking_view_ext()
{
add_meta_box(
'macro_review_meta_box',
'Booking',
function ($view) {
Macro_views::booking_cus_view($view);
},
'macro_booking_record',
'normal',
'high'
);
}
public static function booking_cus_save($post_id, $view)
{
if ($view->post_type == 'macro_booking_record') {
if (isset($_POST['booking_time']) && $_POST['booking_time'] != '') {
update_post_meta($post_id, 'booking_time', $_POST['booking_time']);
}
if (isset($_POST['booking_status']) && $_POST['booking_status'] != '') {
update_post_meta($post_id, 'booking_status', $_POST['booking_status']);
}
}
}
public static function booking_admin_column($column, $post_id)
{
if ($column == 'booking_status') {
Macro_views::booking_status_change($post_id);
}
if ($column == 'booking_time') {
echo str_replace('T', ' ', get_post_meta($post_id, 'booking_time', true));
}
if ($column == 'ID') {
echo $post_id;
}
}
public static function booking_admin_columns($columns)
{
$columns['title'] = 'booking';
$columns['author'] = 'customer';
unset($columns['date']);
$columns['booking_time'] = 'booking time';
$columns['booking_status'] = 'booking status';
$columns['ID'] = 'Record ID';
return $columns;
}
public static function booking_record_fun()
{
register_post_type(
'macro_booking_record',
array(
'label' => 'booking record',
'labels' => array(
'name' => 'Booking',
'singular_name' => 'Booking list',
'add_new' => 'add booking record',
'add_new_item' => 'add booking record',
'edit' => 'update booking record',
'edit_item' => 'update',
'new_item' => 'create',
'view' => 'detail',
'view_item' => 'to detail',
'search_items' => 'query',
'not_found' => 'not found',
'not_found_in_trash' => 'not found'
),
'show_ui' => true,
'show_in_menu' => true,
'public' => true,
'description' => 'Booking Manage',
'has_archive' => false,
'show_in_rest' => false,
'supports' => [
'title',
'author'
]
)
);
}
public static function change_booking_status()
{
check_ajax_referer('omiBeaver');
$post_id = $_POST['post_id'];
$args = array(
'post_type' => 'macro_booking_record',
'posts_per_page' => 10,
'p' => $post_id
);
$data = (new WP_Query($args))->posts;
if (count($data) != 1) {
wp_send_json(['code' => -1, 'msg' => 'action failed:content not found!', 'data' => null]);
}
if (get_post_meta($post_id, 'booking_status', true)['booking_status'] == '0') {
update_post_meta($post_id, 'booking_status', 1);
wp_send_json(['code' => 1, 'msg' => 'success', 'data' => null]);
} else {
wp_send_json(['code' => 1, 'msg' => 'action failed']);
}
}
public static function loadJs()
{
wp_enqueue_script('ajax-script', plugins_url('/assets/utils.js', __FILE__));
wp_localize_script(
'ajax-script',
'winter_ajax_obj',
array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('omiBeaver'),
)
);
}
public static function closeUpdate()
{
add_filter('pre_site_transient_update_core', function ($a) {
return null;
});
add_filter('pre_site_transient_update_plugins', function ($a) {
return null;
});
add_filter('pre_site_transient_update_themes', function ($a) {
return null;
});
remove_action('admin_init', '_maybe_update_core');
remove_action('admin_init', '_maybe_update_plugins');
remove_action('admin_init', '_maybe_update_themes');
}
public static function removeRowBtn($actions, $post)
{
if ($post->post_type == "macro_booking_record") {
unset($actions['view']);
unset($actions['inline hide-if-no-js']);
}
return $actions;
}
public static function customOrderQuery($data, $post, $context): array
{
$data->data['booking_left'] = 2;
return $data;
}
}