context = $context; $this->settings = $settings; $this->resolver = $resolver; $this->url = $this->address( $context, $resolver ); } /** * The address the page's ids hang on: its canonical address, and for pages that have none (search * results are not given one) their own address. * * @since 1.0.0 * * @param Context $context Page context. * @param Resolver $resolver Resolver. * @return string */ private function address( Context $context, Resolver $resolver ): string { $canonical = $resolver->canonical( $context ); if ( '' !== $canonical ) { return $canonical; } return Context::SEARCH === $context->type() ? get_search_link( $context->search() ) : home_url( '/' ); } /** * The post of a singular page. * * @since 1.0.0 * * @return WP_Post|null */ public function post(): ?WP_Post { return $this->context->post(); } /** * Whether the site belongs to a person rather than an organization. * * @since 1.0.0 * * @return bool */ public function is_person(): bool { return 'person' === $this->settings->value( 'profile', 'entity_type' ); } /** * Id of something on this page. * * @since 1.0.0 * * @param string $fragment `webpage`, `article`, `breadcrumb` and so on. * @return string */ public function id( string $fragment ): string { return Ids::on_page( $this->url, $fragment ); } /** * Id of the organization or person behind the site. * * @since 1.0.0 * * @return string */ public function entity_id(): string { return Ids::entity( $this->is_person() ); } /** * The page's description. * * @since 1.0.0 * * @return string */ public function description(): string { return $this->resolver->description( $this->context ); } /** * The page's title. * * @since 1.0.0 * * @return string */ public function title(): string { return $this->resolver->title( $this->context ); } }