PHP 8.2.31
Preview: DataDownloadIPs.php Size: 4.15 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/Admin/API/DataDownloadIPs.php

<?php
/**
 * REST API Data Download IP Controller
 *
 * Handles requests to /data/download-ips
 */

namespace Automattic\WooCommerce\Admin\API;

defined( 'ABSPATH' ) || exit;

/**
 * Data Download IP controller.
 *
 * @internal
 * @extends WC_REST_Data_Controller
 */
class DataDownloadIPs extends \WC_REST_Data_Controller {
	/**
	 * Endpoint namespace.
	 *
	 * @var string
	 */
	protected $namespace = 'wc-analytics';

	/**
	 * Route base.
	 *
	 * @var string
	 */
	protected $rest_base = 'data/download-ips';

	/**
	 * Register routes.
	 *
	 * @since 3.5.0
	 */
	public function register_routes() {
		register_rest_route(
			$this->namespace,
			'/' . $this->rest_base,
			array(
				array(
					'methods'             => \WP_REST_Server::READABLE,
					'callback'            => array( $this, 'get_items' ),
					'permission_callback' => array( $this, 'get_items_permissions_check' ),
				),
				'schema' => array( $this, 'get_public_item_schema' ),
			)
		);
	}

	/**
	 * Return the download IPs matching the passed parameters.
	 *
	 * @since  3.5.0
	 * @param  WP_REST_Request $request Request data.
	 * @return WP_Error|WP_REST_Response
	 */
	public function get_items( $request ) {
		global $wpdb;

		if ( isset( $request['match'] ) ) {
			$downloads = $wpdb->get_results(
				$wpdb->prepare(
					"SELECT DISTINCT( user_ip_address ) FROM {$wpdb->prefix}wc_download_log
					WHERE user_ip_address LIKE %s
					LIMIT 10",
					$request['match'] . '%'
				)
			);
		} else {
			return new \WP_Error( 'woocommerce_rest_data_download_ips_invalid_request', __( 'Invalid request. Please pass the match parameter.', 'woocommerce' ), array( 'status' => 400 ) );
		}

		$data = array();

		if ( ! empty( $downloads ) ) {
			foreach ( $downloads as $download ) {
				$response = $this->prepare_item_for_response( $download, $request );
				$data[]   = $this->prepare_response_for_collection( $response );
			}
		}

		return rest_ensure_response( $data );
	}

	/**
	 * Prepare the data object for response.
	 *
	 * @since  3.5.0
	 * @param object          $item Data object.
	 * @param WP_REST_Request $request Request object.
	 * @return WP_REST_Response $response Response data.
	 */
	public function prepare_item_for_response( $item, $request ) {
		$data     = $this->add_additional_fields_to_object( $item, $request );
		$data     = $this->filter_response_by_context( $data, 'view' );
		$response = rest_ensure_response( $data );

		$response->add_links( $this->prepare_links( $item ) );

		/**
		 * Filter the list returned from the API.
		 *
		 * @param WP_REST_Response $response The response object.
		 * @param array            $item     The original item.
		 * @param WP_REST_Request  $request  Request used to generate the response.
		 */
		return apply_filters( 'woocommerce_rest_prepare_data_download_ip', $response, $item, $request );
	}

	/**
	 * Prepare links for the request.
	 *
	 * @param object $item Data object.
	 * @return array Links for the given object.
	 */
	protected function prepare_links( $item ) {
		$links = array(
			'collection' => array(
				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
			),
		);
		return $links;
	}

	/**
	 * Get the query params for collections.
	 *
	 * @return array
	 */
	public function get_collection_params() {
		$params            = array();
		$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
		$params['match']   = array(
			'description'       => __( 'A partial IP address can be passed and matching results will be returned.', 'woocommerce' ),
			'type'              => 'string',
			'validate_callback' => 'rest_validate_request_arg',
		);
		return $params;
	}


	/**
	 * Get the schema, conforming to JSON Schema.
	 *
	 * @return array
	 */
	public function get_item_schema() {
		$schema = array(
			'$schema'    => 'http://json-schema.org/draft-04/schema#',
			'title'      => 'data_download_ips',
			'type'       => 'object',
			'properties' => array(
				'user_ip_address' => array(
					'type'        => 'string',
					'description' => __( 'IP address.', 'woocommerce' ),
					'context'     => array( 'view' ),
					'readonly'    => true,
				),
			),
		);

		return $this->add_additional_fields_schema( $schema );
	}
}

Directory Contents

Dirs: 3 × Files: 46

Name Size Perms Modified Actions
AI DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Reports DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Templates DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
9.09 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
2.15 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
3.40 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
2.11 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
939 B lrw-r--r-- 2022-04-20 06:50:54
Edit Download
1.12 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
4.15 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
1.82 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
1.70 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
10.57 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
5.15 KB lrw-r--r-- 2024-12-18 22:19:16
Edit Download
18.22 KB lrw-r--r-- 2024-07-30 19:31:16
Edit Download
4.90 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
9.64 KB lrw-r--r-- 2024-03-26 16:56:02
Edit Download
6.02 KB lrw-r--r-- 2023-01-25 03:19:12
Edit Download
5.74 KB lrw-r--r-- 2023-01-25 03:19:12
Edit Download
3.41 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
5.94 KB lrw-r--r-- 2024-01-30 23:24:56
Edit Download
2.10 KB lrw-r--r-- 2022-09-20 22:53:36
Edit Download
2.39 KB lrw-r--r-- 2023-03-21 20:45:06
Edit Download
25.32 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
2.38 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
2.58 KB lrw-r--r-- 2024-07-30 19:31:16
Edit Download
10.77 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
1.94 KB lrw-r--r-- 2024-01-30 23:24:56
Edit Download
1.80 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
18.38 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
32.02 KB lrw-r--r-- 2025-10-06 17:56:06
Edit Download
5.49 KB lrw-r--r-- 2025-10-06 17:56:06
Edit Download
10.00 KB lrw-r--r-- 2025-05-26 19:11:58
Edit Download
10.13 KB lrw-r--r-- 2024-07-30 19:31:16
Edit Download
5.91 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
21.27 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
4.46 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
4.36 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
458 B lrw-r--r-- 2022-04-20 06:50:54
Edit Download
3.06 KB lrw-r--r-- 2023-02-22 07:17:34
Edit Download
1.30 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
9.73 KB lrw-r--r-- 2024-10-21 23:53:16
Edit Download
17.62 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
6.03 KB lrw-r--r-- 2025-01-21 18:53:44
Edit Download
878 B lrw-r--r-- 2023-03-21 20:45:06
Edit Download
4.20 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
6.33 KB lrw-r--r-- 2026-05-11 17:17:08
Edit Download
4.90 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
6.12 KB lrw-r--r-- 2024-02-27 18:59:46
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).