Yoast\WP\SEO\Builders

Indexable_Link_Builder::patch_seo_links()publicYoast 1.0

Fixes existing SEO links that are supposed to have a target indexable but don't, because of prior indexable cleanup.

Метод класса: Indexable_Link_Builder{}

Хуков нет.

Возвращает

null. Ничего (null).

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

$Indexable_Link_Builder = new Indexable_Link_Builder();
$Indexable_Link_Builder->patch_seo_links( $indexable );
$indexable(Indexable) (обязательный)
The indexable to be the target of SEO Links.

Код Indexable_Link_Builder::patch_seo_links() Yoast 23.4

public function patch_seo_links( Indexable $indexable ) {
	if ( ! empty( $indexable->id ) && ! empty( $indexable->object_id ) ) {
		$links = $this->seo_links_repository->find_all_by_target_post_id( $indexable->object_id );

		$updated_indexable = false;
		foreach ( $links as $link ) {
			if ( \is_a( $link, SEO_Links::class ) && empty( $link->target_indexable_id ) ) {
				// Since that post ID exists in an SEO link but has no target_indexable_id, it's probably because of prior indexable cleanup.
				$this->seo_links_repository->update_target_indexable_id( $link->id, $indexable->id );
				$updated_indexable = true;
			}
		}

		if ( $updated_indexable ) {
			$updated_indexable_id = [ $indexable->id ];
			$this->update_incoming_links_for_related_indexables( $updated_indexable_id );
		}
	}
}