# activitypub/9.1.0/includes/transformer/class-term.php

ActivityPub, version 9.1.0. 69 lines.

- Page: https://pluginprobe.com/plugins/activitypub/9.1.0/code/includes/transformer/class-term.php
- Raw: https://pluginprobe.com/plugins/activitypub/9.1.0/raw/includes/transformer/class-term.php
- Modified: 2026-07-22T15:59: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/activitypub/9.1.0/code/includes/transformer/class-term.php#L10-L20`.

```php
<?php
/**
 * Term Transformer Class file.
 *
 * @package Activitypub
 */

namespace Activitypub\Transformer;

use Activitypub\Activity\Base_Object;

/**
 * Term Transformer Class.
 */
class Term extends Base {
	/**
	 * Transforms the WP_Term object to an OrderedCollection.
	 *
	 * @see \Activitypub\Activity\Base_Object
	 *
	 * @return \Activitypub\Activity\Base_Object|\WP_Error The OrderedCollection or WP_Error on failure.
	 */
	public function to_object() {
		$base_object               = new Base_Object();
		$base_object->{'@context'} = 'https://www.w3.org/ns/activitystreams';
		$base_object->set_type( 'OrderedCollection' );
		$base_object->set_id( $this->get_id() );
		$base_object->set_url( $this->get_url() );

		return $base_object;
	}

	/**
	 * Get the OrderedCollection ID.
	 *
	 * @return string The OrderedCollection ID.
	 */
	public function to_id() {
		return $this->get_id();
	}

	/**
	 * Returns the stable ID of the Term.
	 *
	 * Uses term_id query parameter to ensure the ID remains stable
	 * even if the term slug is changed.
	 *
	 * @return string The Term's stable ID.
	 */
	public function get_id() {
		return \add_query_arg( 'term_id', $this->item->term_id, \home_url( '/' ) );
	}

	/**
	 * Returns the URL of the Term.
	 *
	 * @return string The Term's URL (term link).
	 */
	public function get_url() {
		$term_link = \get_term_link( $this->item );

		if ( \is_wp_error( $term_link ) ) {
			return '';
		}

		return \esc_url_raw( $term_link );
	}
}

```
