resolver = $resolver; $this->features = $features; } public function register(): void { // Same priority and legacy wp_title() coverage as MetaTagsProvider. add_filter( 'pre_get_document_title', array( $this, 'filter_title' ), 99 ); add_filter( 'wp_title', array( $this, 'filter_title' ), 99 ); add_filter( 'wp_robots', array( $this, 'filter_robots' ) ); // rel_canonical() in core only prints for singular requests, so the // blog index never gets a canonical link from core — print it here. add_action( 'wp_head', array( $this, 'print_meta_tags' ), 5 ); } public function filter_title( string $title ): string { if ( ! $this->should_handle() || ! $this->features->enabled( 'meta_title' ) || ! $this->resolver->applies() ) { return $title; } $resolved = $this->resolver->title(); return '' !== $resolved ? $resolved : $title; } /** * @param array $robots * * @return array */ public function filter_robots( array $robots ): array { if ( ! $this->should_handle() || ! $this->features->enabled( 'meta_robots' ) || ! $this->resolver->applies() ) { return $robots; } $flags = $this->resolver->robots(); if ( null === $flags ) { return $robots; } if ( ! $flags['index'] ) { $robots['noindex'] = true; } if ( ! $flags['follow'] ) { $robots['nofollow'] = true; } return $robots; } public function print_meta_tags(): void { if ( ! $this->should_handle() || ! $this->resolver->applies() ) { return; } $description = $this->resolver->description(); $canonical = $this->resolver->canonical(); if ( '' !== $description && $this->features->enabled( 'meta_description' ) ) { printf( '' . "\n", esc_attr( $description ) ); } if ( '' !== $canonical && $this->features->enabled( 'canonical' ) ) { printf( '' . "\n", esc_url( $canonical ) ); } $title = $this->resolver->title(); $title = '' !== $title ? $title : $this->resolver->name(); $image = $this->resolver->og_image_url(); if ( $this->features->enabled( 'open_graph' ) ) { SocialTagsPrinter::open_graph( 'website', $title, $canonical, $description, $image ); } if ( $this->features->enabled( 'twitter_cards' ) ) { SocialTagsPrinter::twitter_card( $this->resolver->twitter_card(), $title, $description, $image ); } } private function should_handle(): bool { return (bool) apply_filters( 'acez_seo_should_handle_meta', ! SeoPluginDetector::has_conflict() ); } }