PHP 8.2.31
Preview: AbstractTermsRoute.php Size: 5.08 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/StoreApi/Routes/V1/AbstractTermsRoute.php

<?php
namespace Automattic\WooCommerce\StoreApi\Routes\V1;

use Automattic\WooCommerce\StoreApi\Utilities\Pagination;
use WP_Term_Query;

/**
 * AbstractTermsRoute class.
 */
abstract class AbstractTermsRoute extends AbstractRoute {
	/**
	 * The routes schema.
	 *
	 * @var string
	 */
	const SCHEMA_TYPE = 'term';

	/**
	 * Get the query params for collections of attributes.
	 *
	 * @return array
	 */
	public function get_collection_params() {
		$params                       = array();
		$params['context']            = $this->get_context_param();
		$params['context']['default'] = 'view';

		$params['page'] = array(
			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
			'type'              => 'integer',
			'default'           => 1,
			'sanitize_callback' => 'absint',
			'validate_callback' => 'rest_validate_request_arg',
			'minimum'           => 1,
		);

		$params['per_page'] = array(
			'description'       => __( 'Maximum number of items to be returned in result set. Defaults to no limit if left blank.', 'woocommerce' ),
			'type'              => 'integer',
			'minimum'           => 0,
			'sanitize_callback' => 'absint',
			'validate_callback' => 'rest_validate_request_arg',
		);

		$params['search'] = array(
			'description'       => __( 'Limit results to those matching a string.', 'woocommerce' ),
			'type'              => 'string',
			'sanitize_callback' => 'sanitize_text_field',
			'validate_callback' => 'rest_validate_request_arg',
		);

		$params['exclude'] = array(
			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
			'type'              => 'array',
			'items'             => array(
				'type' => 'integer',
			),
			'default'           => array(),
			'sanitize_callback' => 'wp_parse_id_list',
		);

		$params['include'] = array(
			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
			'type'              => 'array',
			'items'             => array(
				'type' => 'integer',
			),
			'default'           => array(),
			'sanitize_callback' => 'wp_parse_id_list',
		);

		$params['order'] = array(
			'description'       => __( 'Sort ascending or descending.', 'woocommerce' ),
			'type'              => 'string',
			'default'           => 'asc',
			'enum'              => array( 'asc', 'desc' ),
			'validate_callback' => 'rest_validate_request_arg',
		);

		$params['orderby'] = array(
			'description'       => __( 'Sort by term property.', 'woocommerce' ),
			'type'              => 'string',
			'default'           => 'name',
			'enum'              => array(
				'name',
				'slug',
				'count',
			),
			'validate_callback' => 'rest_validate_request_arg',
		);

		$params['hide_empty'] = array(
			'description' => __( 'If true, empty terms will not be returned.', 'woocommerce' ),
			'type'        => 'boolean',
			'default'     => true,
		);

		$params['parent'] = array(
			'description'       => __( 'Limit results to terms with a specific parent (hierarchical taxonomies only).', 'woocommerce' ),
			'type'              => 'integer',
			'sanitize_callback' => 'absint',
			'validate_callback' => 'rest_validate_request_arg',
		);

		return $params;
	}

	/**
	 * Get terms matching passed in args.
	 *
	 * @param string           $taxonomy Taxonomy to get terms from.
	 * @param \WP_REST_Request $request Request object.
	 *
	 * @return \WP_REST_Response
	 */
	protected function get_terms_response( $taxonomy, $request ) {
		$page          = (int) $request['page'];
		$per_page      = $request['per_page'] ? (int) $request['per_page'] : 0;
		$prepared_args = array(
			'taxonomy'   => $taxonomy,
			'exclude'    => $request['exclude'],
			'include'    => $request['include'],
			'order'      => $request['order'],
			'orderby'    => $request['orderby'],
			'hide_empty' => (bool) $request['hide_empty'],
			'number'     => $per_page,
			'offset'     => $per_page > 0 ? ( $page - 1 ) * $per_page : 0,
			'search'     => $request['search'],
		);

		if ( isset( $request['parent'] ) && is_taxonomy_hierarchical( $taxonomy ) ) {
			$prepared_args['parent'] = (int) $request['parent'];
		}

		$term_query = new WP_Term_Query();
		$objects    = $term_query->query( $prepared_args );
		$return     = [];

		foreach ( $objects as $object ) {
			$data     = $this->prepare_item_for_response( $object, $request );
			$return[] = $this->prepare_response_for_collection( $data );
		}

		$response = rest_ensure_response( $return );

		// See if pagination is needed before calculating.
		if ( $per_page > 0 && ( count( $objects ) === $per_page || $page > 1 ) ) {
			$term_count = $this->get_term_count( $taxonomy, $prepared_args );
			$response   = ( new Pagination() )->add_headers( $response, $request, $term_count, ceil( $term_count / $per_page ) );
		}

		return $response;
	}

	/**
	 * Get count of terms for current query.
	 *
	 * @param string $taxonomy Taxonomy to get terms from.
	 * @param array  $args Array of args to pass to wp_count_terms.
	 * @return int
	 */
	protected function get_term_count( $taxonomy, $args ) {
		$count_args = $args;
		unset( $count_args['number'], $count_args['offset'] );
		return (int) wp_count_terms( $taxonomy, $count_args );
	}
}

Directory Contents

Dirs: 2 × Files: 34

Name Size Perms Modified Actions
Agentic DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
AI DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
9.54 KB lrw-r--r-- 2026-03-12 20:10:34
Edit Download
9.77 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
5.08 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
3.77 KB lrw-r--r-- 2026-03-03 03:30:28
Edit Download
1.34 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
4.63 KB lrw-r--r-- 2026-03-09 16:07:22
Edit Download
2.07 KB lrw-r--r-- 2024-07-30 19:31:16
Edit Download
3.89 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
2.66 KB lrw-r--r-- 2024-07-30 19:31:16
Edit Download
1.93 KB lrw-r--r-- 2024-04-30 19:35:34
Edit Download
3.82 KB lrw-r--r-- 2024-04-30 19:35:34
Edit Download
4.07 KB lrw-r--r-- 2024-04-30 19:35:34
Edit Download
2.51 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
2.58 KB lrw-r--r-- 2026-03-09 16:07:22
Edit Download
3.60 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
9.94 KB lrw-r--r-- 2026-03-12 20:10:34
Edit Download
2.49 KB lrw-r--r-- 2026-03-09 16:07:22
Edit Download
32.12 KB lrw-r--r-- 2026-03-12 20:10:34
Edit Download
7.91 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
2.24 KB lrw-r--r-- 2025-11-24 23:10:10
Edit Download
2.86 KB lrw-r--r-- 2024-08-27 23:04:44
Edit Download
1.59 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
2.00 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
2.18 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
1.36 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
2.39 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
1.35 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
1.98 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
7.13 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
6.71 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
15.17 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
2.13 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
2.95 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
1.24 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download

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