# woocommerce-pos/1.10.16/includes/API/V1/Extensions.php

WCPOS – Point of Sale (POS) plugin for WooCommerce, version 1.10.16. 119 lines.

- Page: https://pluginprobe.com/plugins/woocommerce-pos/1.10.16/code/includes/API/V1/Extensions.php
- Raw: https://pluginprobe.com/plugins/woocommerce-pos/1.10.16/raw/includes/API/V1/Extensions.php
- Modified: 2026-08-25T07:52:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/woocommerce-pos/1.10.16/code/includes/API/V1/Extensions.php#L10-L20`.

```php
<?php
/**
 * Extensions REST API controller.
 *
 * Serves the extension catalog with local plugin status.
 *
 * @package WCPOS\WooCommercePOS\API\V1
 */

namespace WCPOS\WooCommercePOS\API\V1;

use WCPOS\WooCommercePOS\Services\Extensions as ExtensionsService;
use WP_REST_Controller;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;

use const WCPOS\WooCommercePOS\SHORT_NAME;

/**
 * Extensions controller class.
 */
class Extensions extends WP_REST_Controller {

	/**
	 * Route namespace.
	 *
	 * @var string
	 */
	protected $namespace = SHORT_NAME . '/v1';

	/**
	 * Route base.
	 *
	 * @var string
	 */
	protected $rest_base = 'extensions';

	/**
	 * Register routes.
	 *
	 * @return void
	 */
	public function register_routes(): void {
		register_rest_route(
			$this->namespace,
			'/' . $this->rest_base,
			array(
				'methods'             => WP_REST_Server::READABLE,
				'callback'            => array( $this, 'get_items' ),
				'permission_callback' => array( $this, 'check_permissions' ),
				'args'                => array(
					'force' => array(
						'type'              => 'boolean',
						'default'           => false,
						'sanitize_callback' => 'rest_sanitize_boolean',
					),
				),
			)
		);
	}

	/**
	 * Get all extensions with status.
	 *
	 * @param WP_REST_Request $request Request object.
	 *
	 * @return WP_REST_Response
	 */
	public function get_items( $request ): WP_REST_Response {
		$service = ExtensionsService::instance();
		$force   = $request->get_param( 'force' );
		if ( $force && ! $service->clear_cache() ) {
			return new WP_REST_Response(
				array(
					'code'    => 'wcpos_extensions_cache_clear_failed',
					'message' => __( 'Could not clear the extensions cache.', 'woocommerce-pos' ),
				),
				500
			);
		}

		$extensions = $service->get_extensions();
		if ( $force && empty( $extensions ) ) {
			return new WP_REST_Response(
				array(
					'code'    => 'wcpos_extensions_refresh_failed',
					'message' => __( 'Could not refresh extensions. Please try again.', 'woocommerce-pos' ),
				),
				502
			);
		}

		$response = new WP_REST_Response( $extensions );
		$response->header( 'X-WP-Total', (string) \count( $extensions ) );

		return $response;
	}

	/**
	 * Check if the current user has permission.
	 *
	 * @param WP_REST_Request $request Request object.
	 *
	 * @return bool|\WP_Error
	 */
	public function check_permissions( WP_REST_Request $request ) {
		if ( ! current_user_can( 'manage_woocommerce_pos' ) ) {
			return new \WP_Error(
				'rest_forbidden',
				__( 'You do not have permission to view extensions.', 'woocommerce-pos' ),
				array( 'status' => rest_authorization_required_code() )
			);
		}

		return true;
	}
}

```
