front_end = $front_end; } /** * Initializes the integration. * * This is the place to register hooks and filters. * * @return void */ public function register_hooks() { \add_action( 'web_stories_enable_metadata', '__return_false' ); \add_action( 'web_stories_enable_schemaorg_metadata', '__return_false' ); \add_action( 'web_stories_enable_open_graph_metadata', '__return_false' ); \add_action( 'web_stories_enable_twitter_metadata', '__return_false' ); \add_action( 'web_stories_story_head', [ $this, 'web_stories_story_head' ], 1 ); \add_filter( 'wpseo_schema_article_type', [ $this, 'filter_schema_article_type' ], 10, 2 ); \add_filter( 'wpseo_metadesc', [ $this, 'filter_meta_description' ], 10, 2 ); } /** * Hooks into web story generation to modify output. * * @return void */ public function web_stories_story_head() { \remove_action( 'web_stories_story_head', 'rel_canonical' ); \add_action( 'web_stories_story_head', [ $this->front_end, 'call_wpseo_head' ], 9 ); } /** * Filters the meta description for stories. * * @param string $description The description sentence. * @param Indexable_Presentation $presentation The presentation of an indexable. * @return string The description sentence. */ public function filter_meta_description( $description, $presentation ) { if ( $description || $presentation->model->object_sub_type !== 'web-story' ) { return $description; } return \get_the_excerpt( $presentation->model->object_id ); } /** * Filters Article type for Web Stories. * * @param string|string[] $type The Article type. * @param Indexable $indexable The indexable. * @return string|string[] Article type. */ public function filter_schema_article_type( $type, $indexable ) { if ( $indexable->object_sub_type !== 'web-story' ) { return $type; } if ( \is_string( $type ) && $type === 'None' ) { return 'Article'; } return $type; } }