Yoast\WP\SEO\Abilities\Infrastructure

Term_SEO_Field_Map{} │ Yoast 1.0└─ Abstract_SEO_Field_Map

Translates between the ability input, a term indexable, and the term SEO data output.

Terms support fewer fields than posts: there are no advanced robots flags and no Schema.org page or article type overrides for terms.

Хуков нет.

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

$Term_SEO_Field_Map = new Term_SEO_Field_Map();
// use class methods

Методы

  1. public __construct( Meta_Surface $meta_surface )
  2. public to_seo_array( $indexable )
  3. protected get_boolean_fields()
  4. protected get_string_fields()

Код Term_SEO_Field_Map{} Yoast 28.9

class Term_SEO_Field_Map extends Abstract_SEO_Field_Map {

	/**
	 * Maps the string input fields to the indexable column they write to.
	 *
	 * @var array<string, string>
	 */
	private const STRING_FIELDS = [
		'seo_title'              => 'title',
		'meta_description'       => 'description',
		'canonical'              => 'canonical',
		'open_graph_title'       => 'open_graph_title',
		'open_graph_description' => 'open_graph_description',
		'twitter_title'          => 'twitter_title',
		'twitter_description'    => 'twitter_description',
	];

	/**
	 * Maps the boolean input fields to the indexable column they write to.
	 *
	 * @var array<string, string>
	 */
	private const BOOLEAN_FIELDS = [
		'is_cornerstone' => 'is_cornerstone',
	];

	/**
	 * The meta surface.
	 *
	 * @var Meta_Surface
	 */
	private $meta_surface;

	/**
	 * Constructor.
	 *
	 * @param Meta_Surface $meta_surface The meta surface.
	 */
	public function __construct( Meta_Surface $meta_surface ) {
		$this->meta_surface = $meta_surface;
	}

	/**
	 * Builds the term SEO data array from an indexable: the identity fields of the term, then the shared SEO fields.
	 *
	 * @param Indexable $indexable The indexable to read from.
	 *
	 * @return array<string, int|string|bool|null> The term SEO data, keyed by output-schema property name.
	 */
	public function to_seo_array( $indexable ): array {
		$meta = $this->meta_surface->for_indexable( $indexable, 'Term_Archive' );

		return \array_merge(
			[
				'term_id'   => (int) $indexable->object_id,
				'term_name' => $indexable->breadcrumb_title,
				'permalink' => $indexable->permalink,
				'taxonomy'  => $indexable->object_sub_type,
			],
			$this->get_shared_seo_fields( $indexable, $meta ),
		);
	}

	/**
	 * Returns the string input fields mapped to the indexable column they write to.
	 *
	 * @return array<string, string> The string fields.
	 */
	protected function get_string_fields(): array {
		return self::STRING_FIELDS;
	}

	/**
	 * Returns the boolean input fields mapped to the indexable column they write to.
	 *
	 * @return array<string, string> The boolean fields.
	 */
	protected function get_boolean_fields(): array {
		return self::BOOLEAN_FIELDS;
	}
}