+
Skip to content

Undefined variable $order in API response #933

Open
@andradedaniel

Description

@andradedaniel

Bug description

When accessing the API with specific parameters related to taxonomy, the following error occurs:
Undefined variable: order in /var/www/html/public/wp-content/plugins/tainacan/classes/api/endpoints/class-tainacan-rest-items-controller.php on line 544.

How to reproduce such bug

Use the following steps to reproduce the issue:
1. Make an API request to the endpoint /wp-json/tainacan/v2/items with parameters including taxonomy-related filters (e.g., ?taxquery[0][taxonomy]=tnc_tax_90498&taxquery[0][terms]=17881&taxquery[0][compare]=IN).
2. Observe the response.

Expected behavior

The API should return the filtered items based on the taxonomy parameters without triggering an error.

Additional context

The error occurs because the $order variable is only initialized if a certain condition within an if statement is met. If the condition is not satisfied, $order remains undefined, leading to the error when it’s used in the line 544. Below is the relevant snippet of the code:

https://github.com/tainacan/tainacan/blob/2e0228b6252008d604fd772fdfac505ebeaffe9e/src/classes/api/endpoints/class-tainacan-rest-items-controller.php#L461C3-L465C4

$filter_order_index = $order ? array_search( $filter_id, array_column( $order, 'id' ) ) : false;

Potential fix:
Ensure $order is always initialized regardless of the condition.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载