diff --git a/includes/admin/reports/class-wc-report-downloads.php b/includes/admin/reports/class-wc-report-downloads.php index b743b73d463..ffedbdaad42 100644 --- a/includes/admin/reports/class-wc-report-downloads.php +++ b/includes/admin/reports/class-wc-report-downloads.php @@ -58,7 +58,8 @@ class WC_Report_Downloads extends WP_List_Table { // Subtitle for permission if set. if ( isset( $_GET['permission_id'] ) && is_numeric( $_GET['permission_id'] ) && $_GET['permission_id'] > 0 ) { - $permission_id = $_GET['permission_id']; + $permission_id = absint( $_GET['permission_id'] ); // WPCS: input var ok. + // Load the permission, order, etc. so we can render more information. $permission = null; $product = null; @@ -66,7 +67,7 @@ class WC_Report_Downloads extends WP_List_Table { $permission = new WC_Customer_Download( $permission_id ); $product = wc_get_product( $permission->product_id ); } catch ( Exception $e ) { - wp_die( sprintf( __( 'Permission #%d not found.', 'woocommerce' ), $permission_id ) ); + wp_die( sprintf( esc_html__( 'Permission #%d not found.', 'woocommerce' ), $permission_id ) ); } if ( ! empty( $permission ) && ! empty( $product ) ) { @@ -129,12 +130,9 @@ class WC_Report_Downloads extends WP_List_Table { echo esc_html( $item->timestamp ); break; case 'product' : - if ( empty( $product ) ) { - break; + if ( ! empty( $product ) ) { + edit_post_link( $product->get_formatted_name(), '', '', $product->get_id() ); } - - edit_post_link( $product->get_formatted_name(), '', '', $product->get_id() ); - break; case 'order' : if ( ! empty( $permission ) ) { @@ -229,10 +227,11 @@ class WC_Report_Downloads extends WP_List_Table { // Apply filter by permission. if ( isset( $_GET['permission_id'] ) && is_numeric( $_GET['permission_id'] ) && $_GET['permission_id'] > 0 ) { + $permission_id = absint( $_GET['permission_id'] ); // WPCS: input var ok. // Ensure the permission and product exist. try { - $permission = new WC_Customer_Download( $_GET['permission_id'] ); + $permission = new WC_Customer_Download( $permission_id ); $product = wc_get_product( $permission->product_id ); } catch ( Exception $e ) { // Leave array empty since we can't find the permission. @@ -240,7 +239,7 @@ class WC_Report_Downloads extends WP_List_Table { } // Add filter for permission id. - $query_from .= $wpdb->prepare( "AND permission_id = %d", $_GET['permission_id'] ); + $query_from .= $wpdb->prepare( "AND permission_id = %d", $permission_id ); } $query_from = apply_filters( 'woocommerce_report_downloads_query_from', $query_from ); diff --git a/includes/class-wc-customer-download-log.php b/includes/class-wc-customer-download-log.php index 74c7bc445d1..4800f3b58f5 100644 --- a/includes/class-wc-customer-download-log.php +++ b/includes/class-wc-customer-download-log.php @@ -145,29 +145,4 @@ class WC_Customer_Download_Log extends WC_Data { public function set_user_ip_address( $value ) { $this->set_prop( 'user_ip_address', $value ); } - - /* - |-------------------------------------------------------------------------- - | CRUD methods - |-------------------------------------------------------------------------- - */ - - /** - * Save data to the database. - * - * @return int Log ID - */ - public function save() { - if ( $this->data_store ) { - // Trigger action before saving to the DB. Use a pointer to adjust object props before save. - do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store ); - - if ( $this->get_id() ) { - $this->data_store->update( $this ); - } else { - $this->data_store->create( $this ); - } - } - return $this->get_id(); - } } diff --git a/tests/unit-tests/customer/customer-download-log.php b/tests/unit-tests/customer/customer-download-log.php index e571c387eac..0e18b643b74 100644 --- a/tests/unit-tests/customer/customer-download-log.php +++ b/tests/unit-tests/customer/customer-download-log.php @@ -24,8 +24,8 @@ class WC_Tests_Customer_Download_Log extends WC_Unit_Test_Case { $set_to = current_time( 'timestamp', true ); // Convert timestamp to WC_DateTime using ISO 8601 for PHP 5.2 compat. - $dtStr = date("c", $set_to); - $wc_timestamp = new WC_DateTime($dtStr); + $dt_str = date( 'c', $set_to ); + $wc_timestamp = new WC_DateTime( $dt_str ); $object->set_timestamp( $set_to ); $this->assertEquals( $wc_timestamp, $object->get_timestamp() ); @@ -78,8 +78,8 @@ class WC_Tests_Customer_Download_Log extends WC_Unit_Test_Case { $timestamp = current_time( 'timestamp', true ); // Convert timestamp to WC_DateTime using ISO 8601 for PHP 5.2 compat. - $dtStr = date("c", $timestamp); - $wc_timestamp = new WC_DateTime($dtStr); + $dt_str = date( 'c', $timestamp ); + $wc_timestamp = new WC_DateTime( $dt_str ); $download_log = new WC_Customer_Download_Log; $download_log->set_timestamp( $timestamp );