Skip to content

Term IDs #2598

@Menrath

Description

@Menrath

Is using the \get_term_link( $this->item ); a good idea for a terms id?

return \get_term_link( $this->item );

What I did in the Event-Bridge back then:

	/**
	 * Get the WordPress term ID of the current Transformers item.
	 *
	 * @return int
	 */
	public function get__id() {
		return $this->item->term_id;
	}

	/**
	 * Get the ActivityPub ID of the term.
	 *
	 * @return string
	 */
	public function get_url() {
		return \get_term_link( $this->item );
	}

	/**
	 * Returns the most unique, resolvable "ID" there currently is for a WordPress term.
	 *
	 * @return string The "ID"
	 */
	public function get_id() {
		/**
		 * The first approach was to use the normal query from WordPress, but it contains the slug, which might be edited.
		 *
		 * \add_query_arg( $this->item->taxonomy, $this->item->slug, \trailingslashit( \home_url() ) );
		 *
		 * As https://github.com/Automattic/wordpress-activitypub/pull/1272 got merged, now we can definy a real ID.
		 */
		return \add_query_arg( 'term_id', $this->item->term_id, \trailingslashit( \home_url() ) );
	}

And of course I had to apply a filter for the query:

       \add_filter( 'activitypub_queried_object', array( $this, 'maybe_detect_event_plugins_location_term' ) );

	/**
	 * Filters the queried object.
	 *
	 * @param \WP_Term|\WP_Post_Type|\WP_Post|\WP_User|\WP_Comment|null $queried_object The queried object.
	 */
	public function maybe_detect_event_plugins_location_term( $queried_object ) {
		if ( $queried_object ) {
			return $queried_object;
		}

		$term_id = \get_query_var( 'term_id' );

		if ( $term_id ) {
			$queried_object = \get_term( $term_id );
		}

		if ( $queried_object instanceof \WP_Term && $this->is_place_taxonomy_of_active_event_plugin( $queried_object->taxonomy ) ) {
			return $queried_object;
		}

		return null;
	}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions