ma_page_type ) ? $context->schema_page_type : [ $context->schema_page_type ];
foreach ( $graph as $key => $piece ) {
if ( ! empty( \array_intersect( $webpage_types, $this->get_type_from_piece( $piece ) ) ) && isset( $piece['breadcrumb'] ) ) {
unset( $piece['breadcrumb'] );
$graph[ $key ] = $piece;
}
}
}
return $graph;
}
/**
* Adapts the WebPage graph piece for password-protected posts.
*
* It should only have certain whitelisted properties.
* The type should always be WebPage.
*
* @param array $graph_piece The WebPage graph piece that should be adapted for password-protected posts.
*
* @return array The WebPage graph piece that has been adapted for password-protected posts.
*/
public function protected_webpage_schema( $graph_piece ) {
$properties_to_show = \array_flip(
[
'@type',
'@id',
'url',
'name',
'isPartOf',
'inLanguage',
'datePublished',
'dateModified',
'breadcrumb',
]
);
$graph_piece = \array_intersect_key( $graph_piece, $properties_to_show );
$graph_piece['@type'] = 'WebPage';
return $graph_piece;
}
/**
* Gets all the graph pieces we need.
*
* @param Meta_Tags_Context $context The meta tags context.
*
* @return Abstract_Schema_Piece[] A filtered array of graph pieces.
*/
protected function get_graph_pieces( $context ) {
if ( $context->indexable->object_type === 'post' && \post_password_required( $context->post ) ) {
$schema_pieces = [
new Schema\WebPage(),
new Schema\Website(),
new Schema\Organization(),
];
\add_filter( 'wpseo_schema_webpage', [ $this, 'protected_webpage_schema' ], 1 );
}
else {
$schema_pieces = [
new Schema\Article(),
new Schema\WebPage(),
new Schema\Main_Image(),
new Schema\Breadcrumb(),
new Schema\Website(),
new Schema\Organization(),
new Schema\Person(),
new Schema\Author(),
new Schema\FAQ(),
new Schema\HowTo(),
];
}
/**
* Filter: 'wpseo_schema_graph_pieces' - Allows adding pieces to the graph.
*
* @param Meta_Tags_Context $context An object with context variables.
*
* @api array $pieces The schema pieces.
*/
return \apply_filters( 'wpseo_schema_graph_pieces', $schema_pieces, $context );
}
/**
* Allows filtering the graph piece by its schema type.
*
* Note: We removed the Abstract_Schema_Piece type-hint from the $graph_piece_generator argument, because
* it caused conflicts with old code, Yoast SEO Video specifically.
*
* @param array $graph_piece The graph piece we're filtering.
* @param string $identifier The identifier of the graph piece that is being filtered.
* @param Meta_Tags_Context $context The meta tags context.
* @param Abstract_Schema_Piece $graph_piece_generator A value object with context variables.
* @param Abstract_Schema_Piece[] $graph_piece_generators A value object with context variables.
*
* @return array The filtered graph piece.
*/
private function type_filter( $graph_piece, $identifier, Meta_Tags_Context $context, $graph_piece_generator, array $graph_piece_generators ) {
$types = $this->get_type_from_piece( $graph_piece );
foreach ( $types as $type ) {
$type = \strtolower( $type );
// Prevent running the same filter twice. This makes sure we run f/i. for 'author' and for 'person'.
if ( $type && $type !== $identifier ) {
/**
* Filter: 'wpseo_schema_