Automattic\WooCommerce\Admin\API

Options::get_item_permissions_check()publicWC 1.0

Check if a given request has access to get options.

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

Хуков нет.

Возвращает

WP_Error|true|false.

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

$Options = new Options();
$Options->get_item_permissions_check( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Код Options::get_item_permissions_check() WC 8.7.0

public function get_item_permissions_check( $request ) {
	$params = ( isset( $request['options'] ) && is_string( $request['options'] ) ) ? explode( ',', $request['options'] ) : array();

	if ( ! $params ) {
		return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'You must supply an array of options.', 'woocommerce' ), 500 );
	}

	foreach ( $params as $option ) {
		if ( ! $this->user_has_permission( $option, $request ) ) {
			if ( 'production' !== wp_get_environment_type() ) {
				return new \WP_Error(
					'woocommerce_rest_cannot_view',
					__( 'Sorry, you cannot view these options, please remember to update the option permissions in Options API to allow viewing these options in non-production environments.', 'woocommerce' ),
					array( 'status' => rest_authorization_required_code() )
				);
			}

			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view these options.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
		}
	}

	return true;
}