| 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 Autoterms_Logs extends WP_List_Table |
| 7 |
{ |
| 8 |
|
| 9 |
/** Class constructor */ |
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
|
| 13 |
parent::__construct([ |
| 14 |
'singular' => __('autotermslog', 'simple-tags'), //singular name of the listed records |
| 15 |
'plural' => __('autotermslogs', 'simple-tags'), //plural name of the listed records |
| 16 |
'ajax' => false //does this table support ajax? |
| 17 |
]); |
| 18 |
|
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Retrieve st_autoterms data from the database |
| 23 |
* |
| 24 |
* @param bool $count_only |
| 25 |
* |
| 26 |
* @return mixed |
| 27 |
*/ |
| 28 |
public function get_st_autoterms() |
| 29 |
{ |
| 30 |
$per_page = $this->get_items_per_page('st_autoterms_logs_per_page', 20); |
| 31 |
$current_page = $this->get_pagenum(); |
| 32 |
|
| 33 |
$orderby = (!empty($_REQUEST['orderby'])) ? sanitize_text_field($_REQUEST['orderby']) : 'ID'; //If no sort, default to role |
| 34 |
$order = (!empty($_REQUEST['order'])) ? sanitize_text_field($_REQUEST['order']) : 'desc'; //If no order, default to asc |
| 35 |
|
| 36 |
|
| 37 |
return taxopress_autoterms_logs_data($per_page, $current_page, $orderby, $order); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Returns the count of records in the database. |
| 42 |
* |
| 43 |
* @return null|string |
| 44 |
*/ |
| 45 |
public static function record_count() |
| 46 |
{ |
| 47 |
return get_st_autoterms()['counts']; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Show single row item |
| 52 |
* |
| 53 |
* @param array $item |
| 54 |
*/ |
| 55 |
public function single_row($item) |
| 56 |
{ |
| 57 |
$class = ['st-autoterm-log-tr']; |
| 58 |
$id = 'st-autoterm-log-' . md5($item->ID); |
| 59 |
echo sprintf('<tr id="%s" class="%s">', esc_attr($id), esc_attr(implode(' ', $class))); |
| 60 |
$this->single_row_columns($item); |
| 61 |
echo '</tr>'; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Add custom pagination side item |
| 66 |
* |
| 67 |
* @param string $which |
| 68 |
*/ |
| 69 |
protected function pagination( $which ) { |
| 70 |
|
| 71 |
parent::pagination($which); |
| 72 |
|
| 73 |
if ('top' === $which) { |
| 74 |
?> |
| 75 |
|
| 76 |
<br class="clear"> |
| 77 |
|
| 78 |
<div class="alignright actions autoterms-log-table-buttons"> |
| 79 |
|
| 80 |
</div> |
| 81 |
<?php |
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Add custom filter to tablenav |
| 88 |
* |
| 89 |
* @param string $which |
| 90 |
*/ |
| 91 |
protected function extra_tablenav( $which ) { |
| 92 |
|
| 93 |
if ( 'top' === $which ) { |
| 94 |
|
| 95 |
|
| 96 |
$log_actions = [ |
| 97 |
'save_posts' => esc_html__( 'Manual post update', 'simple-tags' ), |
| 98 |
'existing_content' => esc_html__( 'Existing content', 'simple-tags' ), |
| 99 |
'daily_cron_schedule' => esc_html__( 'Scheduled daily cron', 'simple-tags' ), |
| 100 |
'hourly_cron_schedule' => esc_html__( 'Scheduled hourly cron', 'simple-tags' ), |
| 101 |
'weekly_cron_schedule' => esc_html__( 'Scheduled weekly cron', 'simple-tags' ) |
| 102 |
]; |
| 103 |
|
| 104 |
$post_types = get_post_types(['public' => true], 'objects'); |
| 105 |
|
| 106 |
$taxonomies = get_all_taxopress_public_taxonomies(); |
| 107 |
|
| 108 |
$status_messages = [ |
| 109 |
'terms_added' => esc_html__( 'Terms added successfully', 'simple-tags' ), |
| 110 |
'invalid_option' => esc_html__( 'Auto Terms settings do not exist.', 'simple-tags' ), |
| 111 |
'term_only_option' => esc_html__( 'Auto Terms settings are configured to skip posts with terms.', 'simple-tags' ), |
| 112 |
'empty_post_content' => esc_html__( 'Post content is empty.', 'simple-tags' ), |
| 113 |
'empty_terms' => esc_html__( 'No new matching terms for Auto Terms settings and the post content.', 'simple-tags' ), |
| 114 |
'empty_terms_remove_all' => esc_html__( 'No new matching terms for Auto Terms settings and the post content. However, the existing terms were removed due to the Auto Terms replacement settings.', 'simple-tags' ) |
| 115 |
]; |
| 116 |
|
| 117 |
$autoterm_settings = taxopress_get_autoterm_data(); |
| 118 |
|
| 119 |
$selected_source = (!empty($_REQUEST['log_source_filter'])) ? sanitize_text_field($_REQUEST['log_source_filter']) : ''; |
| 120 |
$selected_post_type = (!empty($_REQUEST['log_filter_post_type'])) ? sanitize_text_field($_REQUEST['log_filter_post_type']) : ''; |
| 121 |
$selected_taxonomy = (!empty($_REQUEST['log_filter_taxonomy'])) ? sanitize_text_field($_REQUEST['log_filter_taxonomy']) : ''; |
| 122 |
$selected_status_message = (!empty($_REQUEST['log_filter_status_message'])) ? sanitize_text_field($_REQUEST['log_filter_status_message']) : ''; |
| 123 |
$selected_settings = (!empty($_REQUEST['log_filter_settings'])) ? (int)$_REQUEST['log_filter_settings'] : 0; |
| 124 |
?> |
| 125 |
|
| 126 |
|
| 127 |
<div class="alignleft actions autoterms-log-table-filter"> |
| 128 |
|
| 129 |
<select class="auto-terms-log-filter-select" name="log_filter_select_post_type" id="log_filter_select_post_type"> |
| 130 |
<option value=""><?php esc_html_e('Post type', 'simple-tags'); ?></option> |
| 131 |
<?php |
| 132 |
foreach ( $post_types as $post_type ) { |
| 133 |
echo '<option value="'. esc_attr($post_type->name) .'" '.selected($selected_post_type, $post_type->name, false).'>'. esc_html($post_type->label) .'</option>'; |
| 134 |
} |
| 135 |
?> |
| 136 |
</select> |
| 137 |
|
| 138 |
<select class="auto-terms-log-filter-select" name="log_filter_select_taxonomy" id="log_filter_select_taxonomy"> |
| 139 |
<option value=""><?php esc_html_e('Taxonomy', 'simple-tags'); ?></option> |
| 140 |
<?php |
| 141 |
foreach ( $taxonomies as $taxonomy ) { |
| 142 |
echo '<option value="'. esc_attr($taxonomy->name) .'" '.selected($selected_taxonomy, $taxonomy->name, false).'>'. esc_html($taxonomy->labels->name) .'</option>'; |
| 143 |
} |
| 144 |
?> |
| 145 |
</select> |
| 146 |
|
| 147 |
<select class="auto-terms-log-filter-select" name="log_source_filter_select" id="log_source_filter_select"> |
| 148 |
<option value=""><?php esc_html_e('Source', 'simple-tags'); ?></option> |
| 149 |
<?php |
| 150 |
foreach ( $log_actions as $key => $label ) { |
| 151 |
echo '<option value="'. esc_attr($key) .'" '.selected($selected_source, $key, false).'>'. esc_html($label) .'</option>'; |
| 152 |
} |
| 153 |
?> |
| 154 |
</select> |
| 155 |
|
| 156 |
<select class="auto-terms-log-filter-select" name="log_filter_select_status_message" id="log_filter_select_status_message"> |
| 157 |
<option value=""><?php esc_html_e('Status message', 'simple-tags'); ?></option> |
| 158 |
<?php |
| 159 |
foreach ( $status_messages as $key => $label ) { |
| 160 |
echo '<option value="'. esc_attr($key) .'" '.selected($selected_status_message, $key, false).'>'. esc_html($label) .'</option>'; |
| 161 |
} |
| 162 |
?> |
| 163 |
</select> |
| 164 |
|
| 165 |
<select class="auto-terms-log-filter-select" name="log_filter_select_settings" id="log_filter_select_settings"> |
| 166 |
<option value=""><?php esc_html_e('Settings', 'simple-tags'); ?></option> |
| 167 |
<?php |
| 168 |
foreach ( $autoterm_settings as $autoterm_setting ) { |
| 169 |
echo '<option value="'. esc_attr($autoterm_setting['ID']) .'" '.selected($selected_settings, $autoterm_setting['ID'], false).'>'. esc_html($autoterm_setting['title']) .'</option>'; |
| 170 |
} |
| 171 |
?> |
| 172 |
</select> |
| 173 |
|
| 174 |
<a href="javascript:void(0)" class="taxopress-logs-tablenav-filter button"><?php esc_html_e('Filter', 'simple-tags'); ?></a> |
| 175 |
|
| 176 |
</div> |
| 177 |
<?php |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Associative array of columns |
| 183 |
* |
| 184 |
* @return array |
| 185 |
*/ |
| 186 |
function get_columns() |
| 187 |
{ |
| 188 |
$columns = [ |
| 189 |
'cb' => '<input type="checkbox"/>', //Render a checkbox instead of text |
| 190 |
'title' => esc_html__( 'Post', 'simple-tags' ), |
| 191 |
'post_type' => esc_html__( 'Post type', 'simple-tags' ), |
| 192 |
'taxonomy' => esc_html__( 'Taxonomy', 'simple-tags' ), |
| 193 |
'source' => esc_html__( 'Source', 'simple-tags' ), |
| 194 |
'terms' => esc_html__( 'Terms added', 'simple-tags' ), |
| 195 |
'status_message' => esc_html__( 'Status message', 'simple-tags' ), |
| 196 |
'date' => esc_html__( 'Date', 'simple-tags' ), |
| 197 |
'settings' => esc_html__( 'Settings', 'simple-tags' ) |
| 198 |
]; |
| 199 |
|
| 200 |
return $columns; |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Render a column when no column specific method exist. |
| 205 |
* |
| 206 |
* @param array $item |
| 207 |
* @param string $column_name |
| 208 |
* |
| 209 |
* @return mixed |
| 210 |
*/ |
| 211 |
public function column_default($item, $column_name) |
| 212 |
{ |
| 213 |
return isset($item->$column_name) ? $item->$column_name : '—'; |
| 214 |
} |
| 215 |
|
| 216 |
/** Text displayed when no stterm data is available */ |
| 217 |
public function no_items() |
| 218 |
{ |
| 219 |
esc_html_e('No item avaliable.', 'simple-tags'); |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* The checkbox column |
| 224 |
* |
| 225 |
* @param object $item |
| 226 |
* |
| 227 |
* @return string|void |
| 228 |
*/ |
| 229 |
protected function column_cb($item) |
| 230 |
{ |
| 231 |
return sprintf('<input type="checkbox" name="%1$s[]" value="%2$s" />', 'taxopress_autoterms_logs', $item->ID); |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* Get the bulk actions to show in the top page dropdown |
| 236 |
* |
| 237 |
* @return array |
| 238 |
*/ |
| 239 |
protected function get_bulk_actions() |
| 240 |
{ |
| 241 |
$actions = [ |
| 242 |
'taxopress-autoterms-delete-logs' => esc_html__('Delete', 'simple-tags') |
| 243 |
]; |
| 244 |
|
| 245 |
return $actions; |
| 246 |
} |
| 247 |
|
| 248 |
/** |
| 249 |
* Process bulk actions |
| 250 |
*/ |
| 251 |
public function process_bulk_action() |
| 252 |
{ |
| 253 |
|
| 254 |
$query_arg = '_wpnonce'; |
| 255 |
$action = 'bulk-' . $this->_args['plural']; |
| 256 |
$checked = $result = isset($_REQUEST[$query_arg]) ? wp_verify_nonce(sanitize_key($_REQUEST[$query_arg]), $action) : false; |
| 257 |
|
| 258 |
if (!$checked || !current_user_can('simple_tags')) { |
| 259 |
return; |
| 260 |
} |
| 261 |
|
| 262 |
if($this->current_action() === 'taxopress-autoterms-delete-logs'){ |
| 263 |
$taxopress_autoterms_logs = array_map('sanitize_text_field', (array)$_REQUEST['taxopress_autoterms_logs']); |
| 264 |
if (!empty($taxopress_autoterms_logs)) { |
| 265 |
foreach($taxopress_autoterms_logs as $taxopress_autoterms_log){ |
| 266 |
wp_delete_post($taxopress_autoterms_log, true); |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* Columns to make sortable. |
| 275 |
* |
| 276 |
* @return array |
| 277 |
*/ |
| 278 |
protected function get_sortable_columns() |
| 279 |
{ |
| 280 |
$sortable_columns = [ |
| 281 |
'title' => ['title', true], |
| 282 |
'date' => ['date', true] |
| 283 |
]; |
| 284 |
|
| 285 |
return $sortable_columns; |
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* Generates and display row actions links for the list table. |
| 290 |
* |
| 291 |
* @param object $item The item being acted upon. |
| 292 |
* @param string $column_name Current column name. |
| 293 |
* @param string $primary Primary column name. |
| 294 |
* |
| 295 |
* @return string The row actions HTML, or an empty string if the current column is the primary column. |
| 296 |
*/ |
| 297 |
protected function handle_row_actions($item, $column_name, $primary) |
| 298 |
{ |
| 299 |
$auto_term_log_post_id = get_post_meta($item->ID, '_taxopress_log_post_id', true); |
| 300 |
|
| 301 |
//Build row actions |
| 302 |
$actions = [ |
| 303 |
'edit' => sprintf( |
| 304 |
'<a href="%s">%s</a>', |
| 305 |
add_query_arg( |
| 306 |
[ |
| 307 |
'action' => 'edit', |
| 308 |
'post' => $auto_term_log_post_id, |
| 309 |
], |
| 310 |
admin_url('post.php') |
| 311 |
), |
| 312 |
__('Edit Main Post', 'simple-tags') |
| 313 |
), |
| 314 |
'delete' => sprintf( |
| 315 |
'<a href="%s" class="delete-autoterm">%s</a>', |
| 316 |
add_query_arg([ |
| 317 |
'page' => 'st_autoterms', |
| 318 |
'tab' => 'logs', |
| 319 |
'action' => 'taxopress-delete-autoterm-log', |
| 320 |
'taxopress_autoterms_log'=> esc_attr($item->ID), |
| 321 |
'_wpnonce' => wp_create_nonce('autoterm-action-request-nonce') |
| 322 |
], |
| 323 |
admin_url('admin.php')), |
| 324 |
__('Delete Log', 'simple-tags') |
| 325 |
), |
| 326 |
]; |
| 327 |
|
| 328 |
return $column_name === $primary ? $this->row_actions($actions, false) : ''; |
| 329 |
} |
| 330 |
|
| 331 |
/** |
| 332 |
* Method for title column |
| 333 |
* |
| 334 |
* @param array $item |
| 335 |
* |
| 336 |
* @return string |
| 337 |
*/ |
| 338 |
protected function column_title($item) |
| 339 |
{ |
| 340 |
$auto_term_log_post_id = get_post_meta($item->ID, '_taxopress_log_post_id', true); |
| 341 |
|
| 342 |
$title = sprintf( |
| 343 |
'<a href="%1$s"><strong><span class="row-title">%2$s</span></strong></a>', |
| 344 |
add_query_arg( |
| 345 |
[ |
| 346 |
'action' => 'edit', |
| 347 |
'post' => $auto_term_log_post_id, |
| 348 |
], |
| 349 |
admin_url('post.php') |
| 350 |
), |
| 351 |
esc_html(get_the_title($auto_term_log_post_id)) |
| 352 |
); |
| 353 |
|
| 354 |
return $title; |
| 355 |
} |
| 356 |
|
| 357 |
/** |
| 358 |
* Method for post_type column |
| 359 |
* |
| 360 |
* @param array $item |
| 361 |
* |
| 362 |
* @return string |
| 363 |
*/ |
| 364 |
protected function column_post_type($item) |
| 365 |
{ |
| 366 |
$auto_term_log_post_id = get_post_meta($item->ID, '_taxopress_log_post_id', true); |
| 367 |
$auto_term_log_posttype = get_post_type_object(get_post_type($auto_term_log_post_id)); |
| 368 |
|
| 369 |
return ($auto_term_log_posttype && !is_wp_error($auto_term_log_posttype)) ? $auto_term_log_posttype->labels->singular_name : '—'; |
| 370 |
|
| 371 |
} |
| 372 |
|
| 373 |
/** |
| 374 |
* Method for taxonomy column |
| 375 |
* |
| 376 |
* @param array $item |
| 377 |
* |
| 378 |
* @return string |
| 379 |
*/ |
| 380 |
protected function column_taxonomy($item) |
| 381 |
{ |
| 382 |
$taxopress_log_taxonomy = get_post_meta($item->ID, '_taxopress_log_taxonomy', true); |
| 383 |
$taxopress_log_taxonomy_data = get_taxonomy($taxopress_log_taxonomy); |
| 384 |
|
| 385 |
return ($taxopress_log_taxonomy_data && !is_wp_error($taxopress_log_taxonomy_data)) ? $taxopress_log_taxonomy_data->labels->singular_name : '—'; |
| 386 |
|
| 387 |
} |
| 388 |
|
| 389 |
/** |
| 390 |
* Method for source column |
| 391 |
* |
| 392 |
* @param array $item |
| 393 |
* |
| 394 |
* @return string |
| 395 |
*/ |
| 396 |
protected function column_source($item) |
| 397 |
{ |
| 398 |
|
| 399 |
$taxopress_log_action = get_post_meta($item->ID, '_taxopress_log_action', true); |
| 400 |
|
| 401 |
$log_action_texts = [ |
| 402 |
'save_posts' => esc_html__( 'Manual post update', 'simple-tags' ), |
| 403 |
'existing_content' => esc_html__( 'Existing content', 'simple-tags' ), |
| 404 |
'daily_cron_schedule' => esc_html__( 'Scheduled daily cron', 'simple-tags' ), |
| 405 |
'hourly_cron_schedule' => esc_html__( 'Scheduled hourly cron', 'simple-tags' ), |
| 406 |
'weekly_cron_schedule' => esc_html__( 'Scheduled weekly cron', 'simple-tags' ) |
| 407 |
]; |
| 408 |
|
| 409 |
if(array_key_exists($taxopress_log_action, $log_action_texts)){ |
| 410 |
return esc_html($log_action_texts[$taxopress_log_action]); |
| 411 |
}else{ |
| 412 |
return esc_html($taxopress_log_action); |
| 413 |
} |
| 414 |
|
| 415 |
} |
| 416 |
|
| 417 |
/** |
| 418 |
* Method for terms column |
| 419 |
* |
| 420 |
* @param array $item |
| 421 |
* |
| 422 |
* @return string |
| 423 |
*/ |
| 424 |
protected function column_terms($item) |
| 425 |
{ |
| 426 |
$taxopress_log_terms = get_post_meta($item->ID, '_taxopress_log_terms', true); |
| 427 |
|
| 428 |
if($taxopress_log_terms && !empty(trim($taxopress_log_terms))){ |
| 429 |
return '<font color="green"> '.esc_html(ucwords($taxopress_log_terms)).' </font>'; |
| 430 |
}else{ |
| 431 |
return '<font color="red"> '. esc_html__('None', 'simple-tags') .' </font>'; |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
/** |
| 436 |
* Method for settings column |
| 437 |
* |
| 438 |
* @param array $item |
| 439 |
* |
| 440 |
* @return string |
| 441 |
*/ |
| 442 |
protected function column_settings($item) |
| 443 |
{ |
| 444 |
$taxopress_log_settings = get_post_meta($item->ID, '_taxopress_log_options', true); |
| 445 |
if(!empty($taxopress_log_settings) && is_array($taxopress_log_settings)){ |
| 446 |
return sprintf( |
| 447 |
'<a href="%s">%s</a>', |
| 448 |
add_query_arg( |
| 449 |
[ |
| 450 |
'page' => 'st_autoterms', |
| 451 |
'add' => 'new_item', |
| 452 |
'action' => 'edit', |
| 453 |
'taxopress_autoterms' => $taxopress_log_settings['ID'], |
| 454 |
], |
| 455 |
admin_url('admin.php') |
| 456 |
), |
| 457 |
$taxopress_log_settings['title'] |
| 458 |
); |
| 459 |
}else{ |
| 460 |
return '—'; |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
/** |
| 465 |
* Method for status_message column |
| 466 |
* |
| 467 |
* @param array $item |
| 468 |
* |
| 469 |
* @return string |
| 470 |
*/ |
| 471 |
protected function column_status_message($item) |
| 472 |
{ |
| 473 |
$taxopress_log_status_message = get_post_meta($item->ID, '_taxopress_log_status_message', true); |
| 474 |
|
| 475 |
$status_message_text = [ |
| 476 |
'invalid_option' => esc_html__( 'Auto Terms settings do not exist.', 'simple-tags' ), |
| 477 |
'term_only_option' => esc_html__( 'Auto Terms settings are configured to skip posts with terms.', 'simple-tags' ), |
| 478 |
'empty_post_content' => esc_html__( 'Post content is empty.', 'simple-tags' ), |
| 479 |
'terms_added' => esc_html__( 'Terms added successfully', 'simple-tags' ), |
| 480 |
'empty_terms' => esc_html__( 'No new matching terms for Auto Terms settings and the post content.', 'simple-tags' ), |
| 481 |
'empty_terms_remove_all' => esc_html__( 'No new matching terms for Auto Terms settings and the post content. However, the existing terms were removed due to the Auto Terms replacement settings.', 'simple-tags' ) |
| 482 |
]; |
| 483 |
|
| 484 |
if(array_key_exists($taxopress_log_status_message, $status_message_text)){ |
| 485 |
return esc_html($status_message_text[$taxopress_log_status_message]); |
| 486 |
}else{ |
| 487 |
return esc_html($taxopress_log_status_message); |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
/** |
| 492 |
* Method for date column |
| 493 |
* |
| 494 |
* @param array $item |
| 495 |
* |
| 496 |
* @return string |
| 497 |
*/ |
| 498 |
protected function column_date($item) |
| 499 |
{ |
| 500 |
|
| 501 |
return get_the_date('l F j, Y h:i A', $item->ID); |
| 502 |
|
| 503 |
} |
| 504 |
|
| 505 |
/** |
| 506 |
* Displays the search box. |
| 507 |
* |
| 508 |
* @param string $text The 'submit' button label. |
| 509 |
* @param string $input_id ID attribute value for the search input field. |
| 510 |
* |
| 511 |
* |
| 512 |
*/ |
| 513 |
public function search_box($text, $input_id) |
| 514 |
{ |
| 515 |
if (!isset($_REQUEST['s']) && !$this->has_items()) { |
| 516 |
return; |
| 517 |
} |
| 518 |
|
| 519 |
$input_id = $input_id . '-search-input'; |
| 520 |
|
| 521 |
if (!empty($_REQUEST['orderby'])) { |
| 522 |
echo '<input type="hidden" name="orderby" value="' . esc_attr(sanitize_text_field($_REQUEST['orderby'])) . '" />'; |
| 523 |
} |
| 524 |
if (!empty($_REQUEST['order'])) { |
| 525 |
echo '<input type="hidden" name="order" value="' . esc_attr(sanitize_text_field($_REQUEST['order'])) . '" />'; |
| 526 |
} |
| 527 |
if (!empty($_REQUEST['page'])) { |
| 528 |
echo '<input type="hidden" name="page" value="' . esc_attr(sanitize_text_field($_REQUEST['page'])) . '" />'; |
| 529 |
} |
| 530 |
if (!empty($_REQUEST['tab'])) { |
| 531 |
echo '<input type="hidden" name="tab" value="' . esc_attr(sanitize_text_field($_REQUEST['tab'])) . '" />'; |
| 532 |
} |
| 533 |
|
| 534 |
$custom_filters = ['log_source_filter', 'log_filter_post_type', 'log_filter_taxonomy', 'log_filter_status_message', 'log_filter_settings']; |
| 535 |
|
| 536 |
foreach ($custom_filters as $custom_filter) { |
| 537 |
$filter_value = !empty($_REQUEST[$custom_filter]) ? sanitize_text_field($_REQUEST[$custom_filter]) : ''; |
| 538 |
echo '<input type="hidden" name="' . esc_attr($custom_filter) . '" value="' . esc_attr($filter_value) . '" />'; |
| 539 |
} |
| 540 |
|
| 541 |
$log_limit_link = add_query_arg([ |
| 542 |
'page' => 'st_autoterms', |
| 543 |
'tab' => 'logs', |
| 544 |
'action' => 'taxopress-update-autoterm-limit', |
| 545 |
'_wpnonce' => wp_create_nonce('autoterm-action-request-nonce') |
| 546 |
], |
| 547 |
admin_url('admin.php') |
| 548 |
); |
| 549 |
?> |
| 550 |
<p class="search-box"> |
| 551 |
<span class="autoterms-log-table-limit-settings"> |
| 552 |
<label for="taxopress_auto_terms_logs_limit"><?php esc_html_e( 'Limit the number of logs', 'simple-tags' ); ?></label> |
| 553 |
<input data-link="<?php echo esc_attr($log_limit_link); ?>" type="number" step="1" min="1" name="taxopress_auto_terms_logs_limit" id="taxopress_auto_terms_logs_limit" value="<?php echo (int)get_option('taxopress_auto_terms_logs_limit', 1000); ?>" /> |
| 554 |
<a href="javascript:void(0)" class="taxopress-logs-limit-update button"><?php esc_html_e('Update', 'simple-tags'); ?></a> |
| 555 |
</span> |
| 556 |
|
| 557 |
<label class="screen-reader-text" for="<?php echo esc_attr($input_id); ?>"><?php echo esc_html($text); ?>:</label> |
| 558 |
<input type="search" id="<?php echo esc_attr($input_id); ?>" name="s" |
| 559 |
value="<?php _admin_search_query(); ?>"/> |
| 560 |
<?php submit_button($text, '', '', false, ['id' => 'taxopress-log-search-submit']); ?> |
| 561 |
</p> |
| 562 |
<?php |
| 563 |
} |
| 564 |
|
| 565 |
/** |
| 566 |
* Sets up the items (roles) to list. |
| 567 |
*/ |
| 568 |
public function prepare_items() |
| 569 |
{ |
| 570 |
|
| 571 |
$this->_column_headers = $this->get_column_info(); |
| 572 |
$this->process_bulk_action(); |
| 573 |
|
| 574 |
/** |
| 575 |
* First, lets decide how many records per page to show |
| 576 |
*/ |
| 577 |
$per_page = $this->get_items_per_page('st_autoterms_logs_per_page', 20); |
| 578 |
|
| 579 |
/** |
| 580 |
* Fetch the data |
| 581 |
*/ |
| 582 |
$results = $this->get_st_autoterms(); |
| 583 |
$data = $results['posts']; |
| 584 |
$total_items = $results['counts']; |
| 585 |
$current_page = $this->get_pagenum(); |
| 586 |
|
| 587 |
|
| 588 |
/** |
| 589 |
* Now we can add the data to the items property, where it can be used by the rest of the class. |
| 590 |
*/ |
| 591 |
$this->items = $data; |
| 592 |
|
| 593 |
/** |
| 594 |
* We also have to register our pagination options & calculations. |
| 595 |
*/ |
| 596 |
$this->set_pagination_args([ |
| 597 |
'total_items' => $total_items, //calculate the total number of items |
| 598 |
'per_page' => $per_page, //determine how many items to show on a page |
| 599 |
'total_pages' => ceil($total_items / $per_page) //calculate the total number of pages |
| 600 |
]); |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
} |
| 605 |
|