AI
1 year ago
RateLimits
4 weeks ago
Reports
4 weeks ago
Templates
3 years ago
views
4 weeks ago
AnalyticsImports.php
5 months ago
Coupons.php
4 years ago
CustomAttributeTraits.php
4 years ago
Customers.php
4 years ago
Data.php
4 years ago
DataCountries.php
4 years ago
DataDownloadIPs.php
4 years ago
Experiments.php
4 years ago
Features.php
4 years ago
Init.php
4 weeks ago
LaunchYourStore.php
1 year ago
Leaderboards.php
1 year ago
Marketing.php
2 months ago
MarketingCampaignTypes.php
3 years ago
MarketingCampaigns.php
2 years ago
MarketingChannels.php
3 years ago
MarketingOverview.php
2 months ago
MarketingRecommendations.php
2 years ago
MobileAppMagicLink.php
3 years ago
MobileAppQRLogin.php
4 weeks ago
NoteActions.php
4 weeks ago
Notes.php
4 weeks ago
Notice.php
1 year ago
OnboardingFreeExtensions.php
1 year ago
OnboardingPlugins.php
4 weeks ago
OnboardingProductTypes.php
4 years ago
OnboardingProducts.php
2 years ago
OnboardingProfile.php
1 year ago
OnboardingTasks.php
9 months ago
OnboardingThemes.php
9 months ago
Options.php
4 weeks ago
Orders.php
1 year ago
PaymentGatewaySuggestions.php
2 months ago
Plugins.php
2 months ago
ProductAttributeTerms.php
4 years ago
ProductAttributes.php
4 years ago
ProductCategories.php
4 years ago
ProductForm.php
3 years ago
ProductReviews.php
4 years ago
ProductVariations.php
1 year ago
Products.php
1 year ago
ProductsLowInStock.php
4 months ago
SettingOptions.php
3 years ago
ShippingPartnerSuggestions.php
1 month ago
Taxes.php
4 years ago
Themes.php
2 years ago
Customers.php
90 lines
| 1 | <?php |
| 2 | /** |
| 3 | * REST API Customers Controller |
| 4 | * |
| 5 | * Handles requests to /customers/* |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Admin\API; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | /** |
| 13 | * Customers controller. |
| 14 | * |
| 15 | * @internal |
| 16 | * @extends \Automattic\WooCommerce\Admin\API\Reports\Customers\Controller |
| 17 | */ |
| 18 | class Customers extends \Automattic\WooCommerce\Admin\API\Reports\Customers\Controller { |
| 19 | |
| 20 | /** |
| 21 | * Route base. |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | protected $rest_base = 'customers'; |
| 26 | |
| 27 | /** |
| 28 | * Register the routes for customers. |
| 29 | */ |
| 30 | public function register_routes() { |
| 31 | register_rest_route( |
| 32 | $this->namespace, |
| 33 | '/' . $this->rest_base, |
| 34 | array( |
| 35 | array( |
| 36 | 'methods' => \WP_REST_Server::READABLE, |
| 37 | 'callback' => array( $this, 'get_items' ), |
| 38 | 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
| 39 | 'args' => $this->get_collection_params(), |
| 40 | ), |
| 41 | 'schema' => array( $this, 'get_public_item_schema' ), |
| 42 | ) |
| 43 | ); |
| 44 | |
| 45 | register_rest_route( |
| 46 | $this->namespace, |
| 47 | '/' . $this->rest_base . '/(?P<id>[\d-]+)', |
| 48 | array( |
| 49 | 'args' => array( |
| 50 | 'id' => array( |
| 51 | 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), |
| 52 | 'type' => 'integer', |
| 53 | ), |
| 54 | ), |
| 55 | array( |
| 56 | 'methods' => \WP_REST_Server::READABLE, |
| 57 | 'callback' => array( $this, 'get_item' ), |
| 58 | 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
| 59 | 'args' => $this->get_collection_params(), |
| 60 | ), |
| 61 | 'schema' => array( $this, 'get_public_item_schema' ), |
| 62 | ) |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Maps query arguments from the REST request. |
| 68 | * |
| 69 | * @param array $request Request array. |
| 70 | * @return array |
| 71 | */ |
| 72 | protected function prepare_reports_query( $request ) { |
| 73 | $args = parent::prepare_reports_query( $request ); |
| 74 | $args['customers'] = $request['include']; |
| 75 | return $args; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get the query params for collections. |
| 80 | * |
| 81 | * @return array |
| 82 | */ |
| 83 | public function get_collection_params() { |
| 84 | $params = parent::get_collection_params(); |
| 85 | $params['include'] = $params['customers']; |
| 86 | unset( $params['customers'] ); |
| 87 | return $params; |
| 88 | } |
| 89 | } |
| 90 |