PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.54.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.54.0
3.54.0 3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 All 178 releases
simple-tags / inc / schedule-logs-table.php

schedule-logs-table.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.54.0, at inc/schedule-logs-table.php

225 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!class_exists('WP_List_Table')) {
4 require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
5 }
6
7 class SimpleTags_Schedule_Logs extends WP_List_Table
8 {
9 public function __construct()
10 {
11
12 parent::__construct([
13 'singular' => __('autotermsschedulelog', 'simple-tags'),
14 'plural' => __('autotermsschedulelogs', 'simple-tags'),
15 'ajax' => false
16 ]);
17 }
18
19 public function get_st_autoterms()
20 {
21 $per_page = $this->get_items_per_page('st_autoterms_schedule_logs_per_page', 20);
22 $current_page = $this->get_pagenum();
23
24 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading GET parameters for sorting display, no state change
25 $orderby = (!empty($_REQUEST['orderby'])) ? sanitize_text_field(wp_unslash($_REQUEST['orderby'])) : 'ID';
26 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading GET parameter for sort order display, no state change
27 $order = (!empty($_REQUEST['order'])) ? sanitize_text_field(wp_unslash($_REQUEST['order'])) : 'desc';
28
29
30 return taxopress_autoterms_logs_data($per_page, $current_page, $orderby, $order, true);
31 }
32
33 public static function record_count()
34 {
35 return get_st_autoterms()['counts'];
36 }
37
38 public function single_row($item)
39 {
40 $class = ['st-autoterm-log-tr'];
41 $id = 'st-autoterm-log-' . md5($item->ID);
42 echo sprintf('<tr id="%s" class="%s">', esc_attr($id), esc_attr(implode(' ', $class)));
43 $this->single_row_columns($item);
44 echo '</tr>';
45 }
46
47 public function get_columns()
48 {
49 $columns = [
50 'cb' => '<input type="checkbox"/>',
51 'title' => esc_html__('Post', 'simple-tags'),
52 'post_type' => esc_html__('Post type', 'simple-tags'),
53 'taxonomy' => esc_html__('Taxonomy', 'simple-tags'),
54 'terms' => esc_html__('Terms added', 'simple-tags'),
55 'date' => esc_html__('Date', 'simple-tags')
56 ];
57
58 return $columns;
59 }
60
61 public function column_default($item, $column_name)
62 {
63 return isset($item->$column_name) ? $item->$column_name : '&mdash;';
64 }
65
66 public function no_items()
67 {
68 esc_html_e('Schedule log is empty.', 'simple-tags');
69 }
70
71 protected function column_cb($item)
72 {
73 return sprintf('<input type="checkbox" name="%1$s[]" value="%2$s" />', 'taxopress_autoterms_schedule_logs', $item->ID);
74 }
75
76 protected function get_bulk_actions()
77 {
78 $actions = [
79 'taxopress-autoterms-delete-logs' => esc_html__('Delete', 'simple-tags')
80 ];
81
82 return $actions;
83 }
84
85 public function process_bulk_action()
86 {
87
88 $query_arg = '_wpnonce';
89 $action = 'bulk-' . $this->_args['plural'];
90 $checked = $result = isset($_REQUEST[$query_arg]) ? wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST[$query_arg])), $action) : false;
91
92 if (!$checked || !current_user_can('simple_tags')) {
93 return;
94 }
95
96 if ($this->current_action() === 'taxopress-autoterms-delete-logs') {
97 $taxopress_autoterms_schedule_logs = isset($_REQUEST['taxopress_autoterms_schedule_logs']) ? array_map('sanitize_text_field', (array) wp_unslash($_REQUEST['taxopress_autoterms_schedule_logs'])) : [];
98 if (!empty($taxopress_autoterms_schedule_logs)) {
99 foreach ($taxopress_autoterms_schedule_logs as $taxopress_autoterms_log) {
100 wp_delete_post($taxopress_autoterms_log, true);
101 }
102 }
103 }
104 }
105
106 protected function get_sortable_columns()
107 {
108 $sortable_columns = [
109 'title' => ['title', true],
110 'date' => ['date', true]
111 ];
112
113 return $sortable_columns;
114 }
115
116 protected function handle_row_actions($item, $column_name, $primary)
117 {
118 $auto_term_log_post_id = get_post_meta($item->ID, '_taxopress_log_post_id', true);
119
120 $actions = [
121 'edit' => sprintf(
122 '<a href="%s">%s</a>',
123 add_query_arg(
124 [
125 'action' => 'edit',
126 'post' => $auto_term_log_post_id,
127 ],
128 admin_url('post.php')
129 ),
130 __('Edit Main Post', 'simple-tags')
131 ),
132 'delete' => sprintf(
133 '<a href="%s" class="delete-autoterm">%s</a>',
134 add_query_arg(
135 [
136 'page' => 'st_autoterms_schedule',
137 'action' => 'taxopress-delete-autoterm-log',
138 'taxopress_autoterms_log' => esc_attr($item->ID),
139 '_wpnonce' => wp_create_nonce('autoterm-action-request-nonce')
140 ],
141 admin_url('admin.php')
142 ),
143 __('Delete Log', 'simple-tags')
144 ),
145 ];
146
147 return $column_name === $primary ? $this->row_actions($actions, false) : '';
148 }
149
150 protected function column_title($item)
151 {
152 $auto_term_log_post_id = get_post_meta($item->ID, '_taxopress_log_post_id', true);
153
154 $title = sprintf(
155 '<a href="%1$s"><strong><span class="row-title">%2$s</span></strong></a>',
156 add_query_arg(
157 [
158 'action' => 'edit',
159 'post' => $auto_term_log_post_id,
160 ],
161 admin_url('post.php')
162 ),
163 esc_html(get_the_title($auto_term_log_post_id))
164 );
165
166 return $title;
167 }
168
169 protected function column_post_type($item)
170 {
171 $auto_term_log_post_id = get_post_meta($item->ID, '_taxopress_log_post_id', true);
172 $auto_term_log_posttype = get_post_type_object(get_post_type($auto_term_log_post_id));
173
174 return ($auto_term_log_posttype && !is_wp_error($auto_term_log_posttype)) ? $auto_term_log_posttype->labels->singular_name : '&mdash;';
175 }
176
177 protected function column_taxonomy($item)
178 {
179 $taxopress_log_taxonomy = get_post_meta($item->ID, '_taxopress_log_taxonomy', true);
180 $taxopress_log_taxonomy_data = get_taxonomy($taxopress_log_taxonomy);
181
182 return ($taxopress_log_taxonomy_data && !is_wp_error($taxopress_log_taxonomy_data)) ? $taxopress_log_taxonomy_data->labels->singular_name : '&mdash;';
183 }
184
185 protected function column_terms($item)
186 {
187 $taxopress_log_terms = get_post_meta($item->ID, '_taxopress_log_terms', true);
188
189 if ($taxopress_log_terms && !empty(trim($taxopress_log_terms))) {
190 return '<font color="green"> ' . esc_html(ucwords($taxopress_log_terms)) . ' </font>';
191 } else {
192 return '<font color="red"> ' . esc_html__('None', 'simple-tags') . ' </font>';
193 }
194 }
195
196 protected function column_date($item)
197 {
198
199 return get_the_date('l F j, Y h:i A', $item->ID);
200 }
201
202 public function prepare_items()
203 {
204
205 $this->_column_headers = $this->get_column_info();
206 $this->process_bulk_action();
207
208 $per_page = $this->get_items_per_page('st_autoterms_schedule_logs_per_page', 20);
209
210 $results = $this->get_st_autoterms();
211 $data = $results['posts'];
212 $total_items = $results['counts'];
213 $current_page = $this->get_pagenum();
214
215
216 $this->items = $data;
217
218 $this->set_pagination_args([
219 'total_items' => $total_items,
220 'per_page' => $per_page,
221 'total_pages' => ceil($total_items / $per_page)
222 ]);
223 }
224 }
225