Add delete button to single file view

This commit is contained in:
Corey McKrill 2023-11-01 17:10:55 -07:00
parent dbb07106e5
commit 226e2649f7
No known key found for this signature in database
GPG Key ID: 84BBFE669C4D97B8
4 changed files with 40 additions and 7 deletions

View File

@ -1348,6 +1348,12 @@ table.wc_status_table--tools {
} }
} }
.wc-logs-single-file-actions {
margin-left: auto;
display: flex;
gap: 0.5em;
}
.wc-logs-entries { .wc-logs-entries {
background: #f6f7f7; background: #f6f7f7;
border: 1px solid #c3c4c7; border: 1px solid #c3c4c7;

View File

@ -181,7 +181,7 @@ class FileController {
if ( count( $result ) < 1 ) { if ( count( $result ) < 1 ) {
return new WP_Error( return new WP_Error(
'wc_log_file_error', 'wc_log_file_error',
esc_html__( 'Could not read the specified file.', 'woocommerce' ) esc_html__( 'This file does not exist.', 'woocommerce' )
); );
} }

View File

@ -229,7 +229,7 @@ class ListTable extends WP_List_Table {
<input <input
id="cb-select-<?php echo esc_attr( $item->get_file_id() ); ?>" id="cb-select-<?php echo esc_attr( $item->get_file_id() ); ?>"
type="checkbox" type="checkbox"
name="file[]" name="file_id[]"
value="<?php echo esc_attr( $item->get_file_id() ); ?>" value="<?php echo esc_attr( $item->get_file_id() ); ?>"
/> />
<label for="cb-select-<?php echo esc_attr( $item->get_hash() ); ?>"> <label for="cb-select-<?php echo esc_attr( $item->get_hash() ); ?>">

View File

@ -177,9 +177,14 @@ class PageController {
if ( is_wp_error( $file ) ) { if ( is_wp_error( $file ) ) {
?> ?>
<div class="notice notice-error notice-inline"> <div class="notice notice-error notice-inline">
<p> <?php echo wp_kses_post( wpautop( $file->get_error_message() ) ); ?>
<?php echo wp_kses_post( $file->get_error_message() ); ?> <?php
</p> printf(
'<p><a href="%1$s">%2$s</a></p>',
esc_url( $this->get_logs_tab_url() ),
esc_html__( 'Return to the file list.', 'woocommerce' )
);
?>
</div> </div>
<?php <?php
@ -189,6 +194,14 @@ class PageController {
$rotations = $this->file_controller->get_file_rotations( $file->get_file_id() ); $rotations = $this->file_controller->get_file_rotations( $file->get_file_id() );
$rotation_url_base = add_query_arg( 'view', 'single_file', $this->get_logs_tab_url() ); $rotation_url_base = add_query_arg( 'view', 'single_file', $this->get_logs_tab_url() );
$delete_url = add_query_arg(
array(
'action' => 'delete',
'file_id' => array( $file->get_file_id() ),
),
wp_nonce_url( $this->get_logs_tab_url(), 'bulk-log-files' )
);
$stream = $file->get_stream(); $stream = $file->get_stream();
$line_number = 1; $line_number = 1;
@ -234,6 +247,16 @@ class PageController {
</ul> </ul>
</nav> </nav>
<?php endif; ?> <?php endif; ?>
<div class="wc-logs-single-file-actions">
<?php
// Delete button.
printf(
'<a href="%1$s" class="button button-secondary">%2$s</a>',
esc_url( $delete_url ),
esc_html__( 'Delete permanently', 'woocommerce' )
);
?>
</div>
</header> </header>
<section id="logs-entries" class="wc-logs-entries"> <section id="logs-entries" class="wc-logs-entries">
<?php while ( ! feof( $stream ) ) : ?> <?php while ( ! feof( $stream ) ) : ?>
@ -367,12 +390,16 @@ class PageController {
if ( $action ) { if ( $action ) {
check_admin_referer( 'bulk-log-files' ); check_admin_referer( 'bulk-log-files' );
if ( ! current_user_can( 'manage_woocommerce' ) ) {
wp_die( esc_html__( 'You do not have permission to manage log files.', 'woocommerce' ) );
}
$sendback = remove_query_arg( array( 'deleted' ), wp_get_referer() ); $sendback = remove_query_arg( array( 'deleted' ), wp_get_referer() );
// Multiple file[] params will be filtered separately, but assigned to $files as an array. // Multiple file_id[] params will be filtered separately, but assigned to $files as an array.
$file_ids = filter_input( $file_ids = filter_input(
INPUT_GET, INPUT_GET,
'file', 'file_id',
FILTER_CALLBACK, FILTER_CALLBACK,
array( array(
'options' => function( $file ) { 'options' => function( $file ) {