WC_API_Server::get_index()publicWC 2.3

Get the site index.

This endpoint describes the capabilities of the site.

Метод класса: WC_API_Server{}

Возвращает

Массив. Index entity

Использование

$WC_API_Server = new WC_API_Server();
$WC_API_Server->get_index();

Список изменений

С версии 2.3 Введена.

Код WC_API_Server::get_index() WC 8.9.3

public function get_index() {

	// General site data
	$available = array(
		'store' => array(
			'name'        => get_option( 'blogname' ),
			'description' => get_option( 'blogdescription' ),
			'URL'         => get_option( 'siteurl' ),
			'wc_version'  => WC()->version,
			'version'     => WC_API::VERSION,
			'routes'      => array(),
			'meta'        => array(
				'timezone'           => wc_timezone_string(),
				'currency'           => get_woocommerce_currency(),
				'currency_format'    => get_woocommerce_currency_symbol(),
				'currency_position'  => get_option( 'woocommerce_currency_pos' ),
				'thousand_separator' => get_option( 'woocommerce_price_thousand_sep' ),
				'decimal_separator'  => get_option( 'woocommerce_price_decimal_sep' ),
				'price_num_decimals' => wc_get_price_decimals(),
				'tax_included'       => wc_prices_include_tax(),
				'weight_unit'        => get_option( 'woocommerce_weight_unit' ),
				'dimension_unit'     => get_option( 'woocommerce_dimension_unit' ),
				'ssl_enabled'        => ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) || wc_site_is_https() ),
				'permalinks_enabled' => ( '' !== get_option( 'permalink_structure' ) ),
				'generate_password'  => ( 'yes' === get_option( 'woocommerce_registration_generate_password' ) ),
				'links'              => array(
					'help' => 'https://woocommerce.github.io/woocommerce-rest-api-docs/',
				),
			),
		),
	);

	// Find the available routes
	foreach ( $this->get_routes() as $route => $callbacks ) {
		$data = array();

		$route = preg_replace( '#\(\?P(<\w+?>).*?\)#', '$1', $route );

		foreach ( self::$method_map as $name => $bitmask ) {
			foreach ( $callbacks as $callback ) {
				// Skip to the next route if any callback is hidden
				if ( $callback[1] & self::HIDDEN_ENDPOINT ) {
					continue 3;
				}

				if ( $callback[1] & $bitmask ) {
					$data['supports'][] = $name;
				}

				if ( $callback[1] & self::ACCEPT_DATA ) {
					$data['accepts_data'] = true;
				}

				// For non-variable routes, generate links
				if ( strpos( $route, '<' ) === false ) {
					$data['meta'] = array(
						'self' => get_woocommerce_api_url( $route ),
					);
				}
			}
		}

		$available['store']['routes'][ $route ] = apply_filters( 'woocommerce_api_endpoints_description', $data );
	}

	return apply_filters( 'woocommerce_api_index', $available );
}