Merged in feature/280-dev-dev01 (pull request #21)

auto-patch  280-dev-dev01-2024-01-19T16_41_58

* auto-patch  280-dev-dev01-2024-01-19T16_41_58
This commit is contained in:
Tony Volpe
2024-01-19 16:44:43 +00:00
parent 2699b5437a
commit be83910651
2125 changed files with 179300 additions and 35639 deletions

View File

@@ -17,6 +17,12 @@ if ( ! class_exists( 'WP_List_Table' ) ) {
}
class WC_Admin_Log_Table_List extends WP_List_Table {
/**
* The key for the user option of how many list table items to display per page.
*
* @const string
*/
public const PER_PAGE_USER_OPTION_KEY = 'woocommerce_status_log_items_per_page';
/**
* Initialize the log table list.
@@ -92,6 +98,40 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
<?php
}
/**
* Generates the table rows.
*
* @return void
*/
public function display_rows() {
foreach ( $this->items as $log ) {
$this->single_row( $log );
if ( ! empty( $log['context'] ) ) {
$this->context_row( $log );
}
}
}
/**
* Render the additional table row that contains extra log context data.
*
* @param array $log Log entry data.
*
* @return void
*/
protected function context_row( $log ) {
// Maintains alternating row background colors.
?>
<tr style="display: none"><td></td></tr>
<tr id="log-context-<?php echo esc_attr( $log['log_id'] ); ?>" class="log-context">
<td colspan="<?php echo esc_attr( $this->get_column_count() ); ?>">
<p><strong><?php esc_html_e( 'Additional context', 'woocommerce' ); ?></strong></p>
<pre><?php echo esc_html( $log['context'] ); ?></pre>
</td>
</tr>
<?php
}
/**
* Get list columns.
*
@@ -104,6 +144,7 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
'level' => __( 'Level', 'woocommerce' ),
'message' => __( 'Message', 'woocommerce' ),
'source' => __( 'Source', 'woocommerce' ),
'context' => __( 'Context', 'woocommerce' ),
);
}
@@ -167,7 +208,10 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
* @return string
*/
public function column_message( $log ) {
return esc_html( $log['message'] );
return sprintf(
'<pre>%s</pre>',
esc_html( $log['message'] )
);
}
/**
@@ -180,6 +224,36 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
return esc_html( $log['source'] );
}
/**
* Context column.
*
* @param array $log Log entry data.
*
* @return string
*/
public function column_context( $log ) {
$content = '';
if ( ! empty( $log['context'] ) ) {
ob_start();
?>
<button
class="log-toggle button button-secondary button-small"
data-log-id="<?php echo esc_attr( $log['log_id'] ); ?>"
data-toggle-status="off"
data-label-show="<?php esc_attr_e( 'Show context', 'woocommerce' ); ?>"
data-label-hide="<?php esc_attr_e( 'Hide context', 'woocommerce' ); ?>"
>
<span class="dashicons dashicons-arrow-down-alt2"></span>
<span class="log-toggle-label screen-reader-text"><?php esc_html_e( 'Show context', 'woocommerce' ); ?></span>
</button>
<?php
$content = ob_get_clean();
}
return $content;
}
/**
* Get bulk actions.
*
@@ -265,7 +339,10 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
$this->prepare_column_headers();
$per_page = $this->get_items_per_page( 'woocommerce_status_log_items_per_page', 10 );
$per_page = $this->get_items_per_page(
self::PER_PAGE_USER_OPTION_KEY,
$this->get_per_page_default()
);
$where = $this->get_items_query_where();
$order = $this->get_items_query_order();
@@ -273,7 +350,7 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
$offset = $this->get_items_query_offset();
$query_items = "
SELECT log_id, timestamp, level, message, source
SELECT log_id, timestamp, level, message, source, context
FROM {$wpdb->prefix}woocommerce_log
{$where} {$order} {$limit} {$offset}
";
@@ -302,7 +379,11 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
protected function get_items_query_limit() {
global $wpdb;
$per_page = $this->get_items_per_page( 'woocommerce_status_log_items_per_page', 10 );
$per_page = $this->get_items_per_page(
self::PER_PAGE_USER_OPTION_KEY,
$this->get_per_page_default()
);
return $wpdb->prepare( 'LIMIT %d', $per_page );
}
@@ -316,7 +397,10 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
protected function get_items_query_offset() {
global $wpdb;
$per_page = $this->get_items_per_page( 'woocommerce_status_log_items_per_page', 10 );
$per_page = $this->get_items_per_page(
self::PER_PAGE_USER_OPTION_KEY,
$this->get_per_page_default()
);
$current_page = $this->get_pagenum();
if ( 1 < $current_page ) {
$offset = $per_page * ( $current_page - 1 );
@@ -392,4 +476,13 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
$this->get_sortable_columns(),
);
}
/**
* Helper to get the default value for the per_page arg.
*
* @return int
*/
public function get_per_page_default(): int {
return 20;
}
}