Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Admin/API/Reports
File: Controller.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* REST API Reports controller extended to handle requests to the reports endpoint.
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
namespace Automattic\WooCommerce\Admin\API\Reports;
[5] Fix | Delete
[6] Fix | Delete
defined( 'ABSPATH' ) || exit;
[7] Fix | Delete
[8] Fix | Delete
use Automattic\WooCommerce\Admin\API\Reports\GenericController;
[9] Fix | Delete
use Automattic\WooCommerce\Admin\API\Reports\OrderAwareControllerTrait;
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Reports controller class.
[13] Fix | Delete
*
[14] Fix | Delete
* Controller that handles the endpoint that returns all available analytics endpoints.
[15] Fix | Delete
*
[16] Fix | Delete
* @internal
[17] Fix | Delete
* @extends GenericController
[18] Fix | Delete
*/
[19] Fix | Delete
class Controller extends GenericController {
[20] Fix | Delete
[21] Fix | Delete
use OrderAwareControllerTrait;
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Get all reports.
[25] Fix | Delete
*
[26] Fix | Delete
* @param WP_REST_Request $request Request data.
[27] Fix | Delete
* @return array|WP_Error
[28] Fix | Delete
*/
[29] Fix | Delete
public function get_items( $request ) {
[30] Fix | Delete
$data = array();
[31] Fix | Delete
$reports = array(
[32] Fix | Delete
array(
[33] Fix | Delete
'slug' => 'performance-indicators',
[34] Fix | Delete
'description' => __( 'Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce' ),
[35] Fix | Delete
),
[36] Fix | Delete
array(
[37] Fix | Delete
'slug' => 'revenue/stats',
[38] Fix | Delete
'description' => __( 'Stats about revenue.', 'woocommerce' ),
[39] Fix | Delete
),
[40] Fix | Delete
array(
[41] Fix | Delete
'slug' => 'orders/stats',
[42] Fix | Delete
'description' => __( 'Stats about orders.', 'woocommerce' ),
[43] Fix | Delete
),
[44] Fix | Delete
array(
[45] Fix | Delete
'slug' => 'products',
[46] Fix | Delete
'description' => __( 'Products detailed reports.', 'woocommerce' ),
[47] Fix | Delete
),
[48] Fix | Delete
array(
[49] Fix | Delete
'slug' => 'products/stats',
[50] Fix | Delete
'description' => __( 'Stats about products.', 'woocommerce' ),
[51] Fix | Delete
),
[52] Fix | Delete
array(
[53] Fix | Delete
'slug' => 'variations',
[54] Fix | Delete
'description' => __( 'Variations detailed reports.', 'woocommerce' ),
[55] Fix | Delete
),
[56] Fix | Delete
array(
[57] Fix | Delete
'slug' => 'variations/stats',
[58] Fix | Delete
'description' => __( 'Stats about variations.', 'woocommerce' ),
[59] Fix | Delete
),
[60] Fix | Delete
array(
[61] Fix | Delete
'slug' => 'categories',
[62] Fix | Delete
'description' => __( 'Product categories detailed reports.', 'woocommerce' ),
[63] Fix | Delete
),
[64] Fix | Delete
array(
[65] Fix | Delete
'slug' => 'categories/stats',
[66] Fix | Delete
'description' => __( 'Stats about product categories.', 'woocommerce' ),
[67] Fix | Delete
),
[68] Fix | Delete
array(
[69] Fix | Delete
'slug' => 'coupons',
[70] Fix | Delete
'description' => __( 'Coupons detailed reports.', 'woocommerce' ),
[71] Fix | Delete
),
[72] Fix | Delete
array(
[73] Fix | Delete
'slug' => 'coupons/stats',
[74] Fix | Delete
'description' => __( 'Stats about coupons.', 'woocommerce' ),
[75] Fix | Delete
),
[76] Fix | Delete
array(
[77] Fix | Delete
'slug' => 'taxes',
[78] Fix | Delete
'description' => __( 'Taxes detailed reports.', 'woocommerce' ),
[79] Fix | Delete
),
[80] Fix | Delete
array(
[81] Fix | Delete
'slug' => 'taxes/stats',
[82] Fix | Delete
'description' => __( 'Stats about taxes.', 'woocommerce' ),
[83] Fix | Delete
),
[84] Fix | Delete
array(
[85] Fix | Delete
'slug' => 'downloads',
[86] Fix | Delete
'description' => __( 'Product downloads detailed reports.', 'woocommerce' ),
[87] Fix | Delete
),
[88] Fix | Delete
array(
[89] Fix | Delete
'slug' => 'downloads/files',
[90] Fix | Delete
'description' => __( 'Product download files detailed reports.', 'woocommerce' ),
[91] Fix | Delete
),
[92] Fix | Delete
array(
[93] Fix | Delete
'slug' => 'downloads/stats',
[94] Fix | Delete
'description' => __( 'Stats about product downloads.', 'woocommerce' ),
[95] Fix | Delete
),
[96] Fix | Delete
array(
[97] Fix | Delete
'slug' => 'customers',
[98] Fix | Delete
'description' => __( 'Customers detailed reports.', 'woocommerce' ),
[99] Fix | Delete
),
[100] Fix | Delete
array(
[101] Fix | Delete
'slug' => 'customers/stats',
[102] Fix | Delete
'description' => __( 'Stats about groups of customers.', 'woocommerce' ),
[103] Fix | Delete
),
[104] Fix | Delete
);
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* Filter the list of allowed reports, so that data can be loaded from third party extensions in addition to WooCommerce core.
[108] Fix | Delete
* Array items should be in format of array( 'slug' => 'downloads/stats', 'description' => '',
[109] Fix | Delete
* 'url' => '', and 'path' => '/wc-ext/v1/...'.
[110] Fix | Delete
*
[111] Fix | Delete
* @param array $endpoints The list of allowed reports..
[112] Fix | Delete
*/
[113] Fix | Delete
$reports = apply_filters( 'woocommerce_admin_reports', $reports );
[114] Fix | Delete
[115] Fix | Delete
foreach ( $reports as $report ) {
[116] Fix | Delete
// Silently skip non-compliant reports. Like the ones for WC_Admin_Reports::get_reports().
[117] Fix | Delete
if ( empty( $report['slug'] ) ) {
[118] Fix | Delete
continue;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
if ( empty( $report['path'] ) ) {
[122] Fix | Delete
$report['path'] = '/' . $this->namespace . '/reports/' . $report['slug'];
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
// Allows a different admin page to be loaded here,
[126] Fix | Delete
// or allows an empty url if no report exists for a set of performance indicators.
[127] Fix | Delete
if ( ! isset( $report['url'] ) ) {
[128] Fix | Delete
if ( '/stats' === substr( $report['slug'], -6 ) ) {
[129] Fix | Delete
$url_slug = substr( $report['slug'], 0, -6 );
[130] Fix | Delete
} else {
[131] Fix | Delete
$url_slug = $report['slug'];
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
$report['url'] = '/analytics/' . $url_slug;
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
$item = $this->prepare_item_for_response( (object) $report, $request );
[138] Fix | Delete
$data[] = $this->prepare_response_for_collection( $item );
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
return rest_ensure_response( $data );
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Prepare a report object for serialization.
[146] Fix | Delete
*
[147] Fix | Delete
* @param stdClass $report Report data.
[148] Fix | Delete
* @param WP_REST_Request $request Request object.
[149] Fix | Delete
* @return WP_REST_Response
[150] Fix | Delete
*/
[151] Fix | Delete
public function prepare_item_for_response( $report, $request ) {
[152] Fix | Delete
$data = array(
[153] Fix | Delete
'slug' => $report->slug,
[154] Fix | Delete
'description' => $report->description,
[155] Fix | Delete
'path' => $report->path,
[156] Fix | Delete
);
[157] Fix | Delete
[158] Fix | Delete
// Wrap the data in a response object.
[159] Fix | Delete
$response = parent::prepare_item_for_response( $data, $request );
[160] Fix | Delete
$response->add_links(
[161] Fix | Delete
array(
[162] Fix | Delete
'self' => array(
[163] Fix | Delete
'href' => rest_url( $report->path ),
[164] Fix | Delete
),
[165] Fix | Delete
'report' => array(
[166] Fix | Delete
'href' => $report->url,
[167] Fix | Delete
),
[168] Fix | Delete
'collection' => array(
[169] Fix | Delete
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
[170] Fix | Delete
),
[171] Fix | Delete
)
[172] Fix | Delete
);
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Filter a report returned from the API.
[176] Fix | Delete
*
[177] Fix | Delete
* Allows modification of the report data right before it is returned.
[178] Fix | Delete
*
[179] Fix | Delete
* @param WP_REST_Response $response The response object.
[180] Fix | Delete
* @param object $report The original report object.
[181] Fix | Delete
* @param WP_REST_Request $request Request used to generate the response.
[182] Fix | Delete
*/
[183] Fix | Delete
return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request );
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Get the Report's schema, conforming to JSON Schema.
[188] Fix | Delete
*
[189] Fix | Delete
* @override WP_REST_Controller::get_item_schema()
[190] Fix | Delete
*
[191] Fix | Delete
* @return array
[192] Fix | Delete
*/
[193] Fix | Delete
public function get_item_schema() {
[194] Fix | Delete
$schema = array(
[195] Fix | Delete
'$schema' => 'http://json-schema.org/draft-04/schema#',
[196] Fix | Delete
'title' => 'report',
[197] Fix | Delete
'type' => 'object',
[198] Fix | Delete
'properties' => array(
[199] Fix | Delete
'slug' => array(
[200] Fix | Delete
'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
[201] Fix | Delete
'type' => 'string',
[202] Fix | Delete
'context' => array( 'view' ),
[203] Fix | Delete
'readonly' => true,
[204] Fix | Delete
),
[205] Fix | Delete
'description' => array(
[206] Fix | Delete
'description' => __( 'A human-readable description of the resource.', 'woocommerce' ),
[207] Fix | Delete
'type' => 'string',
[208] Fix | Delete
'context' => array( 'view' ),
[209] Fix | Delete
'readonly' => true,
[210] Fix | Delete
),
[211] Fix | Delete
'path' => array(
[212] Fix | Delete
'description' => __( 'API path.', 'woocommerce' ),
[213] Fix | Delete
'type' => 'string',
[214] Fix | Delete
'context' => array( 'view' ),
[215] Fix | Delete
'readonly' => true,
[216] Fix | Delete
),
[217] Fix | Delete
),
[218] Fix | Delete
);
[219] Fix | Delete
[220] Fix | Delete
return $this->add_additional_fields_schema( $schema );
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Get the query params for collections.
[225] Fix | Delete
*
[226] Fix | Delete
* @return array
[227] Fix | Delete
*/
[228] Fix | Delete
public function get_collection_params() {
[229] Fix | Delete
return array(
[230] Fix | Delete
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
[231] Fix | Delete
);
[232] Fix | Delete
}
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function