Deprecate report hooks

This commit is contained in:
Tomek Wytrębowicz 2024-09-19 22:52:29 +02:00
parent bf0646c307
commit afe13c61d9
15 changed files with 230 additions and 67 deletions

View File

@ -472,7 +472,15 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
// Reports Pages.
/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) ) {
$report_screen_ids = apply_filters_deprecated(
'woocommerce_reports_screen_ids',
array( array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
if ( in_array($screen_id, $report_screen_ids ) ) {
wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), $version );
wp_enqueue_script( 'wc-reports' );

View File

@ -100,10 +100,17 @@ if ( ! class_exists( 'WC_Admin_Dashboard', false ) ) :
* Allows modifying the order statuses used in the top seller query inside the dashboard status widget.
*
* @since 2.2.0
* @deprecated 9.5.0 Reports are deprecated and will be removed in future versions. Use Analytics instead.
*
* @param string[] $order_statuses Order statuses.
*/
$order_statuses = apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) );
$order_statuses = apply_filters_deprecated(
'woocommerce_reports_order_statuses',
array( array( 'completed', 'processing', 'on-hold' ) ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$query['where'] .= "AND orders.{$orders_column_status} IN ( 'wc-" . implode( "','wc-", $order_statuses ) . "' ) ";
$query['where'] .= "AND order_item_meta.meta_key = '_qty' ";

View File

@ -141,7 +141,14 @@ class WC_Admin_Reports {
}
$reports = apply_filters( 'woocommerce_admin_reports', $reports );
$reports = apply_filters( 'woocommerce_reports_charts', $reports ); // Backwards compatibility.
// Backwards compatibility.
$reports = apply_filters_deprecated(
'woocommerce_reports_charts',
array( $reports ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
foreach ( $reports as $key => $report_group ) {
if ( isset( $reports[ $key ]['charts'] ) ) {

View File

@ -18,6 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
*
* @package WooCommerce\Admin\Reports
* @version 2.1.0
* @deprecated 9.5.0 Reports are deprecated and will be removed in future versions. Use Analytics instead.
*/
class WC_Admin_Report {
@ -109,7 +110,13 @@ class WC_Admin_Report {
'order_status' => array( 'completed', 'processing', 'on-hold' ),
'parent_order_status' => false,
);
$args = apply_filters( 'woocommerce_reports_get_order_report_data_args', $args );
$args = apply_filters_deprecated(
'woocommerce_reports_get_order_report_data_args',
array( $args ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$args = wp_parse_args( $args, $default_args );
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
@ -119,7 +126,13 @@ class WC_Admin_Report {
return '';
}
$order_status = apply_filters( 'woocommerce_reports_order_statuses', $order_status );
$order_status = apply_filters_deprecated(
'woocommerce_reports_order_statuses',
array( $order_status ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$query = array();
$select = array();
@ -346,7 +359,13 @@ class WC_Admin_Report {
$query['limit'] = "LIMIT {$limit}";
}
$query = apply_filters( 'woocommerce_reports_get_order_report_query', $query );
$query = apply_filters_deprecated(
'woocommerce_reports_get_order_report_query',
array( $query ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$query = implode( ' ', $query );
if ( $debug ) {
@ -358,14 +377,26 @@ class WC_Admin_Report {
if ( $debug || $nocache ) {
self::enable_big_selects();
$result = apply_filters( 'woocommerce_reports_get_order_report_data', $wpdb->$query_type( $query ), $data );
$result = apply_filters_deprecated(
'woocommerce_reports_get_order_report_data',
array( $wpdb->$query_type( $query ), $data ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
} else {
$query_hash = md5( $query_type . $query );
$result = $this->get_cached_query( $query_hash );
if ( null === $result ) {
self::enable_big_selects();
$result = apply_filters( 'woocommerce_reports_get_order_report_data', $wpdb->$query_type( $query ), $data );
$result = apply_filters_deprecated(
'woocommerce_reports_get_order_report_data',
array( $wpdb->$query_type( $query ), $data ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
}
$this->set_cached_query( $query_hash, $result );
}

View File

@ -148,7 +148,13 @@ class WC_Report_Customer_List extends WP_List_Table {
ob_start();
?><p>
<?php
do_action( 'woocommerce_admin_user_actions_start', $user );
wc_do_deprecated_action(
'woocommerce_admin_user_actions_start',
array( $user ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$actions = array();
@ -186,13 +192,25 @@ class WC_Report_Customer_List extends WP_List_Table {
);
}
$actions = apply_filters( 'woocommerce_admin_user_actions', $actions, $user );
$actions = apply_filters_deprecated(
'woocommerce_admin_user_actions',
array( $actions, $user ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
foreach ( $actions as $action ) {
printf( '<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) );
}
do_action( 'woocommerce_admin_user_actions_end', $user );
wc_do_deprecated_action(
'woocommerce_admin_user_actions_end',
array( $user ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
?>
</p>
<?php
@ -281,13 +299,18 @@ class WC_Report_Customer_List extends WP_List_Table {
);
$query = new WP_User_Query(
apply_filters(
apply_filters_deprecated(
'woocommerce_admin_report_customer_list_user_query_args',
array(
'exclude' => array_merge( $admin_users->get_results(), $manager_users->get_results() ),
'number' => $per_page,
'offset' => ( $current_page - 1 ) * $per_page,
)
array(
'exclude' => array_merge( $admin_users->get_results(), $manager_users->get_results() ),
'number' => $per_page,
'offset' => ( $current_page - 1 ) * $per_page,
)
),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.'
)
);

View File

@ -203,12 +203,17 @@ class WC_Report_Customers extends WC_Admin_Report {
);
$users_query = new WP_User_Query(
apply_filters(
apply_filters_deprecated(
'woocommerce_admin_report_customers_user_query_args',
array(
'fields' => array( 'user_registered' ),
'exclude' => array_merge( $admin_users->get_results(), $manager_users->get_results() ),
)
array(
'fields' => array( 'user_registered' ),
'exclude' => array_merge( $admin_users->get_results(), $manager_users->get_results() ),
),
),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
)
);

View File

@ -234,7 +234,16 @@ class WC_Report_Downloads extends WP_List_Table {
$this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
$current_page = absint( $this->get_pagenum() );
// Allow filtering per_page value, but ensure it's at least 1.
$per_page = max( 1, apply_filters( 'woocommerce_admin_downloads_report_downloads_per_page', 20 ) );
$per_page = max(
1,
apply_filters_deprecated(
'woocommerce_admin_downloads_report_downloads_per_page',
array( 20 ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
),
);
$this->get_items( $current_page, $per_page );
@ -327,7 +336,13 @@ class WC_Report_Downloads extends WP_List_Table {
$query_from .= $wpdb->prepare( ' AND user_ip_address = %s ', $filters->user_ip_address );
}
$query_from = apply_filters( 'woocommerce_report_downloads_query_from', $query_from );
$query_from = apply_filters_deprecated(
'woocommerce_report_downloads_query_from',
array( $query_from ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$query_order = $wpdb->prepare( 'ORDER BY timestamp DESC LIMIT %d, %d;', ( $current_page - 1 ) * $per_page, $per_page );
$this->items = $wpdb->get_results( "SELECT * {$query_from} {$query_order}" ); // WPCS: cache ok, db call ok, unprepared SQL ok.

View File

@ -38,21 +38,26 @@ class WC_Report_Low_In_Stock extends WC_Report_Stock {
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
$query_from = apply_filters(
$query_from = apply_filters_deprecated(
'woocommerce_report_low_in_stock_query_from',
$wpdb->prepare(
"
FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND lookup.stock_quantity <= %d
AND lookup.stock_quantity > %d
",
$stock,
$nostock
)
array(
$wpdb->prepare(
"
FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND lookup.stock_quantity <= %d
AND lookup.stock_quantity > %d
",
$stock,
$nostock
)
),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$this->items = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS posts.ID as id, posts.post_parent as parent {$query_from} ORDER BY posts.post_title DESC LIMIT %d, %d;", ( $current_page - 1 ) * $per_page, $per_page ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

View File

@ -30,19 +30,24 @@ class WC_Report_Most_Stocked extends WC_Report_Stock {
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 0 ) );
$query_from = apply_filters(
$query_from = apply_filters_deprecated(
'woocommerce_report_most_stocked_query_from',
$wpdb->prepare(
"
FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND lookup.stock_quantity > %d
",
$stock
)
array(
$wpdb->prepare(
"
FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND lookup.stock_quantity > %d
",
$stock
)
),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$this->items = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS posts.ID as id, posts.post_parent as parent {$query_from} ORDER BY lookup.stock_quantity DESC, id ASC LIMIT %d, %d;", ( $current_page - 1 ) * $per_page, $per_page ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

View File

@ -37,19 +37,24 @@ class WC_Report_Out_Of_Stock extends WC_Report_Stock {
$stock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
$query_from = apply_filters(
$query_from = apply_filters_deprecated(
'woocommerce_report_out_of_stock_query_from',
$wpdb->prepare(
"
FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND lookup.stock_quantity <= %d
",
$stock
)
array(
$wpdb->prepare(
"
FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND lookup.stock_quantity <= %d
",
$stock
)
),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$this->items = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS posts.ID as id, posts.post_parent as parent {$query_from} ORDER BY posts.post_title DESC LIMIT %d, %d;", ( $current_page - 1 ) * $per_page, $per_page ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

View File

@ -65,7 +65,15 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
$term_ids[] = $category_id;
$product_ids = get_objects_in_term( $term_ids, 'product_cat' );
return array_unique( apply_filters( 'woocommerce_report_sales_by_category_get_products_in_category', $product_ids, $category_id ) );
return array_unique(
apply_filters_deprecated(
'woocommerce_report_sales_by_category_get_products_in_category',
array( $product_ids, $category_id ) ,
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
)
);
}
/**

View File

@ -441,7 +441,13 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
$this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->order_items, 'order_item_count' ) ) );
// 3rd party filtering of report data
$this->report_data = apply_filters( 'woocommerce_admin_report_data', $this->report_data );
$this->report_data = apply_filters_deprecated(
'woocommerce_admin_report_data',
array( $this->report_data ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
}
/**
@ -674,7 +680,13 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
}
// 3rd party filtering of report data.
$data = apply_filters( 'woocommerce_admin_report_chart_data', $data );
$data = apply_filters_deprecated(
'woocommerce_admin_report_chart_data',
array( $data ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
// Encode in json format.
$chart_data = wp_json_encode(

View File

@ -144,7 +144,13 @@ class WC_Report_Stock extends WP_List_Table {
);
}
$actions = apply_filters( 'woocommerce_admin_stock_report_product_actions', $actions, $product );
$actions = apply_filters_deprecated(
'woocommerce_admin_stock_report_product_actions',
array( $actions, $product ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
foreach ( $actions as $action ) {
printf(
@ -187,7 +193,13 @@ class WC_Report_Stock extends WP_List_Table {
$this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
$current_page = absint( $this->get_pagenum() );
$per_page = apply_filters( 'woocommerce_admin_stock_report_products_per_page', 20 );
$per_page = apply_filters_deprecated(
'woocommerce_admin_stock_report_products_per_page',
array( 20 ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
);
$this->get_items( $current_page, $per_page );

View File

@ -208,8 +208,26 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
$rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $rate_id ) );
?>
<tr>
<th scope="row"><?php echo wp_kses_post( apply_filters( 'woocommerce_reports_taxes_tax_rate', $tax_row->tax_rate, $rate_id, $tax_row ) ); ?></th>
<td><?php echo wp_kses_post( apply_filters( 'woocommerce_reports_taxes_rate', $rate, $rate_id, $tax_row ) ); ?>%</td>
<th scope="row"><?php
echo wp_kses_post(
apply_filters_deprecated(
'woocommerce_reports_taxes_tax_rate',
array( $tax_row->tax_rate, $rate_id, $tax_row ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
)
); ?></th>
<td><?php
echo wp_kses_post(
apply_filters_deprecated(
'woocommerce_reports_taxes_rate',
array( $rate, $rate_id, $tax_row ),
'9.5.0',
null,
'Reports are deprecated and will be removed in future versions. Use Analytics instead.',
)
); ?>%</td>
<td class="total_row"><?php echo esc_html( $tax_row->total_orders ); ?></td>
<td class="total_row"><?php echo wc_price( $tax_row->tax_amount ); // phpcs:ignore ?></td>
<td class="total_row"><?php echo wc_price( $tax_row->shipping_tax_amount ); // phpcs:ignore ?></td>

View File

@ -65,6 +65,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
/**
* Test: get_order_report_data
*
* @expectedDeprecated woocommerce_reports_get_order_report_data_args
*/
public function test_get_order_report_data_returns_empty_string_if_data_is_empty() {
$report = new WC_Admin_Report();