PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.44.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.44.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 3.6.2 All 177 releases
simple-tags / inc / schedule-logs-table.php

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

229 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!class_exists('WP_List_Table')) {
3 require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
4 }
5
6 class SimpleTags_Schedule_Logs extends WP_List_Table
7 {
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
20 public function get_st_autoterms()
21 {
22 $per_page = $this->get_items_per_page('st_autoterms_schedule_logs_per_page', 20);
23 $current_page = $this->get_pagenum();
24
25 $orderby = (!empty($_REQUEST['orderby'])) ? sanitize_text_field($_REQUEST['orderby']) : 'ID';
26 $order = (!empty($_REQUEST['order'])) ? sanitize_text_field($_REQUEST['order']) : 'desc';
27
28
29 return taxopress_autoterms_logs_data($per_page, $current_page, $orderby, $order, true);
30 }
31
32 public static function record_count()
33 {
34 return get_st_autoterms()['counts'];
35 }
36
37 public function single_row($item)
38 {
39 $class = ['st-autoterm-log-tr'];
40 $id = 'st-autoterm-log-' . md5($item->ID);
41 echo sprintf('<tr id="%s" class="%s">', esc_attr($id), esc_attr(implode(' ', $class)));
42 $this->single_row_columns($item);
43 echo '</tr>';
44 }
45
46 function get_columns()
47 {
48 $columns = [
49 'cb' => '<input type="checkbox"/>',
50 'title' => esc_html__( 'Post', 'simple-tags' ),
51 'post_type' => esc_html__( 'Post type', 'simple-tags' ),
52 'taxonomy' => esc_html__( 'Taxonomy', 'simple-tags' ),
53 'terms' => esc_html__( 'Terms added', 'simple-tags' ),
54 'date' => esc_html__( 'Date', 'simple-tags' )
55 ];
56
57 return $columns;
58 }
59
60 public function column_default($item, $column_name)
61 {
62 return isset($item->$column_name) ? $item->$column_name : '&mdash;';
63 }
64
65 public function no_items()
66 {
67 esc_html_e('Schedule log is empty.', 'simple-tags');
68 }
69
70 protected function column_cb($item)
71 {
72 return sprintf('<input type="checkbox" name="%1$s[]" value="%2$s" />', 'taxopress_autoterms_schedule_logs', $item->ID);
73 }
74
75 protected function get_bulk_actions()
76 {
77 $actions = [
78 'taxopress-autoterms-delete-logs' => esc_html__('Delete', 'simple-tags')
79 ];
80
81 return $actions;
82 }
83
84 public function process_bulk_action()
85 {
86
87 $query_arg = '_wpnonce';
88 $action = 'bulk-' . $this->_args['plural'];
89 $checked = $result = isset($_REQUEST[$query_arg]) ? wp_verify_nonce(sanitize_key($_REQUEST[$query_arg]), $action) : false;
90
91 if (!$checked || !current_user_can('simple_tags')) {
92 return;
93 }
94
95 if($this->current_action() === 'taxopress-autoterms-delete-logs'){
96 $taxopress_autoterms_schedule_logs = array_map('sanitize_text_field', (array)$_REQUEST['taxopress_autoterms_schedule_logs']);
97 if (!empty($taxopress_autoterms_schedule_logs)) {
98 foreach($taxopress_autoterms_schedule_logs as $taxopress_autoterms_log){
99 wp_delete_post($taxopress_autoterms_log, true);
100 }
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 'page' => 'st_autoterms_schedule',
136 'action' => 'taxopress-delete-autoterm-log',
137 'taxopress_autoterms_log'=> esc_attr($item->ID),
138 '_wpnonce' => wp_create_nonce('autoterm-action-request-nonce')
139 ],
140 admin_url('admin.php')),
141 __('Delete Log', 'simple-tags')
142 ),
143 ];
144
145 return $column_name === $primary ? $this->row_actions($actions, false) : '';
146 }
147
148 protected function column_title($item)
149 {
150 $auto_term_log_post_id = get_post_meta($item->ID, '_taxopress_log_post_id', true);
151
152 $title = sprintf(
153 '<a href="%1$s"><strong><span class="row-title">%2$s</span></strong></a>',
154 add_query_arg(
155 [
156 'action' => 'edit',
157 'post' => $auto_term_log_post_id,
158 ],
159 admin_url('post.php')
160 ),
161 esc_html(get_the_title($auto_term_log_post_id))
162 );
163
164 return $title;
165 }
166
167 protected function column_post_type($item)
168 {
169 $auto_term_log_post_id = get_post_meta($item->ID, '_taxopress_log_post_id', true);
170 $auto_term_log_posttype = get_post_type_object(get_post_type($auto_term_log_post_id));
171
172 return ($auto_term_log_posttype && !is_wp_error($auto_term_log_posttype)) ? $auto_term_log_posttype->labels->singular_name : '&mdash;';
173
174 }
175
176 protected function column_taxonomy($item)
177 {
178 $taxopress_log_taxonomy = get_post_meta($item->ID, '_taxopress_log_taxonomy', true);
179 $taxopress_log_taxonomy_data = get_taxonomy($taxopress_log_taxonomy);
180
181 return ($taxopress_log_taxonomy_data && !is_wp_error($taxopress_log_taxonomy_data)) ? $taxopress_log_taxonomy_data->labels->singular_name : '&mdash;';
182
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
203 public function prepare_items()
204 {
205
206 $this->_column_headers = $this->get_column_info();
207 $this->process_bulk_action();
208
209 $per_page = $this->get_items_per_page('st_autoterms_schedule_logs_per_page', 20);
210
211 $results = $this->get_st_autoterms();
212 $data = $results['posts'];
213 $total_items = $results['counts'];
214 $current_page = $this->get_pagenum();
215
216
217 $this->items = $data;
218
219 $this->set_pagination_args([
220 'total_items' => $total_items,
221 'per_page' => $per_page,
222 'total_pages' => ceil($total_items / $per_page)
223 ]);
224 }
225
226
227 }
228
229